1010import static org .hibernate .reactive .testing .DatabaseSelectionRule .runOnlyFor ;
1111import static org .hibernate .reactive .testing .ReactiveAssertions .assertThrown ;
1212
13- import java .util .Collection ;
14- import java .util .List ;
1513
1614import org .hibernate .cfg .AvailableSettings ;
1715import org .hibernate .cfg .Configuration ;
1816import org .hibernate .reactive .testing .DatabaseSelectionRule ;
1917import org .junit .Rule ;
2018import org .junit .Test ;
2119
20+ import io .smallrye .mutiny .Uni ;
2221import io .vertx .ext .unit .TestContext ;
2322import jakarta .persistence .Entity ;
2423import jakarta .persistence .GeneratedValue ;
@@ -56,11 +55,6 @@ protected Configuration constructConfiguration() {
5655 }
5756 }
5857
59- @ Override
60- protected Collection <Class <?>> annotatedEntities () {
61- return List .of ( IntegerTypeEntity .class , LongTypeEntity .class , ShortTypeEntity .class );
62- }
63-
6458 @ Override
6559 protected Configuration constructConfiguration () {
6660 Configuration configuration = super .constructConfiguration ();
@@ -69,44 +63,65 @@ protected Configuration constructConfiguration() {
6963 return configuration ;
7064 }
7165
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+
7277 @ Test
7378 public void longIdentityType (TestContext context ) {
79+ Configuration configuration = constructConfiguration ();
80+ configuration .addAnnotatedClass ( LongTypeEntity .class );
81+
7482 LongTypeEntity entity = new LongTypeEntity ();
7583
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+ )
8291 );
8392 }
8493
8594 @ Test
8695 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 () ) ) ) )
89102 .invoke ( exception -> validateErrorMessage ( Integer .class , IntegerTypeEntity .class , exception ) )
90103 );
91-
92104 }
93105
94106 @ Test
95107 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 ) )
99115 );
100116 }
101117
102-
103- private void validateErrorMessage (Class <?> idType , Class <?> entityTYpe , PersistenceException exception ) {
118+ private void validateErrorMessage (Class <?> idType , Class <?> entityType , PersistenceException exception ) {
104119 assertThat ( exception .getMessage () )
105120 .as ( "Unexpected error code - this should be a CockroachDB specific issue" )
106121 .contains ( "HR000073" );
107122 assertThat ( exception .getMessage () )
108123 .as ( "Error message should contain the entity name" )
109- .contains ( entityTYpe .getName () );
124+ .contains ( entityType .getName () );
110125 assertThat ( exception .getMessage () )
111126 .as ( "Error message should contain the invalid type" )
112127 .contains ( idType .getName () );
0 commit comments