24
24
import jakarta .persistence .OneToMany ;
25
25
import jakarta .persistence .Table ;
26
26
27
+ import static org .assertj .core .api .Assertions .assertThat ;
28
+
27
29
public class EmbeddedIdWithManyTest extends BaseReactiveTest {
28
30
31
+ Fruit cherry ;
32
+ Fruit apple ;
33
+ Fruit banana ;
34
+
35
+ Flower sunflower ;
36
+ Flower chrysanthemum ;
37
+ Flower rose ;
38
+
29
39
@ Override
30
40
protected Collection <Class <?>> annotatedEntities () {
31
41
return List .of ( Flower .class , Fruit .class );
@@ -34,21 +44,21 @@ protected Collection<Class<?>> annotatedEntities() {
34
44
@ BeforeEach
35
45
public void populateDb (VertxTestContext context ) {
36
46
Seed seed1 = new Seed ( 1 );
37
- Flower rose = new Flower ( seed1 , "Rose" );
47
+ rose = new Flower ( seed1 , "Rose" );
38
48
39
- Fruit cherry = new Fruit ( seed1 , "Cherry" );
49
+ cherry = new Fruit ( seed1 , "Cherry" );
40
50
cherry .addFriend ( rose );
41
51
42
52
Seed seed2 = new Seed ( 2 );
43
- Flower sunflower = new Flower ( seed2 , "Sunflower" );
53
+ sunflower = new Flower ( seed2 , "Sunflower" );
44
54
45
- Fruit apple = new Fruit ( seed2 , "Apple" );
55
+ apple = new Fruit ( seed2 , "Apple" );
46
56
apple .addFriend ( sunflower );
47
57
48
58
Seed seed3 = new Seed ( 3 );
49
- Flower chrysanthemum = new Flower ( seed3 , "Chrysanthemum" );
59
+ chrysanthemum = new Flower ( seed3 , "Chrysanthemum" );
50
60
51
- Fruit banana = new Fruit ( seed3 , "Banana" );
61
+ banana = new Fruit ( seed3 , "Banana" );
52
62
banana .addFriend ( chrysanthemum );
53
63
54
64
test (
@@ -60,11 +70,28 @@ public void populateDb(VertxTestContext context) {
60
70
}
61
71
62
72
@ Test
63
- public void test (VertxTestContext context ) {
73
+ public void testFindWithEmbeddedId (VertxTestContext context ) {
74
+ test (
75
+ context , getMutinySessionFactory ().withTransaction ( s -> s
76
+ .find ( Flower .class , chrysanthemum .getSeed () )
77
+ .invoke ( flower -> assertThat ( flower .getName () ).isEqualTo ( chrysanthemum .getName () ) )
78
+ )
79
+ );
80
+ }
81
+
82
+ @ Test
83
+ public void testSelectQueryWithEmbeddedId (VertxTestContext context ) {
64
84
test (
65
85
context , getMutinySessionFactory ().withTransaction ( s -> s
66
86
.createSelectionQuery ( "from Flower" , Flower .class )
67
87
.getResultList ()
88
+ .invoke ( list -> assertThat ( list .stream ().map ( Flower ::getName ) )
89
+ .containsExactlyInAnyOrder (
90
+ sunflower .getName (),
91
+ chrysanthemum .getName (),
92
+ rose .getName ()
93
+ )
94
+ )
68
95
)
69
96
);
70
97
}
0 commit comments