Result result = controller.execute();
Assert.assertThat(result, is(not(instanceOf(Failed.class))));
JavaSourceFacet facet = project.getFacet(JavaSourceFacet.class);
JavaResource javaResource = facet.getJavaResource("org.jboss.forge.test.TestEJB");
Assert.assertNotNull(javaResource);
Assert.assertThat(javaResource.getJavaType(), is(instanceOf(JavaClass.class)));
Assert.assertTrue(javaResource.getJavaType().hasAnnotation(MessageDriven.class));
Assert.assertTrue(((JavaClass<?>) javaResource.getJavaType()).hasField("serialVersionUID"));
Assert.assertNotNull(((JavaClass<?>) javaResource.getJavaType()).getMethod("onMessage", Message.class));
CommandController controller2 = testHarness.createCommandController(EJBSetClassTransactionAttributeCommand.class,
project.getRoot());
controller2.initialize();
Assert.assertFalse(controller2.canExecute());
controller2.setValueFor("targetEjb", "org.jboss.forge.test.TestEJB");
controller2.setValueFor("type", TransactionAttributeType.NOT_SUPPORTED);
Assert.assertTrue(controller2.canExecute());
Assert.assertFalse(((JavaClass<?>) javaResource.getJavaType()).hasAnnotation(TransactionAttribute.class));
controller2.execute();
Assert.assertTrue(((JavaClass<?>) javaResource.getJavaType()).hasAnnotation(TransactionAttribute.class));
Assert.assertEquals(TransactionAttributeType.NOT_SUPPORTED,
((JavaClass<?>) javaResource.getJavaType()).getAnnotation(TransactionAttribute.class).getEnumValue(
TransactionAttributeType.class));
CommandController controller3 = testHarness.createCommandController(
EJBSetMethodTransactionAttributeCommand.class,
project.getRoot());
controller3.initialize();
Assert.assertFalse(controller3.canExecute());
controller3.setValueFor("targetEjb", "org.jboss.forge.test.TestEJB");
controller3.setValueFor("method", "onMessage(javax.jms.Message)::void");
controller3.setValueFor("type", TransactionAttributeType.NEVER);
Assert.assertTrue(controller3.canExecute());
Assert.assertFalse(((JavaClass<?>) javaResource.getJavaType()).getMethod("onMessage", Message.class)
.hasAnnotation(TransactionAttribute.class));
controller3.execute();
project = projectHelper.refreshProject(project);
Assert.assertTrue(project.hasFacet(EJBFacet.class));
Assert.assertTrue(project.hasFacet(JMSFacet.class));
Assert.assertTrue(((JavaClass<?>) javaResource.getJavaType()).getMethod("onMessage", Message.class)
.hasAnnotation(
TransactionAttribute.class));
Assert.assertEquals(TransactionAttributeType.NEVER,
((JavaClass<?>) javaResource.getJavaType()).getMethod("onMessage", Message.class)
.getAnnotation(TransactionAttribute.class).getEnumValue(TransactionAttributeType.class));
}