-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #11798 from stuartwdouglas/testtransaction
Add the @TestTransaction annotation
- Loading branch information
Showing
15 changed files
with
334 additions
and
29 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
21 changes: 21 additions & 0 deletions
21
.../main/java/io/quarkus/hibernate/orm/deployment/test/HibernateTestTransactionCallback.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,21 @@ | ||
package io.quarkus.hibernate.orm.deployment.test; | ||
|
||
import javax.enterprise.inject.spi.CDI; | ||
import javax.persistence.EntityManager; | ||
|
||
import io.quarkus.narayana.jta.runtime.test.TestTransactionCallback; | ||
|
||
public class HibernateTestTransactionCallback implements TestTransactionCallback { | ||
@Override | ||
public void postBegin() { | ||
|
||
} | ||
|
||
@Override | ||
public void preRollback() { | ||
for (EntityManager i : CDI.current().select(EntityManager.class)) { | ||
i.flush(); | ||
} | ||
|
||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/META-INF/services/io.quarkus.narayana.jta.runtime.test.TestTransactionCallback
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.hibernate.orm.deployment.test.HibernateTestTransactionCallback |
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
46 changes: 46 additions & 0 deletions
46
...src/main/java/io/quarkus/narayana/jta/runtime/interceptor/TestTransactionInterceptor.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,46 @@ | ||
package io.quarkus.narayana.jta.runtime.interceptor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.ServiceLoader; | ||
|
||
import javax.inject.Inject; | ||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.InvocationContext; | ||
import javax.transaction.UserTransaction; | ||
|
||
import io.quarkus.narayana.jta.runtime.test.TestTransactionCallback; | ||
|
||
public class TestTransactionInterceptor { | ||
|
||
static final List<TestTransactionCallback> CALLBACKS; | ||
|
||
static { | ||
List<TestTransactionCallback> callbacks = new ArrayList<>(); | ||
for (TestTransactionCallback i : ServiceLoader.load(TestTransactionCallback.class)) { | ||
callbacks.add(i); | ||
} | ||
CALLBACKS = callbacks; | ||
} | ||
|
||
@Inject | ||
UserTransaction userTransaction; | ||
|
||
@AroundInvoke | ||
public Object intercept(InvocationContext context) throws Exception { | ||
try { | ||
userTransaction.begin(); | ||
for (TestTransactionCallback i : CALLBACKS) { | ||
i.postBegin(); | ||
} | ||
Object result = context.proceed(); | ||
for (TestTransactionCallback i : CALLBACKS) { | ||
i.preRollback(); | ||
} | ||
return result; | ||
} finally { | ||
userTransaction.rollback(); | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...a/runtime/src/main/java/io/quarkus/narayana/jta/runtime/test/TestTransactionCallback.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,9 @@ | ||
package io.quarkus.narayana.jta.runtime.test; | ||
|
||
public interface TestTransactionCallback { | ||
|
||
void postBegin(); | ||
|
||
void preRollback(); | ||
|
||
} |
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
17 changes: 17 additions & 0 deletions
17
...ts/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/inheritance/Interceptor1.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,17 @@ | ||
package io.quarkus.arc.test.interceptors.inheritance; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.Interceptor; | ||
import javax.interceptor.InvocationContext; | ||
|
||
@One | ||
@Interceptor | ||
public class Interceptor1 extends OverridenInterceptor { | ||
|
||
@AroundInvoke | ||
@Override | ||
public Object intercept(InvocationContext ctx) throws Exception { | ||
return ctx.proceed() + "1"; | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...ts/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/inheritance/Interceptor2.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,9 @@ | ||
package io.quarkus.arc.test.interceptors.inheritance; | ||
|
||
import javax.interceptor.Interceptor; | ||
|
||
@Two | ||
@Interceptor | ||
public class Interceptor2 extends OverridenInterceptor { | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...src/test/java/io/quarkus/arc/test/interceptors/inheritance/InterceptorSuperclassTest.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,44 @@ | ||
package io.quarkus.arc.test.interceptors.inheritance; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
/** | ||
* "Around-invoke methods may be defined on interceptor classes and/or the target class and/or super- | ||
* classes of the target class or the interceptor classes. However, only one around-invoke method may be | ||
* defined on a given class." | ||
*/ | ||
public class InterceptorSuperclassTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(Interceptor1.class, Interceptor2.class, One.class, Two.class, | ||
OverridenInterceptor.class, Fool.class); | ||
|
||
@Test | ||
public void testInterception() { | ||
Fool fool = Arc.container().instance(Fool.class).get(); | ||
assertEquals("ping1", fool.pingOne()); | ||
assertEquals("pingoverriden", fool.pingTwo()); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class Fool { | ||
|
||
@One | ||
String pingOne() { | ||
return "ping"; | ||
} | ||
|
||
@Two | ||
String pingTwo() { | ||
return "ping"; | ||
} | ||
|
||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...nt-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/inheritance/One.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,18 @@ | ||
package io.quarkus.arc.test.interceptors.inheritance; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface One { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...ests/src/test/java/io/quarkus/arc/test/interceptors/inheritance/OverridenInterceptor.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,12 @@ | ||
package io.quarkus.arc.test.interceptors.inheritance; | ||
|
||
import javax.interceptor.AroundInvoke; | ||
import javax.interceptor.InvocationContext; | ||
|
||
public class OverridenInterceptor { | ||
|
||
@AroundInvoke | ||
public Object intercept(InvocationContext ctx) throws Exception { | ||
return ctx.proceed() + "overriden"; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...nt-projects/arc/tests/src/test/java/io/quarkus/arc/test/interceptors/inheritance/Two.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,18 @@ | ||
package io.quarkus.arc.test.interceptors.inheritance; | ||
|
||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.interceptor.InterceptorBinding; | ||
|
||
@Target({ TYPE, METHOD }) | ||
@Retention(RUNTIME) | ||
@Documented | ||
@InterceptorBinding | ||
public @interface Two { | ||
|
||
} |
Oops, something went wrong.