Skip to content

Commit ae4c990

Browse files
committed
HHH-19324 - Switch tests using hbm.xml to use mapping.xml
1 parent 60459f0 commit ae4c990

File tree

5 files changed

+74
-114
lines changed

5 files changed

+74
-114
lines changed

hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/InvocationTargetExceptionTest.java

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,48 @@
44
*/
55
package org.hibernate.orm.test.bytecode;
66

7-
import java.text.ParseException;
8-
97
import org.hibernate.Hibernate;
10-
import org.hibernate.Session;
11-
12-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
13-
import org.junit.Test;
14-
15-
import static org.junit.Assert.assertFalse;
16-
import static org.junit.Assert.fail;
17-
18-
public class InvocationTargetExceptionTest extends BaseCoreFunctionalTestCase {
8+
import org.hibernate.testing.orm.junit.DomainModel;
9+
import org.hibernate.testing.orm.junit.SessionFactory;
10+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
11+
import org.junit.jupiter.api.AfterEach;
12+
import org.junit.jupiter.api.Test;
1913

20-
@Override
21-
protected String getBaseForMappings() {
22-
return "org/hibernate/orm/test/";
23-
}
14+
import java.text.ParseException;
2415

25-
@Override
26-
public String[] getMappings() {
27-
return new String[] { "bytecode/Bean.hbm.xml" };
28-
}
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.junit.jupiter.api.Assertions.fail;
2918

19+
@SuppressWarnings("JUnitMalformedDeclaration")
20+
@DomainModel(xmlMappings = "org/hibernate/orm/test/bytecode/Bean.xml")
21+
@SessionFactory
22+
public class InvocationTargetExceptionTest {
3023
@Test
31-
public void testProxiedInvocationException() {
32-
Session s = openSession();
33-
s.beginTransaction();
34-
Bean bean = new Bean();
35-
bean.setSomeString( "my-bean" );
36-
s.persist( bean );
37-
s.getTransaction().commit();
38-
s.close();
39-
40-
s = openSession();
41-
s.beginTransaction();
42-
bean = ( Bean ) s.getReference( Bean.class, bean.getSomeString() );
43-
assertFalse( Hibernate.isInitialized( bean ) );
44-
try {
45-
bean.throwException();
46-
fail( "exception not thrown" );
47-
}
48-
catch ( ParseException e ) {
49-
// expected behavior
50-
}
51-
catch ( Throwable t ) {
52-
fail( "unexpected exception type : " + t );
53-
}
24+
public void testProxiedInvocationException(SessionFactoryScope factoryScope) {
25+
factoryScope.inTransaction( (s) -> {
26+
Bean bean = new Bean();
27+
bean.setSomeString( "my-bean" );
28+
s.persist( bean );
29+
} );
30+
31+
factoryScope.inTransaction( (s) -> {
32+
Bean bean = s.getReference( Bean.class, "my-bean" );
33+
assertThat( Hibernate.isInitialized( bean ) ).isFalse();
34+
try {
35+
bean.throwException();
36+
fail( "exception not thrown" );
37+
}
38+
catch ( ParseException e ) {
39+
// expected behavior
40+
}
41+
catch ( Throwable t ) {
42+
fail( "unexpected exception type : " + t );
43+
}
44+
} );
45+
}
5446

55-
s.remove( bean );
56-
s.getTransaction().commit();
57-
s.close();
47+
@AfterEach
48+
public void dropTestData(SessionFactoryScope factoryScope) throws Exception {
49+
factoryScope.dropData();
5850
}
5951
}

hibernate-core/src/test/java/org/hibernate/orm/test/bytecode/ProxyBean.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

hibernate-core/src/test/resources/org/hibernate/orm/test/array/A.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<generated-value generator="increment"/>
1616
</id>
1717
<one-to-many name="bs" target-entity="B" fetch-mode="JOIN">
18-
<join-column name="a_fk"/>
1918
<order-column name="idx"/>
19+
<join-column name="a_fk"/>
2020
<cascade>
2121
<cascade-all/>
2222
</cascade>

hibernate-core/src/test/resources/org/hibernate/orm/test/bytecode/Bean.hbm.xml

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
~ SPDX-License-Identifier: Apache-2.0
4+
~ Copyright Red Hat Inc. and Hibernate Authors
5+
-->
6+
<entity-mappings xmlns="http://www.hibernate.org/xsd/orm/mapping"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
version="7.0">
9+
<package>org.hibernate.orm.test.bytecode</package>
10+
11+
<entity class="Bean">
12+
<attributes>
13+
<id name="someString"/>
14+
<basic name="someLong">
15+
<column name="some_long"/>
16+
</basic>
17+
<basic name="someInteger">
18+
<column name="some_integer"/>
19+
</basic>
20+
<basic name="someDate">
21+
<column name="some_date"/>
22+
<temporal>TIMESTAMP</temporal>
23+
</basic>
24+
<basic name="somelong">
25+
<column name="some_long2"/>
26+
</basic>
27+
<basic name="someint">
28+
<column name="some_integer2"/>
29+
</basic>
30+
<basic name="someObject">
31+
<column name="some_obj"/>
32+
<jdbc-type-code>2004</jdbc-type-code>
33+
</basic>
34+
</attributes>
35+
</entity>
36+
</entity-mappings>

0 commit comments

Comments
 (0)