16
16
import jakarta .persistence .Table ;
17
17
18
18
19
+ import org .junit .After ;
19
20
import org .junit .Before ;
20
21
import org .junit .Test ;
21
22
@@ -43,25 +44,33 @@ public void populateDB(TestContext context) {
43
44
.withTransaction ( s -> s .persistAll ( painting , artist , dealer ) ) );
44
45
}
45
46
47
+ @ After
48
+ public void cleanDb (TestContext context ) {
49
+ test ( context , getSessionFactory ()
50
+ .withTransaction ( s -> s .createQuery ( "delete from Painting" ).executeUpdate ()
51
+ .thenCompose ( v -> s .createQuery ( "delete from Artist" ).executeUpdate () )
52
+ .thenCompose ( v -> s .createQuery ( "delete from Dealer" ).executeUpdate ())) );
53
+ }
54
+
46
55
@ Test
47
56
public void testNonNullableSuccess (TestContext context ) {
48
57
test ( context , getMutinySessionFactory ()
49
58
.withTransaction ( session -> session
50
59
.createQuery ( "from Artist" , Artist .class )
51
- .getSingleResult ().chain ( a -> session .fetch ( a .paintings ) )
60
+ .getSingleResult ().chain ( a -> session .fetch ( a .getPaintings () ) )
52
61
.invoke ( paintings -> {
53
62
context .assertNotNull ( paintings );
54
63
context .assertEquals ( 1 , paintings .size () );
55
- context .assertEquals ( "Mona Lisa" , paintings .get ( 0 ).name );
64
+ context .assertEquals ( "Mona Lisa" , paintings .get ( 0 ).getName () );
56
65
} ) )
57
66
.chain ( () -> getMutinySessionFactory ()
58
67
.withTransaction ( s1 -> s1
59
68
.createQuery ( "from Dealer" , Dealer .class )
60
- .getSingleResult ().chain ( d -> s1 .fetch ( d .paintings ) )
69
+ .getSingleResult ().chain ( d -> s1 .fetch ( d .getPaintings () ) )
61
70
.invoke ( paintings -> {
62
71
context .assertNotNull ( paintings );
63
72
context .assertEquals ( 1 , paintings .size () );
64
- context .assertEquals ( "Mona Lisa" , paintings .get ( 0 ).name );
73
+ context .assertEquals ( "Mona Lisa" , paintings .get ( 0 ).getName () );
65
74
} )
66
75
)
67
76
)
@@ -89,6 +98,39 @@ public Painting() {
89
98
public Painting (String name ) {
90
99
this .name = name ;
91
100
}
101
+
102
+
103
+ public Long getId () {
104
+ return id ;
105
+ }
106
+
107
+ public void setId (Long id ) {
108
+ this .id = id ;
109
+ }
110
+
111
+ public String getName () {
112
+ return name ;
113
+ }
114
+
115
+ public void setName (String name ) {
116
+ this .name = name ;
117
+ }
118
+
119
+ public Artist getAuthor () {
120
+ return author ;
121
+ }
122
+
123
+ public void setAuthor (Artist author ) {
124
+ this .author = author ;
125
+ }
126
+
127
+ public Dealer getDealer () {
128
+ return dealer ;
129
+ }
130
+
131
+ public void setDealer (Dealer dealer ) {
132
+ this .dealer = dealer ;
133
+ }
92
134
}
93
135
94
136
@ Entity (name = "Artist" )
@@ -114,6 +156,29 @@ public void addPainting(Painting painting) {
114
156
painting .author = this ;
115
157
}
116
158
159
+ public Long getId () {
160
+ return id ;
161
+ }
162
+
163
+ public void setId (Long id ) {
164
+ this .id = id ;
165
+ }
166
+
167
+ public String getName () {
168
+ return name ;
169
+ }
170
+
171
+ public void setName (String name ) {
172
+ this .name = name ;
173
+ }
174
+
175
+ public List <Painting > getPaintings () {
176
+ return paintings ;
177
+ }
178
+
179
+ public void setPaintings (List <Painting > paintings ) {
180
+ this .paintings = paintings ;
181
+ }
117
182
}
118
183
119
184
@ Entity (name = "Dealer" )
@@ -139,5 +204,28 @@ public void addPainting(Painting painting) {
139
204
painting .dealer = this ;
140
205
}
141
206
207
+ public Long getId () {
208
+ return id ;
209
+ }
210
+
211
+ public void setId (Long id ) {
212
+ this .id = id ;
213
+ }
214
+
215
+ public String getName () {
216
+ return name ;
217
+ }
218
+
219
+ public void setName (String name ) {
220
+ this .name = name ;
221
+ }
222
+
223
+ public List <Painting > getPaintings () {
224
+ return paintings ;
225
+ }
226
+
227
+ public void setPaintings (List <Painting > paintings ) {
228
+ this .paintings = paintings ;
229
+ }
142
230
}
143
231
}
0 commit comments