Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UniAsserter - introduce UniAsserterInterceptor #31014

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Feb 8, 2023

A typical implementation use case could be something like:

package org.acme;

import java.util.function.Supplier;
import io.quarkus.hibernate.reactive.panache.Panache;
import io.quarkus.test.vertx.UniAsserter;
import io.smallrye.mutiny.Uni;

public class TransactionalUniAsserterInterceptor extends UniAsserterInterceptor {

    public TransactionUniAsserterInterceptor(UniAsserter asserter) {
        super(asserter);
    }

    @Override
    protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) {
        return () -> Panache.withTransaction(uniSupplier);
    }
}

which basically "wraps" every assert and execute method with a database transaction.

And the usage looks like:

@RunOnVertxContext
@Test
public void testEntity(UniAsserter asserter) {
        asserter = new TransactionalUniAsserterInterceptor(asserter);
        asserter.execute(() -> new MyEntity().persist());
        asserter.assertEquals(() -> MyEntity.count(), 1l);
        asserter.execute(() -> MyEntity.deleteAll());
    }

@geoand
Copy link
Contributor

geoand commented Feb 8, 2023

I like it!

We should probably doument it in the Hibernate Reactive doc

@quarkus-bot

This comment has been minimized.

@mkouba mkouba force-pushed the uni-asserter-interceptor branch from 72cb87b to 0a41d84 Compare February 9, 2023 08:59
@mkouba
Copy link
Contributor Author

mkouba commented Feb 9, 2023

I like it!

We should probably doument it in the Hibernate Reactive doc

Done.

@github-actions
Copy link

github-actions bot commented Feb 9, 2023

🙈 The PR is closed and the preview is expired.

@quarkus-bot
Copy link

quarkus-bot bot commented Feb 9, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@mkouba mkouba merged commit f4b305e into quarkusio:main Feb 9, 2023
@quarkus-bot quarkus-bot bot added this to the 3.0 - main milestone Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants