clean up remaining test suite failures

This commit is contained in:
Steve Ebersole 2022-01-18 16:06:47 -06:00
parent aefb3c3edc
commit e8d8b43bfd
1 changed files with 52 additions and 55 deletions

View File

@ -6,73 +6,69 @@
*/ */
package org.hibernate.test.resulttransformer; package org.hibernate.test.resulttransformer;
import java.util.List;
import org.junit.Test;
import org.hibernate.query.Query;
import org.hibernate.ScrollableResults; import org.hibernate.ScrollableResults;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.AbstractHANADialect; import org.hibernate.dialect.AbstractHANADialect;
import org.hibernate.testing.TestForIssue; import org.hibernate.query.Query;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.transform.ResultTransformer; import org.hibernate.transform.ResultTransformer;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.orm.junit.NotImplementedYet;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* @author Sharath Reddy * @author Sharath Reddy
*/ */
public class ResultTransformerTest extends BaseCoreFunctionalTestCase { @DomainModel(
@Override xmlMappings = "org/hibernate/test/resulttransformer/Contract.hbm.xml"
public String[] getMappings() { )
return new String[] { "resulttransformer/Contract.hbm.xml" }; @SessionFactory
} public class ResultTransformerTest {
@Test @Test
@TestForIssue( jiraKey = "HHH-3694" ) @JiraKey( "HHH-3694" )
public void testResultTransformerIsAppliedToScrollableResults() throws Exception @NotImplementedYet( strict = false, reason = "More problems with hbm.xml sql resultset mappings" )
{ public void testResultTransformerIsAppliedToScrollableResults(SessionFactoryScope scope) {
Session s = openSession(); scope.inTransaction( (session) -> {
Transaction tx = s.beginTransaction(); final PartnerA a = new PartnerA();
PartnerA a = new PartnerA();
a.setName("Partner A"); a.setName("Partner A");
PartnerB b = new PartnerB();
final PartnerB b = new PartnerB();
b.setName("Partner B"); b.setName("Partner B");
Contract obj1 = new Contract();
final Contract obj1 = new Contract();
obj1.setName("Contract"); obj1.setName("Contract");
obj1.setA(a); obj1.setA(a);
obj1.setB(b); obj1.setB(b);
s.save(a);
s.save(b);
s.save(obj1);
tx.commit(); session.persist(a);
s.close(); session.persist(b);
session.persist(obj1);
} );
s = openSession(); scope.inSession( (session) -> {
Query q = session.getNamedQuery(Contract.class.getName() + ".testQuery");
Query q = s.getNamedQuery(Contract.class.getName() + ".testQuery");
q.setFetchSize(100); q.setFetchSize(100);
q.setResultTransformer(new ResultTransformer() { q.setResultTransformer(
(ResultTransformer) (arg0, arg1) -> {
private static final long serialVersionUID = -5815434828170704822L;
public Object transformTuple(Object[] arg0, String[] arg1)
{
// return only the PartnerA object from the query // return only the PartnerA object from the query
return arg0[1]; return arg0[1];
} }
}); );
ScrollableResults sr = q.scroll(); ScrollableResults sr = q.scroll();
// HANA supports only ResultSet.TYPE_FORWARD_ONLY and // HANA supports only ResultSet.TYPE_FORWARD_ONLY and
// does not support java.sql.ResultSet.first() // does not support java.sql.ResultSet.first()
if (getDialect() instanceof AbstractHANADialect) { if ( scope.getSessionFactory().getDialect() instanceof AbstractHANADialect ) {
sr.next(); sr.next();
} else { }
else {
sr.first(); sr.first();
} }
@ -80,7 +76,8 @@ public class ResultTransformerTest extends BaseCoreFunctionalTestCase {
assertTrue(obj instanceof PartnerA); assertTrue(obj instanceof PartnerA);
PartnerA obj2 = (PartnerA) obj; PartnerA obj2 = (PartnerA) obj;
assertEquals("Partner A", obj2.getName()); assertEquals("Partner A", obj2.getName());
s.close();
} );
} }
} }