use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.
the class MultiplePersistenceUnitsCdiTest method testDefaultSession.
@Test
@ActivateRequestContext
public void testDefaultSession() {
DefaultPUEntity entity = new DefaultPUEntity("someText");
inTransaction(() -> defaultPUSession.toEntityManager().persist(entity));
inTransaction(() -> assertThat(defaultPUSession.search(DefaultPUEntity.class).where(f -> f.matchAll()).fetchHits(20)).hasSize(1).element(0).returns(entity.getId(), DefaultPUEntity::getId));
}
use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.
the class MultiplePersistenceUnitsCdiTest method testPU2Session.
@Test
@ActivateRequestContext
public void testPU2Session() {
PU2Entity entity = new PU2Entity("someText");
inTransaction(() -> pu2Session.toEntityManager().persist(entity));
inTransaction(() -> assertThat(pu2Session.search(PU2Entity.class).where(f -> f.matchAll()).fetchHits(20)).hasSize(1).element(0).returns(entity.getId(), PU2Entity::getId));
}
use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.
the class QuarkusTransactionTest method testCallJoinExisting.
@Test
@ActivateRequestContext
public void testCallJoinExisting() throws SystemException {
RunOptions options = runOptions().semantic(RunOptions.Semantic.JOIN_EXISTING);
QuarkusTransaction.begin();
var tx = transactionManager.getTransaction();
QuarkusTransaction.call(options, () -> {
Assertions.assertTrue(QuarkusTransaction.isActive());
if (tx != transactionManager.getTransaction()) {
throw new RuntimeException("Running in different transaction");
}
return null;
});
}
use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.
the class QuarkusTransactionTest method testCallDisallowExisting.
@Test
@ActivateRequestContext
public void testCallDisallowExisting() {
RunOptions options = runOptions().semantic(RunOptions.Semantic.DISALLOW_EXISTING);
Assertions.assertEquals(Status.STATUS_COMMITTED, QuarkusTransaction.call(options, this::register).completionStatus);
QuarkusTransaction.begin();
Assertions.assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.call(options, this::register));
}
use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.
the class QuarkusTransactionTest method testCallRequiresNew.
@Test
@ActivateRequestContext
public void testCallRequiresNew() throws SystemException {
RunOptions options = runOptions().semantic(RunOptions.Semantic.REQUIRE_NEW);
QuarkusTransaction.begin();
var tx = transactionManager.getTransaction();
QuarkusTransaction.call(options, () -> {
Assertions.assertTrue(QuarkusTransaction.isActive());
if (tx == transactionManager.getTransaction()) {
throw new RuntimeException("Running in same transaction");
}
return null;
});
}
Aggregations