@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(MyTransactionalTxTypeBean.class);
}
cd javaee7-samples/jta/transactional/Now we are ready to start testing. You can run all the tests in this sample by executing:
mvn test
Or you can run individual tests by executing one of the following:mvn test -Dtest=MyTransactionalTxTypeBeanTestmvn test -Dtest=MyTransactionalBeanWithUserTransactionTestmvn test -Dtest=MyTransactionalBeanTest
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class)
.addClass(MyTransactionalTxTypeBean.class);
}
@Test
public void should_required_work() {
bean.required();
}
@Test
public void should_requiresNew_work() {
bean.requiresNew();
}
@Test(expected = TransactionalException.class)
public void should_mandatory_throw_exception() {
bean.mandatory();
}
@Test
public void should_supports_work() {
bean.supports();
}
@Test
public void should_notSupported_work() {
bean.notSupported();
}
@Test
public void should_never_work() {
bean.never();
}
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(MyTransactionalBean.class, MyTransactionScopedBean.class)
.addAsManifestResource("beans.xml");
}
@Test
public void should_withTransaction_have_only_one_instance_injected() throws Exception{
ut.begin();
bean.withTransaction();
ut.commit();
assertThat("bean1 and bean2 should the same object", bean.id1, is(bean.id2));
}
@Test
public void should_withTransaction_called_twice_have_same_instances_injected() throws Exception {
ut.begin();
bean.withTransaction();
String firstId1 = bean.id1;
bean.withTransaction();
String secondId1 = bean.id1;
ut.commit();
assertThat("bean1 should change between scenarios", firstId1, is(secondId1));
}
@Test
public void should_withoutTransaction_NOT_fail() throws Exception {
try {
ut.begin();
bean.withoutTransaction();
ut.commit();
} catch (ContextNotActiveException e) {
fail(e.toString());
}
}
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(MyTransactionalBean.class, MyTransactionScopedBean.class)
.addAsManifestResource("beans.xml");
}
@Test
public void should_withTransaction_have_only_one_instance_injected() {
bean.withTransaction();
assertThat("bean1 and bean2 should the same object", bean.id1, is(bean.id2));
}
@Test
public void should_withTransaction_called_twice_have_different_instances_injected() {
bean.withTransaction();
String firstId1 = bean.id1;
bean.withTransaction();
String secondId1 = bean.id1;
assertThat("bean1 should change between scenarios", firstId1, is(not(secondId1)));
}
@Test
public void should_withoutTransaction_fail() {
try {
bean.withoutTransaction();
fail("No ContextNotActiveException");
} catch (ContextNotActiveException e) {
}
}
There's a lot more about JavaEE to cover. If you're ready to learn more, check out the other available samples.
git clone git://github.com/javaee-samples/javaee7-samples.git
cd javaee7-samples/jta/transactional/
Do the changes as you see fit and send a pull request!
Good Luck!