Skip to content

Commit 94f2f9c

Browse files
dreab8DavideD
authored andcommitted
[hibernate#1906] Fix MutationDelegateTest, MutationDelegateJoinedInheritanceTest and MutationDelegateIdentityTest update query assertions
1 parent ed22492 commit 94f2f9c

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MutationDelegateIdentityTest.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ public void testUpdateGeneratedValuesAndIdentity(VertxTestContext context) {
142142
.invoke( identityAndValues -> {
143143
assertThat( entity.getUpdateDate() ).isNotNull();
144144
assertThat( sqlTracker.getLoggedQueries().size() ).isEqualTo( expectedQuerySize );
145-
assertThat( sqlTracker.getLoggedQueries().get( 0 ) )
146-
.startsWith( "select" ).contains( "update" );
145+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).startsWith( "select" );
146+
assertThat( sqlTracker.getLoggedQueries().get( 1 ) ).contains( "update " );
147147
} )
148148
) )
149149
);
@@ -182,7 +182,7 @@ public void testInsertGeneratedValuesAndIdentityAndRowId(VertxTestContext contex
182182
.call( s::flush )
183183
.invoke( () -> {
184184
assertThat( entity.getUpdateDate() ).isNotNull();
185-
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "update" );
185+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "update " );
186186
assertNumberOfOccurrenceInQueryNoSpace( 0, "id_column", shouldHaveRowId ? 0 : 1 );
187187
} )
188188
)
@@ -227,10 +227,19 @@ public void testInsertGeneratedValuesAndIdentityAndRowIdAndNaturalId(VertxTestCo
227227
);
228228
}
229229

230+
/**
231+
* The method is used to verify that the query logged at position `queryNumber`
232+
* contains the `expectedNumberOfOccurrences` occurrences of the value `toCkeck`.
233+
* e.g. `assertNumberOfOccurrenceInQueryNoSpace(1, "id", 3)` verifies the 1st executed query contains 3 occurrences of `id`
234+
*
235+
* @param queryNumber the position of the logged query
236+
* @param toCheck the String we want to check the number of occurrences in the query
237+
* @param expectedNumberOfOccurrences the number of occurrences of the `toCkeck` value we expect
238+
*/
230239
private static void assertNumberOfOccurrenceInQueryNoSpace(int queryNumber, String toCheck, int expectedNumberOfOccurrences) {
231240
String query = sqlTracker.getLoggedQueries().get( queryNumber );
232241
int actual = query.split( toCheck, -1 ).length - 1;
233-
assertThat( actual ).as( "number of " + toCheck ).isEqualTo( expectedNumberOfOccurrences );
242+
assertThat( actual ).as( "Unexpected number of '" + toCheck + "' in the query " + query ).isEqualTo( expectedNumberOfOccurrences );
234243
}
235244

236245
private static GeneratedValuesMutationDelegate getDelegate(Class<?> entityClass, MutationType mutationType) {

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MutationDelegateJoinedInheritanceTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ public void testUpdateBaseEntity(VertxTestContext context) {
136136
.invoke( baseEntity -> {
137137
assertThat( entity.getUpdateDate() ).isNotNull();
138138
assertThat( sqlTracker.getLoggedQueries() ).hasSize( expectedQueriesSize );
139-
assertThat( sqlTracker.getLoggedQueries().get( 0 ) )
140-
.startsWith( "select" ).contains( "update" );
139+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).startsWith( "select" );
140+
assertThat( sqlTracker.getLoggedQueries().get( 1 ) ).contains( "update " );
141141
} )
142142
)
143143
)
@@ -158,7 +158,8 @@ public void testUpdateChildEntity(VertxTestContext context) {
158158
assertThat( entity.getChildUpdateDate() ).isNotNull();
159159

160160
assertThat( sqlTracker.getLoggedQueries() ).hasSize( 3 );
161-
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).startsWith( "select" ).contains( "update" );
161+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).startsWith( "select" );
162+
assertThat( sqlTracker.getLoggedQueries().get( 1 ) ).contains( "update " );
162163
// Note: this is a current restriction, mutation delegates only retrieve generated values
163164
// on the "root" table, and we expect other values to be read through a subsequent select
164165
assertThat( sqlTracker.getLoggedQueries().get( 2 ) ).startsWith( "select" );

hibernate-reactive-core/src/test/java/org/hibernate/reactive/MutationDelegateTest.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ public void testUpdateGeneratedValues(VertxTestContext context) {
111111
.invoke( valuesOnly -> {
112112
assertThat( entity.getUpdateDate() ).isNotNull();
113113
assertThat( sqlTracker.getLoggedQueries() ).hasSize( expectedQueriesSize );
114-
assertThat( sqlTracker.getLoggedQueries().get( 0 ) )
115-
.startsWith( "select" )
116-
.contains( "update" );
114+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).startsWith( "select" );
115+
assertThat( sqlTracker.getLoggedQueries().get( 1 ) ).contains( "update " );
117116
} )
118117
)
119118
);
@@ -147,7 +146,7 @@ public void testGeneratedValuesAndRowId(VertxTestContext context) {
147146
} )
148147
.call( s::flush )
149148
.invoke( () -> {
150-
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "update" );
149+
assertThat( sqlTracker.getLoggedQueries().get( 0 ) ).contains( "update " );
151150
assertNumberOfOccurrenceInQueryNoSpace( 0, "id_column", shouldHaveRowId ? 0 : 1 );
152151
} )
153152
)
@@ -181,10 +180,19 @@ public void testInsertGeneratedValuesAndNaturalId(VertxTestContext context) {
181180
);
182181
}
183182

183+
/**
184+
* The method is used to verify that the query logged at position `queryNumber`
185+
* contains the `expectedNumberOfOccurrences` occurrences of the value `toCkeck`.
186+
* e.g. `assertNumberOfOccurrenceInQueryNoSpace(1, "id", 3)` verifies the 1st executed query contains 3 occurrences of `id`
187+
*
188+
* @param queryNumber the position of the logged query
189+
* @param toCheck the String we want to check the number of occurrences in the query
190+
* @param expectedNumberOfOccurrences the number of occurrences of the `toCkeck` value we expect
191+
*/
184192
private static void assertNumberOfOccurrenceInQueryNoSpace(int queryNumber, String toCheck, int expectedNumberOfOccurrences) {
185193
String query = sqlTracker.getLoggedQueries().get( queryNumber );
186194
int actual = query.split( toCheck, -1 ).length - 1;
187-
assertThat( actual ).as( "number of " + toCheck ).isEqualTo( expectedNumberOfOccurrences );
195+
assertThat( actual ).as( "Unexpected number of '" + toCheck + "' in the query " + query ).isEqualTo( expectedNumberOfOccurrences );
188196
}
189197

190198
private static GeneratedValuesMutationDelegate getDelegate(Class<?> entityClass, MutationType mutationType) {

0 commit comments

Comments
 (0)