-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34334 from mkouba/test-hibernate-reactive-panache
Introduce quarkus-test-hibernate-reactive-panache module
- Loading branch information
Showing
11 changed files
with
170 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...ve-panache/src/test/java/io/quarkus/it/panache/reactive/TransactionalUniAsserterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.quarkus.it.panache.reactive; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.hibernate.reactive.panache.Panache; | ||
import io.quarkus.test.hibernate.reactive.panache.TransactionalUniAsserter; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.vertx.RunOnVertxContext; | ||
|
||
@QuarkusTest | ||
public class TransactionalUniAsserterTest { | ||
|
||
@RunOnVertxContext | ||
@Test | ||
public void testTransactionalUniAsserter(TransactionalUniAsserter asserter) { | ||
assertNotNull(asserter); | ||
asserter.assertThat(() -> Panache.currentTransaction(), transaction -> { | ||
assertNotNull(transaction); | ||
assertFalse(transaction.isMarkedForRollback()); | ||
asserter.putData("tx", transaction); | ||
}); | ||
asserter.assertThat(() -> Panache.currentTransaction(), transaction -> { | ||
assertNotNull(transaction); | ||
assertFalse(transaction.isMarkedForRollback()); | ||
assertNotEquals(transaction, asserter.getData("tx")); | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-test-framework</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>quarkus-test-hibernate-reactive-panache</artifactId> | ||
<name>Quarkus - Test framework - Hibernate Reactive Panache</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-hibernate-reactive-panache-common</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-test-vertx</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-vertx</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.smallrye.reactive</groupId> | ||
<artifactId>mutiny</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
26 changes: 26 additions & 0 deletions
26
...he/src/main/java/io/quarkus/test/hibernate/reactive/panache/TransactionalUniAsserter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.quarkus.test.hibernate.reactive.panache; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import io.quarkus.hibernate.reactive.panache.common.runtime.SessionOperations; | ||
import io.quarkus.test.vertx.UniAsserter; | ||
import io.quarkus.test.vertx.UniAsserterInterceptor; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
/** | ||
* A {@link UniAsserterInterceptor} that wraps each assert method within a separate reactive transaction. | ||
* | ||
* @see UniAsserter | ||
*/ | ||
public final class TransactionalUniAsserter extends UniAsserterInterceptor { | ||
|
||
TransactionalUniAsserter(UniAsserter asserter) { | ||
super(asserter); | ||
} | ||
|
||
@Override | ||
protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) { | ||
return () -> SessionOperations.withTransaction(() -> uniSupplier.get()); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...io/quarkus/test/hibernate/reactive/panache/TransactionalUniAsserterTestMethodInvoker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.quarkus.test.hibernate.reactive.panache; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import io.quarkus.test.vertx.DefaultUniAsserter; | ||
import io.quarkus.test.vertx.RunOnVertxContextTestMethodInvoker; | ||
import io.quarkus.test.vertx.UniAsserter; | ||
|
||
public class TransactionalUniAsserterTestMethodInvoker extends RunOnVertxContextTestMethodInvoker { | ||
|
||
private UniAsserter uniAsserter; | ||
|
||
@Override | ||
public boolean handlesMethodParamType(String paramClassName) { | ||
return TransactionalUniAsserter.class.getName().equals(paramClassName); | ||
} | ||
|
||
@Override | ||
public Object methodParamInstance(String paramClassName) { | ||
if (!handlesMethodParamType(paramClassName)) { | ||
throw new IllegalStateException( | ||
"TransactionalUniAsserterTestMethodInvoker does not handle '" + paramClassName + "' method param types"); | ||
} | ||
uniAsserter = new TransactionalUniAsserter(new DefaultUniAsserter()); | ||
return uniAsserter; | ||
} | ||
|
||
@Override | ||
public boolean supportsMethod(Class<?> originalTestClass, Method originalTestMethod) { | ||
return hasSupportedAnnotation(originalTestClass, originalTestMethod) | ||
&& hasSupportedParams(originalTestMethod); | ||
} | ||
|
||
private boolean hasSupportedParams(Method originalTestMethod) { | ||
return originalTestMethod.getParameterCount() == 1 | ||
// we need to use the class name to avoid ClassLoader issues | ||
&& originalTestMethod.getParameterTypes()[0].getName().equals(TransactionalUniAsserter.class.getName()); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...e-reactive-panache/src/main/resources/META-INF/services/io.quarkus.test.TestMethodInvoker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.test.hibernate.reactive.panache.TransactionalUniAsserterTestMethodInvoker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters