Skip to content

Commit 7d4df4a

Browse files
dreab8beikov
authored andcommitted
Re-enabled additional tests
1 parent 6efb29e commit 7d4df4a

File tree

3 files changed

+77
-39
lines changed

3 files changed

+77
-39
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
<!--
1313
Demonstrates use of a class-level where restriction
1414
-->
15-
<hibernate-mapping package="org.hibernate.test.nonpkassociation">
15+
<hibernate-mapping package="org.hibernate.orm.test.nonpkassociation">
1616

17-
<class name="org.hibernate.test.nonpkassociation.NonPkManyToOneAssociationHbmTest$Parent" table="T_PARENT">
17+
<class name="org.hibernate.orm.test.nonpkassociation.NonPkManyToOneAssociationHbmTest$Parent" table="T_PARENT">
1818
<id name="id">
1919
<generator class="increment"/>
2020
</id>
@@ -25,15 +25,17 @@
2525

2626
<set name="children" inverse="true" cascade="all-delete-orphan">
2727
<key column="parentVal"/>
28-
<one-to-many class="org.hibernate.test.nonpkassociation.NonPkManyToOneAssociationHbmTest$Child"/>
28+
<one-to-many class="org.hibernate.orm.test.nonpkassociation.NonPkManyToOneAssociationHbmTest$Child"/>
2929
</set>
3030
</class>
3131

32-
<class name="org.hibernate.test.nonpkassociation.NonPkManyToOneAssociationHbmTest$Child" table="T_CHILD">
32+
<class name="org.hibernate.orm.test.nonpkassociation.NonPkManyToOneAssociationHbmTest$Child" table="T_CHILD">
3333
<id name="id">
3434
<generator class="increment"/>
3535
</id>
3636

37+
<property name="name"/>
38+
3739
<many-to-one name="parent" property-ref="collectionKey" not-null="true">
3840
<column name="parentVal" />
3941
</many-to-one>
Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,35 @@
44
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
55
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
66
*/
7-
package org.hibernate.test.nonpkassociation;
7+
package org.hibernate.orm.test.nonpkassociation;
88

99
import java.util.HashSet;
10-
import java.util.List;
1110
import java.util.Set;
1211

13-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
14-
import org.junit.Before;
15-
import org.junit.Test;
12+
import org.hibernate.testing.orm.junit.DomainModel;
13+
import org.hibernate.testing.orm.junit.SessionFactory;
14+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
15+
import org.junit.jupiter.api.AfterEach;
16+
import org.junit.jupiter.api.BeforeEach;
17+
import org.junit.jupiter.api.Test;
18+
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
1620

17-
import static org.junit.Assert.assertEquals;
1821

1922
/**
2023
* @author pholvs
2124
*/
22-
public class NonPkManyToOneAssociationHbmTest extends BaseCoreFunctionalTestCase {
23-
24-
public String[] getMappings() {
25-
return new String[] { "nonpkassociation/NonPkManyToOneAssociationHbmTest.hbm.xml" };
26-
}
25+
@DomainModel(
26+
xmlMappings = "org/hibernate/orm/test/nonpkassociation/NonPkManyToOneAssociationHbmTest.hbm.xml"
27+
)
28+
@SessionFactory
29+
public class NonPkManyToOneAssociationHbmTest {
2730

2831
private Parent parent;
2932

30-
@Before
31-
public void createTestData() {
32-
inTransaction(
33+
@BeforeEach
34+
public void createTestData(SessionFactoryScope scope) {
35+
scope.inTransaction(
3336
s -> {
3437
parent = new Parent( 99999L );
3538
s.persist( parent );
@@ -41,10 +44,20 @@ public void createTestData() {
4144
);
4245
}
4346

47+
@AfterEach
48+
public void tearDown(SessionFactoryScope scope){
49+
scope.inTransaction(
50+
session -> {
51+
session.createQuery( "delete from NonPkManyToOneAssociationHbmTest$Child" ).executeUpdate();
52+
session.createQuery( "delete from NonPkManyToOneAssociationHbmTest$Parent" ).executeUpdate();
53+
}
54+
);
55+
}
56+
4457

4558
@Test
46-
public void testHqlWithFetch() {
47-
inTransaction(
59+
public void testHqlWithFetch(SessionFactoryScope scope) {
60+
scope.inTransaction(
4861
s -> {
4962
Parent dbParent = s.find( Parent.class, this.parent.getId() );
5063
Set<Child> children = dbParent.getChildren();
@@ -96,6 +109,16 @@ public static class Child {
96109

97110
private Long id;
98111

112+
public String getName() {
113+
return name;
114+
}
115+
116+
public void setName(String name) {
117+
this.name = name;
118+
}
119+
120+
private String name;
121+
99122
private Parent parent;
100123

101124
public Child(Parent parent) {
Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
55
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
66
*/
7-
package org.hibernate.test.nonpkassociation;
7+
package org.hibernate.orm.test.nonpkassociation;
88

99
import java.io.Serializable;
1010
import java.util.HashSet;
@@ -17,30 +17,31 @@
1717
import javax.persistence.ManyToOne;
1818
import javax.persistence.OneToMany;
1919

20-
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
21-
import org.junit.Before;
22-
import org.junit.Test;
20+
import org.hibernate.testing.orm.junit.DomainModel;
21+
import org.hibernate.testing.orm.junit.SessionFactory;
22+
import org.hibernate.testing.orm.junit.SessionFactoryScope;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
25+
import org.junit.jupiter.api.Test;
2326

2427
import static org.junit.Assert.assertEquals;
2528

2629
/**
2730
* @author pholvs
2831
*/
29-
public class NonPkManyToOneAssociationTest extends BaseCoreFunctionalTestCase {
30-
31-
@Override
32-
protected Class<?>[] getAnnotatedClasses() {
33-
return new Class[] {
34-
Parent.class,
35-
Child.class,
36-
};
37-
}
38-
32+
@DomainModel(
33+
annotatedClasses = {
34+
NonPkManyToOneAssociationTest.Parent.class,
35+
NonPkManyToOneAssociationTest.Child.class,
36+
}
37+
)
38+
@SessionFactory
39+
public class NonPkManyToOneAssociationTest {
3940
private Parent parent;
4041

41-
@Before
42-
public void createTestData() {
43-
inTransaction(
42+
@BeforeEach
43+
public void createTestData(SessionFactoryScope scope) {
44+
scope.inTransaction(
4445
s -> {
4546
parent = new Parent( 99999L );
4647
s.persist( parent );
@@ -52,10 +53,20 @@ public void createTestData() {
5253
);
5354
}
5455

56+
@AfterEach
57+
public void tearDown(SessionFactoryScope scope) {
58+
scope.inTransaction(
59+
session -> {
60+
session.createQuery( "delete from Child" ).executeUpdate();
61+
session.createQuery( "delete from Parent" ).executeUpdate();
62+
}
63+
);
64+
}
65+
5566

5667
@Test
57-
public void testHqlWithFetch() {
58-
inTransaction(
68+
public void testHqlWithFetch(SessionFactoryScope scope) {
69+
scope.inTransaction(
5970
s -> {
6071
Parent parent = s.find( Parent.class, this.parent.getId() );
6172
assertEquals( 1, parent.getChildren().size() );
@@ -114,6 +125,8 @@ public static class Child {
114125
@GeneratedValue
115126
private Long id;
116127

128+
private String name;
129+
117130
@ManyToOne
118131
@JoinColumn(name = "parentVal", referencedColumnName = "collectionKey")
119132
private Parent parent;

0 commit comments

Comments
 (0)