29
29
import static org .hibernate .reactive .testing .ReactiveAssertions .assertThrown ;
30
30
31
31
/**
32
- * Test supported types for ids generated by CockroachDB
32
+ * Test supported types for ids generated by CockroachDB.
33
+ * <p>
34
+ * It won't work with {@link Short} and {@link Integer} because the id generated by CockroachDB don't map
35
+ * those types - they are less than 0 or bigger.
36
+ * </p>
33
37
*
34
38
* @see IdentityGeneratorTest
35
39
* @see IdentityGeneratorTypeTest
@@ -71,7 +75,7 @@ public void longIdentityType(TestContext context) {
71
75
LongTypeEntity entity = new LongTypeEntity ();
72
76
73
77
test ( context , getMutinySessionFactory ()
74
- .withTransaction ( ( s , tx ) -> s .persist ( entity ) )
78
+ .withTransaction ( s -> s .persist ( entity ) )
75
79
.invoke ( () -> {
76
80
context .assertNotNull ( entity );
77
81
context .assertTrue ( entity .id > 0 );
@@ -82,26 +86,39 @@ public void longIdentityType(TestContext context) {
82
86
@ Test
83
87
public void integerIdentityType (TestContext context ) {
84
88
test ( context , assertThrown ( PersistenceException .class , getMutinySessionFactory ()
85
- .withTransaction ( (s , tx ) -> s .persist ( new IntegerTypeEntity () ) ) )
86
- .invoke ( exception -> {
87
- assertThat ( exception .getMessage () ).contains ( "too big" );
88
- assertThat ( exception .getMessage () ).contains ( "Integer" );
89
- } )
89
+ .withTransaction ( s -> s .persist ( new IntegerTypeEntity () ) ) )
90
+ .invoke ( exception -> validateErrorMessage ( Integer .class , IntegerTypeEntity .class , exception ) )
90
91
);
91
92
92
93
}
93
94
94
95
@ Test
95
96
public void shortIdentityType (TestContext context ) {
96
97
test ( context , assertThrown ( PersistenceException .class , getMutinySessionFactory ()
97
- .withTransaction ( (s , tx ) -> s .persist ( new ShortTypeEntity () ) ) )
98
- .invoke ( exception -> {
99
- assertThat ( exception .getMessage () ).contains ( "too big" );
100
- assertThat ( exception .getMessage () ).contains ( "Short" );
101
- } )
98
+ .withTransaction ( s -> s .persist ( new ShortTypeEntity () ) ) )
99
+ .invoke ( exception -> validateErrorMessage ( Short .class , ShortTypeEntity .class , exception ) )
102
100
);
103
101
}
104
102
103
+
104
+ private void validateErrorMessage (Class <?> idType , Class <?> entityTYpe , PersistenceException exception ) {
105
+ assertThat ( exception .getMessage () )
106
+ .as ( "Unexpected error code - this should be a CockroachDB specific issue" )
107
+ .contains ( "HR000073" );
108
+ assertThat ( exception .getMessage () )
109
+ .as ( "Error message should contain the entity name" )
110
+ .contains ( entityTYpe .getName () );
111
+ assertThat ( exception .getMessage () )
112
+ .as ( "Error message should contain the invalid type" )
113
+ .contains ( idType .getName () );
114
+ assertThat ( exception .getMessage () )
115
+ .as ( "Error message should contain the valid type" )
116
+ .contains ( Long .class .getName () );
117
+ assertThat ( exception .getMessage () )
118
+ .as ( "Error message should mention that it happens only for CockroachDB" )
119
+ .contains ( "CockroachDB" );
120
+ }
121
+
105
122
interface TypeIdentity <T extends Number > {
106
123
T getId ();
107
124
}
0 commit comments