1616import jakarta .persistence .GeneratedValue ;
1717import jakarta .persistence .Id ;
1818
19+ import static org .assertj .core .api .Assertions .assertThat ;
20+
1921/**
2022 * Verifies that scheduled changes in the reactive session
2123 * are being auto-flushed before a mutation query on the same
@@ -30,68 +32,44 @@ protected Collection<Class<?>> annotatedEntities() {
3032
3133 @ Test
3234 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+ ) )
6250 );
6351 }
6452
6553 @ Test
6654 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+ ) )
9573 );
9674 }
9775
@@ -101,14 +79,19 @@ private static Person newPerson(String name) {
10179 return person ;
10280 }
10381
104- @ Entity (name = "Person" )
82+ @ Entity (name = "Person" )
10583 public static class Person {
10684
10785 @ Id
10886 @ GeneratedValue
10987 Integer id ;
11088
11189 String name ;
90+
91+ @ Override
92+ public String toString () {
93+ return name ;
94+ }
11295 }
11396
11497}
0 commit comments