16
16
import jakarta .persistence .GeneratedValue ;
17
17
import jakarta .persistence .Id ;
18
18
19
+ import static org .assertj .core .api .Assertions .assertThat ;
20
+
19
21
/**
20
22
* Verifies that scheduled changes in the reactive session
21
23
* are being auto-flushed before a mutation query on the same
@@ -30,68 +32,44 @@ protected Collection<Class<?>> annotatedEntities() {
30
32
31
33
@ Test
32
34
public void testPersistThenDelete (TestContext context ) {
33
- test (context ,
34
- getSessionFactory ().withTransaction (
35
- (s , t ) -> s .persist ( newPerson ( "foo" ), newPerson ( "bar" ), newPerson ( "baz" ) )
36
- )
37
- .thenCompose (
38
- v ->
39
- getSessionFactory ().withTransaction (
40
- (s , t ) -> s .createQuery ( "from Person" ).getResultList ().thenAccept ( l ->
41
- context .assertEquals ( 3 , l .size () )
42
- )
43
- )
44
- )
45
- .thenCompose (
46
- v ->
47
- getSessionFactory ().withTransaction (
48
- (s , t ) ->
49
- s .persist ( newPerson ( "critical" ) )
50
- .thenCompose ( vo -> s .createQuery ( "delete from Person" )
51
- .executeUpdate () )
52
- )
53
- )
54
- .thenCompose (
55
- v ->
56
- getSessionFactory ().withTransaction (
57
- (s , t ) -> s .createQuery ( "from Person" ).getResultList ().thenAccept ( l ->
58
- context .assertEquals ( 0 , l .size () )
59
- )
60
- )
61
- )
35
+ test ( context , getSessionFactory ()
36
+ .withTransaction ( s -> s
37
+ .persist ( newPerson ( "foo" ), newPerson ( "bar" ), newPerson ( "baz" ) ) )
38
+ .thenCompose ( v -> getSessionFactory ().withTransaction ( s -> s
39
+ .createQuery ( "from Person" ).getResultList ()
40
+ .thenAccept ( l -> assertThat ( l ).hasSize ( 3 ) )
41
+ ) )
42
+ .thenCompose ( v -> getSessionFactory ().withTransaction ( s -> s
43
+ .persist ( newPerson ( "critical" ) )
44
+ .thenCompose ( vo -> s .createQuery ( "delete from Person" ).executeUpdate () )
45
+ ) )
46
+ .thenCompose ( v -> getSessionFactory ().withTransaction ( s -> s
47
+ .createQuery ( "from Person" ).getResultList ()
48
+ .thenAccept ( l -> assertThat ( l ).isEmpty () )
49
+ ) )
62
50
);
63
51
}
64
52
65
53
@ Test
66
54
public void testDeleteThenPersist (TestContext context ) {
67
- test (context ,
68
- getSessionFactory ().withTransaction (
69
- (s , t ) -> s .persist ( newPerson ( "foo" ), newPerson ( "bar" ), newPerson ( "baz" ) )
70
- )
71
- .thenCompose (
72
- v ->
73
- getSessionFactory ().withTransaction (
74
- (s , t ) -> s .createQuery ( "from Person" ).getResultList ().thenAccept ( l ->
75
- context .assertEquals ( 3 , l .size () )
76
- )
77
- )
78
- )
79
- .thenCompose (
80
- v ->
81
- getSessionFactory ().withTransaction (
82
- (s , t ) ->
83
- s .createQuery ( "delete from Person" ).executeUpdate ()
84
- .thenCompose ( vo -> s .persist ( newPerson ( "critical" ) ) )
85
- )
86
- )
87
- .thenCompose (
88
- v ->
89
- getSessionFactory ().withTransaction (
90
- (s , t ) -> s .createQuery ( "from Person" ).getResultList ().thenAccept ( l ->
91
- context .assertEquals ( 1 , l .size () )
92
- )
93
- )
94
- )
55
+ test ( context , getSessionFactory ()
56
+ .withTransaction ( s -> s
57
+ .persist ( newPerson ( "foo" ), newPerson ( "bar" ), newPerson ( "baz" ) ) )
58
+ .thenCompose ( v -> getSessionFactory ().withTransaction ( s -> s
59
+ .createQuery ( "from Person" )
60
+ .getResultList ()
61
+ .thenAccept ( l -> assertThat ( l ).hasSize ( 3 ) )
62
+ ) )
63
+ .thenCompose ( v -> getSessionFactory ().withTransaction ( s -> s
64
+ .createQuery ( "delete from Person" )
65
+ .executeUpdate ()
66
+ .thenCompose ( vo -> s .persist ( newPerson ( "critical" ) ) )
67
+ ) )
68
+ .thenCompose ( v -> getSessionFactory ().withTransaction ( s -> s
69
+ .createQuery ( "from Person" )
70
+ .getResultList ()
71
+ .thenAccept ( l -> assertThat ( l ).hasSize ( 1 ) )
72
+ ) )
95
73
);
96
74
}
97
75
@@ -101,14 +79,19 @@ private static Person newPerson(String name) {
101
79
return person ;
102
80
}
103
81
104
- @ Entity (name = "Person" )
82
+ @ Entity (name = "Person" )
105
83
public static class Person {
106
84
107
85
@ Id
108
86
@ GeneratedValue
109
87
Integer id ;
110
88
111
89
String name ;
90
+
91
+ @ Override
92
+ public String toString () {
93
+ return name ;
94
+ }
112
95
}
113
96
114
97
}
0 commit comments