I have Java Enterprise application consisting of more than ten projects compiled into one ear archive. I need to do some integration testing and I have to use the Arquillian platform with ShrinkWrap. In the @Deployment annotated method I have to explicitly include each class in the dependency tree of the class I need to test.
My question: is there a tool that can build the class tree for classes referenced via EJB annotation (CDI) starting from a single EJB?
For example: I have such tree (omitting some classes)
@Singleton
public class A{
@EJB
B b;
public void doSomethingOnB(){
b.doSomething();
}
}
@Singleton
public class B{
@EJB
C c;
@EJB
D d;
@EJB
E e;
public void doSomething(){
d.toString();
e.toString();
c.fin();
}
}
@Singleton
public class C{
@EJB
E e;
@EJB
F f;
public void fin(){
System.out.println(f.toString()+e.toString);
}
}
My @Deployment annotated method would look like this:
@RunWith(Arquillian.class) public class ClassAlphaTest {
@Deployment(testable=true)
public static JavaArchive createDeployment() {
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addClass(A.class)
.addClass(B.class)
.addClass(C.class)
.addClass(D.class)
.addClass(E.class)
.addClass(F.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
System.out.println(jar.toString(true));
return jar;
}
And my test:
@Test
public void testLoadCategories(A alpha) {
System.out.println("DoingTest");
alpha.doSomethingOnB();
}
I would like my createDeployment to look more like this:
@Deployment(testable=true)
public static JavaArchive createDeployment() {
List<Class> classes = buildClassTree(A.class);
JavaArchive jar = ShrinkWrap.create(JavaArchive.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
foreach(Class c : classes){
jar.addClass(c);
}
System.out.println(jar.toString(true));
return jar;
}
Where buildClassTree is the method I am looking for.