Skip to content

Commit d747770

Browse files
committed
[#2412] Add additional tests
1 parent a5e96c6 commit d747770

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,66 @@ public void testHqlInsertWithTransaction(VertxTestContext context) {
208208
);
209209
}
210210

211+
@Test
212+
public void testHqlUpdate(VertxTestContext context) {
213+
final Integer id = 1;
214+
final String title = "Spell Book: A Comprehensive Guide to Magic Spells and Incantations";
215+
test( context, getMutinySessionFactory().withTransaction( session -> session
216+
.createMutationQuery( "insert into SpellBook (id, title, forbidden) values (:id, :title, :forbidden)" )
217+
.setParameter( "id", id )
218+
.setParameter( "title", title )
219+
.setParameter( "forbidden", true )
220+
.executeUpdate() )
221+
.call( () -> getMutinySessionFactory().withTransaction( session -> session
222+
.createMutationQuery(
223+
"update SpellBook set id = :id, title = :newTitle, forbidden = :newForbidden where forbidden = :forbidden and title = :title" )
224+
.setParameter( "id", id )
225+
.setParameter( "title", title )
226+
.setParameter( "forbidden", true )
227+
.setParameter( "newTitle", "new title" )
228+
.setParameter( "newForbidden", false )
229+
.executeUpdate() )
230+
)
231+
.call( () -> getMutinySessionFactory().withTransaction( session -> session
232+
.createSelectionQuery( "from SpellBook g where g.id = :id ", SpellBook.class )
233+
.setParameter( "id", id )
234+
.getSingleResult()
235+
.invoke( spellBook -> {
236+
assertThat( spellBook.getTitle() ).isEqualTo( "new title" );
237+
assertThat( spellBook.forbidden ).isFalse();
238+
}
239+
)
240+
) )
241+
);
242+
}
243+
244+
@Test
245+
public void testHqlDelete(VertxTestContext context) {
246+
final Integer id = 1;
247+
final String title = "Spell Book: A Comprehensive Guide to Magic Spells and Incantations";
248+
test( context, getMutinySessionFactory().withTransaction( session -> session
249+
.createMutationQuery( "insert into SpellBook (id, title, forbidden) values (:id, :title, :forbidden)" )
250+
.setParameter( "id", id )
251+
.setParameter( "title", title )
252+
.setParameter( "forbidden", true )
253+
.executeUpdate() )
254+
.call( () -> getMutinySessionFactory().withTransaction( session -> session
255+
.createMutationQuery(
256+
"delete from SpellBook where id = :id and forbidden = :forbidden and title = :title" )
257+
.setParameter( "id", id )
258+
.setParameter( "title", title )
259+
.setParameter( "forbidden", true )
260+
.executeUpdate() )
261+
)
262+
.call( () -> getMutinySessionFactory().withTransaction( session -> session
263+
.createSelectionQuery( "from SpellBook g where g.id = :id ", SpellBook.class )
264+
.setParameter( "id", id )
265+
.getSingleResultOrNull()
266+
.invoke( Assertions::assertNull ) )
267+
)
268+
);
269+
}
270+
211271
@Entity(name="SpellBook")
212272
@Table(name = "SpellBookJS")
213273
@DiscriminatorValue("S")

0 commit comments

Comments
 (0)