test cleanup
This commit is contained in:
parent
3f24a0064f
commit
e090480ea1
|
@ -331,7 +331,7 @@ public class BooleanMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||||
public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) {
|
public void testBooleanFunctionAsPredicate(SessionFactoryScope scope) {
|
||||||
// Not strictly relevant to boolean mappings, but test that boolean
|
// Not strictly relevant to boolean mappings, but test that boolean
|
||||||
|
@ -350,7 +350,7 @@ public class BooleanMappingTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(dialectClass = OracleDialect.class)
|
@SkipForDialect(dialectClass = OracleDialect.class)
|
||||||
@SkipForDialect(dialectClass = SybaseDialect.class)
|
@SkipForDialect(dialectClass = SybaseDialect.class, matchSubTypes = true)
|
||||||
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
@SkipForDialect(dialectClass = SQLServerDialect.class)
|
||||||
public void testBooleanFunctionInPredicate(SessionFactoryScope scope) {
|
public void testBooleanFunctionInPredicate(SessionFactoryScope scope) {
|
||||||
// Not strictly relevant to boolean mappings, but test that boolean
|
// Not strictly relevant to boolean mappings, but test that boolean
|
||||||
|
|
|
@ -6,100 +6,113 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.annotations.manytoonewithformula;
|
package org.hibernate.orm.test.annotations.manytoonewithformula;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.dialect.HSQLDialect;
|
import org.hibernate.dialect.HSQLDialect;
|
||||||
import org.hibernate.dialect.OracleDialect;
|
import org.hibernate.dialect.OracleDialect;
|
||||||
import org.hibernate.dialect.SQLServerDialect;
|
import org.hibernate.dialect.SQLServerDialect;
|
||||||
|
|
||||||
import org.hibernate.testing.RequiresDialect;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Sharath Reddy
|
* @author Sharath Reddy
|
||||||
*/
|
*/
|
||||||
public class ManyToOneWithFormulaTest extends BaseCoreFunctionalTestCase {
|
@DomainModel( annotatedClasses = {
|
||||||
|
Menu.class,
|
||||||
|
FoodItem.class,
|
||||||
|
Company.class,
|
||||||
|
Person.class,
|
||||||
|
Message.class,
|
||||||
|
Language.class,
|
||||||
|
Contract.class,
|
||||||
|
ContractId.class,
|
||||||
|
Model.class,
|
||||||
|
ModelId.class,
|
||||||
|
Manufacturer.class,
|
||||||
|
ManufacturerId.class,
|
||||||
|
Product.class,
|
||||||
|
ProductSqlServer.class
|
||||||
|
} )
|
||||||
|
@SessionFactory
|
||||||
|
public class ManyToOneWithFormulaTest {
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneFromNonPk() throws Exception {
|
public void testManyToOneFromNonPk(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (session) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
Menu menu = new Menu();
|
Menu menu = new Menu();
|
||||||
menu.setOrderNbr( "123" );
|
menu.setOrderNbr( "123" );
|
||||||
menu.setDefault( "F" );
|
menu.setDefault( "F" );
|
||||||
s.persist( menu );
|
session.persist( menu );
|
||||||
FoodItem foodItem = new FoodItem();
|
FoodItem foodItem = new FoodItem();
|
||||||
foodItem.setItem( "Mouse" );
|
foodItem.setItem( "Mouse" );
|
||||||
foodItem.setOrder( menu );
|
foodItem.setOrder( menu );
|
||||||
s.persist( foodItem );
|
session.persist( foodItem );
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
foodItem = ( FoodItem ) s.get( FoodItem.class, foodItem.getId() );
|
|
||||||
assertNotNull( foodItem.getOrder() );
|
foodItem = session.get( FoodItem.class, foodItem.getId() );
|
||||||
assertEquals( "123", foodItem.getOrder().getOrderNbr() );
|
assertThat( foodItem.getOrder() ).isNotNull();
|
||||||
tx.rollback();
|
assertThat( foodItem.getOrder().getOrderNbr() ).isEqualTo( "123" );
|
||||||
s.close();
|
|
||||||
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testManyToOneFromPk() throws Exception {
|
public void testManyToOneFromPk(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (session) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
Company company = new Company();
|
Company company = new Company();
|
||||||
s.persist( company );
|
session.persist( company );
|
||||||
|
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
person.setDefaultFlag( "T" );
|
person.setDefaultFlag( "T" );
|
||||||
person.setCompanyId( company.getId() );
|
person.setCompanyId( company.getId() );
|
||||||
s.persist( person );
|
session.persist( person );
|
||||||
|
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
|
|
||||||
company = ( Company ) s.get( Company.class, company.getId() );
|
company = session.get( Company.class, company.getId() );
|
||||||
assertNotNull( company.getDefaultContactPerson() );
|
assertThat( company.getDefaultContactPerson() ).isNotNull();
|
||||||
assertEquals( person.getId(), company.getDefaultContactPerson().getId() );
|
assertThat( company.getDefaultContactPerson().getId() ).isEqualTo( person.getId() );
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497")
|
@SkipForDialect( dialectClass = HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497" )
|
||||||
public void testManyToOneToPkWithOnlyFormula() throws Exception {
|
public void testManyToOneToPkWithOnlyFormula(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (session) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
Language language = new Language();
|
Language language = new Language();
|
||||||
language.setCode( "EN" );
|
language.setCode( "EN" );
|
||||||
language.setName( "English" );
|
language.setName( "English" );
|
||||||
s.persist( language );
|
session.persist( language );
|
||||||
|
|
||||||
Message msg = new Message();
|
Message msg = new Message();
|
||||||
msg.setLanguageCode( "en" );
|
msg.setLanguageCode( "en" );
|
||||||
msg.setLanguageName( "English" );
|
msg.setLanguageName( "English" );
|
||||||
s.persist( msg );
|
session.persist( msg );
|
||||||
|
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
|
|
||||||
msg = ( Message ) s.get( Message.class, msg.getId() );
|
msg = session.get( Message.class, msg.getId() );
|
||||||
assertNotNull( msg.getLanguage() );
|
assertThat( msg.getLanguage() ).isNotNull();
|
||||||
assertEquals( "EN", msg.getLanguage().getCode() );
|
assertThat( msg.getLanguage().getCode() ).isEqualTo( "EN" );
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity() throws Exception {
|
public void testReferencedColumnNameBelongsToEmbeddedIdOfReferencedEntity(SessionFactoryScope scope) {
|
||||||
Session session = openSession();
|
scope.inTransaction( (session) -> { Integer companyCode = 10;
|
||||||
Transaction tx = session.beginTransaction();
|
|
||||||
|
|
||||||
Integer companyCode = 10;
|
|
||||||
Integer mfgCode = 100;
|
Integer mfgCode = 100;
|
||||||
String contractNumber = "NSAR97841";
|
String contractNumber = "NSAR97841";
|
||||||
ContractId contractId = new ContractId(companyCode, 12457l, 1);
|
ContractId contractId = new ContractId(companyCode, 12457l, 1);
|
||||||
|
@ -124,104 +137,84 @@ public class ManyToOneWithFormulaTest extends BaseCoreFunctionalTestCase {
|
||||||
session.flush();
|
session.flush();
|
||||||
session.clear();
|
session.clear();
|
||||||
|
|
||||||
contract = (Contract) session.load(Contract.class, contractId);
|
contract = session.get( Contract.class, contractId );
|
||||||
assertEquals("NSAR97841", contract.getContractNumber());
|
assertThat( contract.getContractNumber() ).isEqualTo( "NSAR97841" );
|
||||||
assertEquals("FORD", contract.getManufacturer().getName());
|
assertThat( contract.getManufacturer().getName() ).isEqualTo( "FORD" );
|
||||||
assertEquals("FORD FOCUS", contract.getModel().getName());
|
assertThat( contract.getModel().getName() ).isEqualTo( "FORD FOCUS" );
|
||||||
|
|
||||||
tx.commit();
|
session.getTransaction().markRollbackOnly();
|
||||||
session.close();
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect( value = { HSQLDialect.class }, comment = "The used join conditions does not work in HSQLDB. See HHH-4497." )
|
@SkipForDialect( dialectClass =HSQLDialect.class, reason = "The used join conditions does not work in HSQLDB. See HHH-4497." )
|
||||||
@SkipForDialect( value = { OracleDialect.class }, comment = "Oracle do not support 'substring' function" )
|
@SkipForDialect( dialectClass = OracleDialect.class, reason = "Oracle do not support 'substring' function" )
|
||||||
public void testManyToOneFromNonPkToNonPk() throws Exception {
|
public void testManyToOneFromNonPkToNonPk(SessionFactoryScope scope) {
|
||||||
// also tests usage of the stand-alone @JoinFormula annotation (i.e. not wrapped within @JoinColumnsOrFormulas)
|
// also tests usage of the stand-alone @JoinFormula annotation
|
||||||
Session s = openSession();
|
// (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
Product kit = new Product();
|
Product kit = new Product();
|
||||||
kit.id = 1;
|
kit.id = 1;
|
||||||
kit.productIdnf = "KIT";
|
kit.productIdnf = "KIT";
|
||||||
kit.description = "Kit";
|
kit.description = "Kit";
|
||||||
s.persist(kit);
|
session.persist(kit);
|
||||||
|
|
||||||
Product kitkat = new Product();
|
Product kitkat = new Product();
|
||||||
kitkat.id = 2;
|
kitkat.id = 2;
|
||||||
kitkat.productIdnf = "KIT_KAT";
|
kitkat.productIdnf = "KIT_KAT";
|
||||||
kitkat.description = "Chocolate";
|
kitkat.description = "Chocolate";
|
||||||
s.persist(kitkat);
|
session.persist(kitkat);
|
||||||
|
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
|
|
||||||
kit = (Product) s.get(Product.class, 1);
|
kit = session.get(Product.class, 1);
|
||||||
kitkat = (Product) s.get(Product.class, 2);
|
kitkat = session.get(Product.class, 2);
|
||||||
System.out.println(kitkat.description);
|
|
||||||
assertNotNull(kitkat);
|
|
||||||
assertEquals(kit, kitkat.getProductFamily());
|
|
||||||
assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
|
|
||||||
assertEquals("KIT_KAT", kitkat.productIdnf.trim());
|
|
||||||
assertEquals("Chocolate", kitkat.description.trim());
|
|
||||||
|
|
||||||
tx.rollback();
|
assertThat( kitkat ).isNotNull();
|
||||||
s.close();
|
assertThat( kitkat.getProductFamily() ).isEqualTo( kit );
|
||||||
|
assertThat( kit.productIdnf ).isEqualTo( kitkat.getProductFamily().productIdnf );
|
||||||
|
assertThat( kitkat.productIdnf.trim() ).isEqualTo( "KIT_KAT" );
|
||||||
|
assertThat( kitkat.description.trim() ).isEqualTo( "Chocolate" );
|
||||||
|
|
||||||
|
session.getTransaction().markRollbackOnly();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@RequiresDialect(value = { SQLServerDialect.class})
|
@RequiresDialect( SQLServerDialect.class )
|
||||||
public void testManyToOneFromNonPkToNonPkSqlServer() throws Exception {
|
public void testManyToOneFromNonPkToNonPkSqlServer(SessionFactoryScope scope) {
|
||||||
// also tests usage of the stand-alone @JoinFormula annotation (i.e. not wrapped within @JoinColumnsOrFormulas)
|
// also tests usage of the stand-alone @JoinFormula annotation
|
||||||
Session s = openSession();
|
// (i.e. not wrapped within @JoinColumnsOrFormulas)
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
|
|
||||||
|
scope.inTransaction( (session) -> {
|
||||||
ProductSqlServer kit = new ProductSqlServer();
|
ProductSqlServer kit = new ProductSqlServer();
|
||||||
kit.id = 1;
|
kit.id = 1;
|
||||||
kit.productIdnf = "KIT";
|
kit.productIdnf = "KIT";
|
||||||
kit.description = "Kit";
|
kit.description = "Kit";
|
||||||
s.persist(kit);
|
session.persist(kit);
|
||||||
|
|
||||||
ProductSqlServer kitkat = new ProductSqlServer();
|
ProductSqlServer kitkat = new ProductSqlServer();
|
||||||
kitkat.id = 2;
|
kitkat.id = 2;
|
||||||
kitkat.productIdnf = "KIT_KAT";
|
kitkat.productIdnf = "KIT_KAT";
|
||||||
kitkat.description = "Chocolate";
|
kitkat.description = "Chocolate";
|
||||||
s.persist(kitkat);
|
session.persist(kitkat);
|
||||||
|
|
||||||
s.flush();
|
session.flush();
|
||||||
s.clear();
|
session.clear();
|
||||||
|
|
||||||
kit = (ProductSqlServer) s.get(ProductSqlServer.class, 1);
|
kit = session.get(ProductSqlServer.class, 1);
|
||||||
kitkat = (ProductSqlServer) s.get(ProductSqlServer.class, 2);
|
kitkat = session.get(ProductSqlServer.class, 2);
|
||||||
System.out.println(kitkat.description);
|
|
||||||
assertNotNull(kitkat);
|
|
||||||
assertEquals(kit, kitkat.getProductFamily());
|
|
||||||
assertEquals(kit.productIdnf, kitkat.getProductFamily().productIdnf);
|
|
||||||
assertEquals("KIT_KAT", kitkat.productIdnf.trim());
|
|
||||||
assertEquals("Chocolate", kitkat.description.trim());
|
|
||||||
|
|
||||||
tx.rollback();
|
assertThat( kitkat ).isNotNull();
|
||||||
s.close();
|
assertThat( kitkat.getProductFamily() ).isEqualTo( kit );
|
||||||
}
|
assertThat( kit.productIdnf ).isEqualTo( kitkat.getProductFamily().productIdnf );
|
||||||
|
assertThat( kitkat.productIdnf.trim() ).isEqualTo( "KIT_KAT" );
|
||||||
|
assertThat( kitkat.description.trim() ).isEqualTo( "Chocolate" );
|
||||||
|
|
||||||
@Override
|
session.getTransaction().markRollbackOnly();
|
||||||
protected Class<?>[] getAnnotatedClasses() {
|
} );
|
||||||
return new Class[] {
|
|
||||||
Menu.class,
|
|
||||||
FoodItem.class,
|
|
||||||
Company.class,
|
|
||||||
Person.class,
|
|
||||||
Message.class,
|
|
||||||
Language.class,
|
|
||||||
Contract.class,
|
|
||||||
ContractId.class,
|
|
||||||
Model.class,
|
|
||||||
ModelId.class,
|
|
||||||
Manufacturer.class,
|
|
||||||
ManufacturerId.class,
|
|
||||||
Product.class,
|
|
||||||
ProductSqlServer.class
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,15 +6,17 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.annotations.uniqueconstraint;
|
package org.hibernate.orm.test.annotations.uniqueconstraint;
|
||||||
|
|
||||||
import jakarta.persistence.PersistenceException;
|
|
||||||
|
|
||||||
import org.hibernate.JDBCException;
|
import org.hibernate.JDBCException;
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.Transaction;
|
|
||||||
import org.hibernate.dialect.SybaseDialect;
|
import org.hibernate.dialect.SybaseDialect;
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import jakarta.persistence.PersistenceException;
|
||||||
|
|
||||||
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
@ -23,22 +25,15 @@ import static org.junit.Assert.fail;
|
||||||
* @author Manuel Bernhardt
|
* @author Manuel Bernhardt
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
@SkipForDialect(value = SybaseDialect.class,
|
@DomainModel( annotatedClasses = { Room.class, Building.class, House.class } )
|
||||||
comment = "Sybase does not properly support unique constraints on nullable columns")
|
@SessionFactory
|
||||||
public class UniqueConstraintTest extends BaseCoreFunctionalTestCase {
|
@SkipForDialect( dialectClass = SybaseDialect.class,
|
||||||
|
reason = "Sybase does not properly support unique constraints on nullable columns" )
|
||||||
protected Class[] getAnnotatedClasses() {
|
public class UniqueConstraintTest {
|
||||||
return new Class[]{
|
|
||||||
Room.class,
|
|
||||||
Building.class,
|
|
||||||
House.class
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUniquenessConstraintWithSuperclassProperty() {
|
public void testUniquenessConstraintWithSuperclassProperty(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inTransaction( (s) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
|
||||||
Room livingRoom = new Room();
|
Room livingRoom = new Room();
|
||||||
livingRoom.setId(1l);
|
livingRoom.setId(1l);
|
||||||
livingRoom.setName("livingRoom");
|
livingRoom.setName("livingRoom");
|
||||||
|
@ -66,9 +61,9 @@ public class UniqueConstraintTest extends BaseCoreFunctionalTestCase {
|
||||||
//success
|
//success
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
tx.rollback();
|
s.getTransaction().markRollbackOnly();
|
||||||
s.close();
|
|
||||||
}
|
}
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,40 +9,47 @@ package org.hibernate.orm.test.annotations.xml.ejb3;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
|
||||||
import org.hibernate.SessionFactory;
|
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.dialect.CockroachDialect;
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
|
||||||
import org.hibernate.dialect.PostgreSQLDialect;
|
import org.hibernate.dialect.PostgreSQLDialect;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||||
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.orm.junit.DomainModel;
|
||||||
import org.junit.Test;
|
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||||
|
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||||
|
import org.hibernate.testing.orm.junit.SkipForDialect;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-14529")
|
@TestForIssue(jiraKey = "HHH-14529")
|
||||||
public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
@DomainModel(
|
||||||
|
annotatedClasses = { CarModel.class, Manufacturer.class, Model.class, Light.class },
|
||||||
@Override
|
xmlMappings = {
|
||||||
protected void prepareBootstrapRegistryBuilder(BootstrapServiceRegistryBuilder builder) {
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm.xml",
|
||||||
super.prepareBootstrapRegistryBuilder( builder );
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm2.xml",
|
||||||
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm3.xml",
|
||||||
|
"org/hibernate/orm/test/annotations/xml/ejb3/orm4.xml"
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
@SessionFactory
|
||||||
|
public class Ejb3XmlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SkipForDialect(value = {PostgreSQLDialect.class, CockroachDialect.class},
|
@SkipForDialect( dialectClass = PostgreSQLDialect.class,
|
||||||
comment = "postgresql jdbc driver does not implement the setQueryTimeout method")
|
reason = "driver does not implement the setQueryTimeout method" )
|
||||||
public void testEjb3Xml() throws Exception {
|
@SkipForDialect( dialectClass = CockroachDialect.class,
|
||||||
Session s = openSession();
|
reason = "driver does not implement the setQueryTimeout method" )
|
||||||
Transaction tx = s.beginTransaction();
|
public void testEjb3Xml(SessionFactoryScope scope) {
|
||||||
|
scope.inSession( (s) -> {
|
||||||
|
s.getTransaction().begin();
|
||||||
|
|
||||||
CarModel model = new CarModel();
|
CarModel model = new CarModel();
|
||||||
model.setYear( new Date() );
|
model.setYear( new Date() );
|
||||||
Manufacturer manufacturer = new Manufacturer();
|
Manufacturer manufacturer = new Manufacturer();
|
||||||
|
@ -54,24 +61,25 @@ public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
model.setYear( new Date() );
|
model.setYear( new Date() );
|
||||||
manufacturer = (Manufacturer) s.get( Manufacturer.class, manufacturer.getId() );
|
manufacturer = s.get( Manufacturer.class, manufacturer.getId() );
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
||||||
.setParameter( "manufacturer", manufacturer )
|
.setParameter( "manufacturer", manufacturer )
|
||||||
.list();
|
.list();
|
||||||
assertEquals( 1, cars.size() );
|
assertEquals( 1, cars.size() );
|
||||||
for ( Model car : cars ) {
|
for ( Model car : cars ) {
|
||||||
assertNotNull( car.getManufacturer() );
|
Assertions.assertNotNull( car.getManufacturer() );
|
||||||
s.delete( manufacturer );
|
s.remove( manufacturer );
|
||||||
s.delete( car );
|
s.remove( car );
|
||||||
}
|
}
|
||||||
tx.rollback();
|
|
||||||
s.close();
|
s.getTransaction().rollback();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXMLEntityHandled() throws Exception {
|
public void testXMLEntityHandled(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inSession( (s) -> {
|
||||||
s.getTransaction().begin();
|
s.getTransaction().begin();
|
||||||
Lighter l = new Lighter();
|
Lighter l = new Lighter();
|
||||||
l.name = "Blue";
|
l.name = "Blue";
|
||||||
|
@ -79,12 +87,12 @@ public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||||
s.persist( l );
|
s.persist( l );
|
||||||
s.flush();
|
s.flush();
|
||||||
s.getTransaction().rollback();
|
s.getTransaction().rollback();
|
||||||
s.close();
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testXmlDefaultOverriding() throws Exception {
|
public void testXmlDefaultOverriding(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inSession( (s) -> {
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
Manufacturer manufacturer = new Manufacturer();
|
Manufacturer manufacturer = new Manufacturer();
|
||||||
s.persist( manufacturer );
|
s.persist( manufacturer );
|
||||||
|
@ -92,15 +100,16 @@ public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
||||||
|
|
||||||
tx.rollback();
|
tx.rollback();
|
||||||
s.close();
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void testMapXMLSupport() throws Exception {
|
public void testMapXMLSupport(SessionFactoryScope scope) {
|
||||||
Session s = openSession();
|
scope.inSession( (s) -> {
|
||||||
SessionFactory sf = s.getSessionFactory();
|
SessionFactoryImplementor sf = s.getSessionFactory();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
|
|
||||||
// Verify that we can persist an object with a couple Map mappings
|
// Verify that we can persist an object with a couple Map mappings
|
||||||
|
@ -124,27 +133,6 @@ public class Ejb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||||
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
||||||
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
||||||
tx.rollback();
|
tx.rollback();
|
||||||
s.close();
|
} );
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Class[] getAnnotatedClasses() {
|
|
||||||
return new Class[] {
|
|
||||||
CarModel.class,
|
|
||||||
Manufacturer.class,
|
|
||||||
Model.class,
|
|
||||||
Light.class
|
|
||||||
//Lighter.class xml only entuty
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String[] getOrmXmlFiles() {
|
|
||||||
return new String[] {
|
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm.xml",
|
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm2.xml",
|
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm3.xml",
|
|
||||||
"org/hibernate/orm/test/annotations/xml/ejb3/orm4.xml"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.dialect.CockroachDialect;
|
import org.hibernate.dialect.CockroachDialect;
|
||||||
import org.hibernate.dialect.OracleDialect;
|
import org.hibernate.dialect.OracleDialect;
|
||||||
|
|
||||||
import org.hibernate.testing.SkipForDialect;
|
|
||||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue