10
10
import static org .hibernate .reactive .testing .DatabaseSelectionRule .runOnlyFor ;
11
11
import static org .hibernate .reactive .testing .ReactiveAssertions .assertThrown ;
12
12
13
- import java .util .Collection ;
14
- import java .util .List ;
15
13
16
14
import org .hibernate .cfg .AvailableSettings ;
17
15
import org .hibernate .cfg .Configuration ;
18
16
import org .hibernate .reactive .testing .DatabaseSelectionRule ;
19
17
import org .junit .Rule ;
20
18
import org .junit .Test ;
21
19
20
+ import io .smallrye .mutiny .Uni ;
22
21
import io .vertx .ext .unit .TestContext ;
23
22
import jakarta .persistence .Entity ;
24
23
import jakarta .persistence .GeneratedValue ;
@@ -56,11 +55,6 @@ protected Configuration constructConfiguration() {
56
55
}
57
56
}
58
57
59
- @ Override
60
- protected Collection <Class <?>> annotatedEntities () {
61
- return List .of ( IntegerTypeEntity .class , LongTypeEntity .class , ShortTypeEntity .class );
62
- }
63
-
64
58
@ Override
65
59
protected Configuration constructConfiguration () {
66
60
Configuration configuration = super .constructConfiguration ();
@@ -69,44 +63,65 @@ protected Configuration constructConfiguration() {
69
63
return configuration ;
70
64
}
71
65
66
+ @ Override
67
+ public void before (TestContext context ) {
68
+ // Do nothing
69
+ }
70
+
71
+ @ Override
72
+ public void after (TestContext context ) {
73
+ super .after ( context );
74
+ closeFactory ( context );
75
+ }
76
+
72
77
@ Test
73
78
public void longIdentityType (TestContext context ) {
79
+ Configuration configuration = constructConfiguration ();
80
+ configuration .addAnnotatedClass ( LongTypeEntity .class );
81
+
74
82
LongTypeEntity entity = new LongTypeEntity ();
75
83
76
- test ( context , getMutinySessionFactory ()
77
- .withTransaction ( s -> s .persist ( entity ) )
78
- .invoke ( () -> {
79
- context .assertNotNull ( entity );
80
- context .assertTrue ( entity .id > 0 );
81
- } )
84
+ test ( context , Uni .createFrom ()
85
+ .completionStage ( setupSessionFactory ( configuration ) )
86
+ .chain ( () -> getMutinySessionFactory ().withTransaction ( s -> s .persist ( entity ) ) )
87
+ .invoke ( () -> assertThat ( entity )
88
+ .isNotNull ()
89
+ .satisfies ( it -> assertThat ( it .id ).isGreaterThan ( 0 ) )
90
+ )
82
91
);
83
92
}
84
93
85
94
@ Test
86
95
public void integerIdentityType (TestContext context ) {
87
- test ( context , assertThrown ( PersistenceException .class , getMutinySessionFactory ()
88
- .withTransaction ( s -> s .persist ( new IntegerTypeEntity () ) ) )
96
+ Configuration configuration = constructConfiguration ();
97
+ configuration .addAnnotatedClass ( IntegerTypeEntity .class );
98
+
99
+ test ( context , assertThrown ( PersistenceException .class , Uni .createFrom ()
100
+ .completionStage ( setupSessionFactory ( configuration ) )
101
+ .chain ( () -> getMutinySessionFactory ().withTransaction ( s -> s .persist ( new IntegerTypeEntity () ) ) ) )
89
102
.invoke ( exception -> validateErrorMessage ( Integer .class , IntegerTypeEntity .class , exception ) )
90
103
);
91
-
92
104
}
93
105
94
106
@ Test
95
107
public void shortIdentityType (TestContext context ) {
96
- test ( context , assertThrown ( PersistenceException .class , getMutinySessionFactory ()
97
- .withTransaction ( s -> s .persist ( new ShortTypeEntity () ) ) )
98
- .invoke ( exception -> validateErrorMessage ( Short .class , ShortTypeEntity .class , exception ) )
108
+ Configuration configuration = constructConfiguration ();
109
+ configuration .addAnnotatedClass ( ShortTypeEntity .class );
110
+
111
+ test ( context , assertThrown ( PersistenceException .class , Uni .createFrom ()
112
+ .completionStage ( setupSessionFactory ( configuration ) )
113
+ .chain ( () -> getMutinySessionFactory ().withTransaction ( s -> s .persist ( new ShortTypeEntity () ) ) ) )
114
+ .invoke ( exception -> validateErrorMessage ( Short .class , ShortTypeEntity .class , exception ) )
99
115
);
100
116
}
101
117
102
-
103
- private void validateErrorMessage (Class <?> idType , Class <?> entityTYpe , PersistenceException exception ) {
118
+ private void validateErrorMessage (Class <?> idType , Class <?> entityType , PersistenceException exception ) {
104
119
assertThat ( exception .getMessage () )
105
120
.as ( "Unexpected error code - this should be a CockroachDB specific issue" )
106
121
.contains ( "HR000073" );
107
122
assertThat ( exception .getMessage () )
108
123
.as ( "Error message should contain the entity name" )
109
- .contains ( entityTYpe .getName () );
124
+ .contains ( entityType .getName () );
110
125
assertThat ( exception .getMessage () )
111
126
.as ( "Error message should contain the invalid type" )
112
127
.contains ( idType .getName () );
0 commit comments