final ClassLoader loader = javaClass.getClassLoader();
AppModule appModule = new AppModule(loader, javaClass.getSimpleName());
// Add the test case as an @ManagedBean
{
final EjbJar ejbJar = new EjbJar();
final OpenejbJar openejbJar = new OpenejbJar();
final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(javaClass.getSimpleName(), javaClass.getName(), true));
bean.setTransactionType(TransactionType.BEAN);
final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
ejbDeployment.setDeploymentId(javaClass.getName());
appModule.getEjbModules().add(new EjbModule(ejbJar, openejbJar));
}
Application application = null;
// Invoke the @Module producer methods to build out the AppModule
for (FrameworkMethod method : testClass.getAnnotatedMethods(Module.class)) {
final Object obj = method.invokeExplosively(testInstance);
if (obj instanceof WebModule) {
appModule.getWebModules().add((WebModule) obj);
} else if (obj instanceof EjbModule) {
appModule.getEjbModules().add((EjbModule) obj);
} else if (obj instanceof EjbJar) {
final EjbJar ejbJar = (EjbJar) obj;
setId(ejbJar, method);
appModule.getEjbModules().add(new EjbModule(ejbJar));
} else if (obj instanceof EnterpriseBean) {
final EnterpriseBean bean = (EnterpriseBean) obj;
final EjbJar ejbJar = new EjbJar(method.getName());
ejbJar.addEnterpriseBean(bean);
EjbModule ejbModule = new EjbModule(ejbJar);
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(bean.getEjbClass());
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(clazz)).link());
appModule.getEjbModules().add(ejbModule);
} else if (obj instanceof Application) {
application = (Application) obj;
setId(application, method);
} else if (obj instanceof Connector) {
final Connector connector = (Connector) obj;
setId(connector, method);
appModule.getConnectorModules().add(new ConnectorModule(connector));
} else if (obj instanceof Persistence) {
final Persistence persistence = (Persistence) obj;
appModule.getPersistenceModules().add(new PersistenceModule("", persistence));
} else if (obj instanceof PersistenceUnit) {
final PersistenceUnit unit = (PersistenceUnit) obj;
appModule.getPersistenceModules().add(new PersistenceModule("", new Persistence(unit)));
} else if (obj instanceof Beans) {
final Beans beans = (Beans) obj;
final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
ejbModule.setBeans(beans);
appModule.getEjbModules().add(ejbModule);
} else if (obj instanceof Class[]) {
final Class[] beans = (Class[]) obj;
final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(beans)).link());
ejbModule.setBeans(new Beans());
appModule.getEjbModules().add(ejbModule);
} else if (obj instanceof Class) {
final Class bean = (Class) obj;
final EjbModule ejbModule = new EjbModule(new EjbJar(method.getName()));
ejbModule.setFinder(new AnnotationFinder(new ClassesArchive(bean)).link());
ejbModule.setBeans(new Beans());
appModule.getEjbModules().add(ejbModule);
}
}