liveBook · Manning

TransactionalUniAsserter

As explained in Quarkus in Action

TransactionalUniAsserter is a testing API that performs assertions on Uni results while wrapping each operation in a new transaction.

TransactionalUniAsserter tests Hibernate Reactive persistence without treating asynchronous Uni operations like ordinary synchronous calls. Inject it into a test running on the Vert.x event-loop thread; each asserted operation executes in a new transaction. section 7.7.2

Use the asserter to coordinate reactive persistence checks:

  • Call assertThat with a Uni-producing operation and verify its result with assertions. section 7.7.2
  • Use assertEquals for follow-up asynchronous queries such as counting persisted entities. section 7.7.2
  • Pass values between operations with putData and getData, such as a generated reservation identifier. section 7.7.2

Reservation persistence test

A test creates a reservation with asserter.assertThat(() -> reservation.persist(), ...), verifies its generated identifier, stores that identifier with putData, counts persisted reservations, and retrieves the entity with findById(getData(...)). section 7.7.2

Listing 7.43 Reactive invocations in the ReservationPersistenceTest
@Test
@RunOnVertxContext
public void testCreateReservation(TransactionalUniAsserter asserter) {
    Reservation reservation = new Reservation();
    reservation.startDay = LocalDate.now().plus(5, ChronoUnit.DAYS);
    reservation.endDay = LocalDate.now().plus(12, ChronoUnit.DAYS);
    reservation.carId = 384L;

    asserter.<Reservation>assertThat(() -> reservation.persist(),
        r -> {
            Assertions.assertNotNull(r.id);
            asserter.putData("reservation.id", r.id);
        });

    asserter.assertEquals(() -> Reservation.count(), 1L);
    asserter.assertThat(() -> Reservation.<Reservation>findById(
            asserter.getData("reservation.id")),
        persistedReservation -> {
            Assertions.assertNotNull(persistedReservation);
            Assertions.assertEquals(reservation.carId,
                persistedReservation.carId);
        });
}

Inspect the complete reactive invocation pattern for creating, counting, and retrieving a reservation. section 7.7.2

How Quarkus in Action covers it

How deep it goes
Explains event-loop execution, per-operation transactions, JUnit-like assertions, and asynchronous data passing; defers base UniAsserter customization.
Examples
Uses reservation creation, counting, lookup, generated identifiers, and asserter data storage.
What you can do after
Apply it via quarkus-test-hibernate-reactive-panache to write transaction-aware assertions for reactive persistence tests.
How it connects
Connects Uni results with Vert.x contexts, Hibernate Reactive, transactions, and JUnit assertions.

This explainer was generated by Manning's knowledge graph from the text of Quarkus in Action. The section links point to the parts of the book it draws on.