public void testMultipleArchives() throws Exception
{
WebArchive war1 = createWar("web1.war", true, ServletWebBean.class);
DeploymentUnit war1Unit = assertDeploy(war1);
Deployment war1Deployment = initializeDeploymentBean(war1Unit);
BeanDeploymentArchive war1BDA = war1Deployment.getBeanDeploymentArchives().iterator().next();
assertBDAId(war1BDA, "web1.war");
assertExpectedClasses(war1BDA, ServletWebBean.class);
Class<?> servletWebBeanWar1Class = getClass(ServletWebBean.class, war1Unit);
WebArchive war2 = createWar("web2.war", true, NotWBJsfBean.class);
createLib(war2, "crm.jar", false, CrmWebBean.class);
DeploymentUnit war2Unit = assertDeploy(war2);
Deployment war2Deployment = initializeDeploymentBean(war2Unit);
BeanDeploymentArchive war2BDA = war2Deployment.getBeanDeploymentArchives().iterator().next();
assertBDAId(war2BDA, "web2.war");
assertExpectedClasses(war2BDA, NotWBJsfBean.class);
Class<?> notWBJsfBeanWar2Class = getClass(NotWBJsfBean.class, war2Unit);
Class<?> crmWebBeanWar2Class = getClass(CrmWebBean.class, war2Unit);
JavaArchive ejbJar = createEjbJar("ejb.jar", true, BusinessInterface.class);
DeploymentUnit ejbJarUnit = assertDeploy(ejbJar);
Deployment ejbJarDeployment = initializeDeploymentBean(ejbJarUnit);
BeanDeploymentArchive ejbJarBDA = ejbJarDeployment.getBeanDeploymentArchives().iterator().next();
assertBDAId(ejbJarBDA, "ejb.jar");
assertExpectedClasses(ejbJarBDA, BusinessInterface.class);
Class<?> businessInterfaceClass = getClass(BusinessInterface.class, ejbJarUnit);
EnterpriseArchive ear1 = ShrinkWrap.create(EnterpriseArchive.class, "full.ear");
WebArchive warInEar1 = createWarWithLibs(false, true, true);
ear1.addModule(warInEar1);
ear1.addModule(war2);
JavaArchive ejbJarInEar1 = createEjbJar("ejbInFullEar.jar", false, MySLSBean.class);
ear1.addModule(ejbJarInEar1);
createLib(ear1, "lib1.jar", false, ExternalWebBean.class);
createLib(ear1, "lib2.jar", true, A.class);
createLib(ear1, "lib3.jar", false, B.class);
MockArchiveManifest.addManifest(ear1);
DeploymentUnit ear1Unit = assertDeploy(ear1);
Deployment ear1Deployment = initializeDeploymentBean(ear1Unit);
BeanDeploymentArchive ear1BDA = null, ear1War1BDA = null, ear1War2BDA = null;
for (BeanDeploymentArchive bda: ear1Deployment.getBeanDeploymentArchives())
{
if (bda.getId().contains(WAR_NAME))
{
ear1War1BDA = bda;
}
else if (bda.getId().contains("web2.war"))
{
ear1War2BDA = bda;
}
else
{
ear1BDA = bda;
}
}
assertBDAId(ear1BDA, "full.ear");
assertExpectedClasses(ear1BDA, A.class);
assertBDAId(ear1War1BDA, "full.ear/" + WAR_NAME);
assertExpectedClasses(ear1War1BDA, UIWebBean.class, CrmWebBean.class);
assertBDAId(ear1War2BDA, "full.ear/web2.war");
assertExpectedClasses(ear1War2BDA, NotWBJsfBean.class);
Class<?> servletWebBeanEar1Class = null, uiWebBeanEar1Class = null,
crmWebBeanEar1War1Class = null, notWBJsfBeanEar1Class = null,
crmWebBeanEar1War2Class = null;
for (DeploymentUnit ear1Child: ear1Unit.getChildren())
{
if (ear1Child.getName().contains(WAR_NAME))
{
servletWebBeanEar1Class = getClass(ServletWebBean.class, ear1Child);
uiWebBeanEar1Class = getClass(UIWebBean.class, ear1Child);
crmWebBeanEar1War1Class = getClass(CrmWebBean.class, ear1Child);
}
else if (ear1Child.getName().contains("web2.war"))
{
notWBJsfBeanEar1Class = getClass(NotWBJsfBean.class, ear1Child);
crmWebBeanEar1War2Class = getClass(CrmWebBean.class, ear1Child);
}
}
Class<?> externalWebBeanClass = getClass(ExternalWebBean.class, ear1Unit);
Class<?> aClass = getClass(A.class, ear1Unit);
Class<?> bClass = getClass(B.class, ear1Unit);
EnterpriseArchive ear2 = ShrinkWrap.create(EnterpriseArchive.class, "ejbWLibs.ear");
JavaArchive ejbJarInEar2 = createEjbJar("ejbInEar2.jar", true, PlainJavaBean.class);
ear2.addModule(ejbJarInEar2);
createLib(ear2, "lib1.jar", false, SomeUtil.class);
createLib(ear2, "lib2.jar", true, CrmWebBean.class);
MockArchiveManifest.addManifest(ear2);
DeploymentUnit ear2Unit = assertDeploy(ear2);
Deployment ear2Deployment = initializeDeploymentBean(ear2Unit);
BeanDeploymentArchive ear2BDA = ear2Deployment.getBeanDeploymentArchives().iterator().next();
assertBDAId(ear2BDA, "ejbWLibs.ear");
assertExpectedClasses(ear2BDA, PlainJavaBean.class, CrmWebBean.class);
Class<?> plainJavaBeanClass = getClass(PlainJavaBean.class, ear2Unit);
Class<?> someUtilClass = getClass(SomeUtil.class, ear2Unit);
Class<?> crmWebBeanClass = getClass(CrmWebBean.class, ear2Unit);
// Assert on web classes
// assertion deleted as loadBDA implementation does not check for unreachable classes anymore
/*assertCannotLoadBDA(war1Deployment, servletWebBeanEar1Class);
assertCannotLoadBDA(war1Deployment, notWBJsfBeanWar2Class);
assertCannotLoadBDA(war1Deployment, notWBJsfBeanEar1Class);
assertCannotLoadBDA(war1Deployment, crmWebBeanWar2Class);
assertCannotLoadBDA(war1Deployment, crmWebBeanEar1War1Class);
assertCannotLoadBDA(war1Deployment, crmWebBeanEar1War2Class);
assertCannotLoadBDA(war1Deployment, uiWebBeanEar1Class);*/
BeanDeploymentArchive bda = war1Deployment.loadBeanDeploymentArchive(servletWebBeanWar1Class);
assertSame(war1BDA, bda);
// verify the absence of collateral effects on the BDA
assertBDAId(war1BDA, "web1.war");
assertExpectedClasses(war1BDA, ServletWebBean.class);
// assertion deleted as loadBDA implementation does not check for unreachable classes anymore
/*assertCannotLoadBDA(war2Deployment, servletWebBeanWar1Class);
assertCannotLoadBDA(war2Deployment, servletWebBeanEar1Class);
assertCannotLoadBDA(war2Deployment, notWBJsfBeanEar1Class);
assertCannotLoadBDA(war2Deployment, crmWebBeanEar1War1Class);
assertCannotLoadBDA(war2Deployment, crmWebBeanEar1War2Class);
assertCannotLoadBDA(war2Deployment, uiWebBeanEar1Class);*/
bda = war2Deployment.loadBeanDeploymentArchive(notWBJsfBeanWar2Class);
bda = war2Deployment.loadBeanDeploymentArchive(crmWebBeanWar2Class);
assertSame(war2BDA, bda);
assertBDAId(war2BDA, "web2.war");
assertExpectedClasses(war2BDA, NotWBJsfBean.class, CrmWebBean.class);
// assertion deleted as loadBDA implementation does not check for unreachable classes anymore
/*assertCannotLoadBDA(ejbJarDeployment, servletWebBeanWar1Class);
assertCannotLoadBDA(ejbJarDeployment, servletWebBeanEar1Class);
assertCannotLoadBDA(ejbJarDeployment, notWBJsfBeanWar2Class);
assertCannotLoadBDA(ejbJarDeployment, notWBJsfBeanEar1Class);
assertCannotLoadBDA(ejbJarDeployment, crmWebBeanWar2Class);
assertCannotLoadBDA(ejbJarDeployment, crmWebBeanEar1War1Class);
assertCannotLoadBDA(ejbJarDeployment, crmWebBeanEar1War2Class);
assertCannotLoadBDA(ejbJarDeployment, uiWebBeanEar1Class);
assertCannotLoadBDA(ear1Deployment, servletWebBeanWar1Class);
assertCannotLoadBDA(ear1Deployment, notWBJsfBeanWar2Class);
assertCannotLoadBDA(ear1Deployment, crmWebBeanWar2Class);*/
bda = ear1Deployment.loadBeanDeploymentArchive(servletWebBeanEar1Class);
assertSame(ear1War1BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(uiWebBeanEar1Class);
assertSame(ear1War1BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(crmWebBeanEar1War1Class);
assertSame(ear1War1BDA, bda);
assertBDAId(ear1War1BDA, "full.ear/" + WAR_NAME);
assertExpectedClasses(ear1War1BDA, ServletWebBean.class, UIWebBean.class, CrmWebBean.class);
bda = ear1Deployment.loadBeanDeploymentArchive(notWBJsfBeanEar1Class);
assertSame(ear1War2BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(crmWebBeanEar1War2Class);
assertSame(ear1War2BDA, bda);
assertBDAId(ear1War2BDA, "full.ear/web2.war");
assertExpectedClasses(ear1War2BDA, NotWBJsfBean.class, CrmWebBean.class);
// assertion deleted as loadBDA implementation does not check for unreachable classes anymore
/*assertCannotLoadBDA(ear2Deployment, servletWebBeanWar1Class);
assertCannotLoadBDA(ear2Deployment, servletWebBeanEar1Class);
assertCannotLoadBDA(ear2Deployment, notWBJsfBeanWar2Class);
assertCannotLoadBDA(ear2Deployment, notWBJsfBeanEar1Class);
assertCannotLoadBDA(ear2Deployment, crmWebBeanWar2Class);
assertCannotLoadBDA(ear2Deployment, crmWebBeanEar1War1Class);
assertCannotLoadBDA(ear2Deployment, crmWebBeanEar1War2Class);
assertCannotLoadBDA(ear2Deployment, uiWebBeanEar1Class);*/
// Assert on business classes that are part of existing BDAs
bda = ejbJarDeployment.loadBeanDeploymentArchive(businessInterfaceClass);
assertSame(ejbJarBDA, bda);
war1Deployment.loadBeanDeploymentArchive(businessInterfaceClass);
assertSame(ejbJarBDA, bda);
war2Deployment.loadBeanDeploymentArchive(businessInterfaceClass);
assertSame(ejbJarBDA, bda);
ear1Deployment.loadBeanDeploymentArchive(businessInterfaceClass);
assertSame(ejbJarBDA, bda);
war2Deployment.loadBeanDeploymentArchive(businessInterfaceClass);
assertSame(ejbJarBDA, bda);
assertBDAId(ejbJarBDA, "ejb.jar"); // no collateral effects on the BDA
assertExpectedClasses(ejbJarBDA, BusinessInterface.class);
bda = ear1Deployment.loadBeanDeploymentArchive(aClass);
assertSame(ear1BDA, bda);
bda = war1Deployment.loadBeanDeploymentArchive(aClass);
assertSame(ear1BDA, bda);
bda = war2Deployment.loadBeanDeploymentArchive(aClass);
assertSame(ear1BDA, bda);
bda = ejbJarDeployment.loadBeanDeploymentArchive(aClass);
assertSame(ear1BDA, bda);
bda = ear2Deployment.loadBeanDeploymentArchive(aClass);
assertSame(ear1BDA, bda);
assertBDAId(ear1BDA, "full.ear"); // no collateral effects on the BDA
assertExpectedClasses(ear1BDA, A.class);
bda = ear2Deployment.loadBeanDeploymentArchive(plainJavaBeanClass);
assertSame(ear2BDA, bda);
bda = ear2Deployment.loadBeanDeploymentArchive(crmWebBeanClass);
assertSame(ear2BDA, bda);
bda = war1Deployment.loadBeanDeploymentArchive(plainJavaBeanClass);
assertSame(ear2BDA, bda);
bda = war1Deployment.loadBeanDeploymentArchive(crmWebBeanClass);
assertSame(ear2BDA, bda);
bda = war2Deployment.loadBeanDeploymentArchive(plainJavaBeanClass);
assertSame(ear2BDA, bda);
bda = war2Deployment.loadBeanDeploymentArchive(crmWebBeanClass);
assertSame(ear2BDA, bda);
bda = ejbJarDeployment.loadBeanDeploymentArchive(plainJavaBeanClass);
assertSame(ear2BDA, bda);
bda = ejbJarDeployment.loadBeanDeploymentArchive(crmWebBeanClass);
assertSame(ear2BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(plainJavaBeanClass);
assertSame(ear2BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(crmWebBeanClass);
assertSame(ear2BDA, bda);
assertBDAId(ear2BDA, "ejbWLibs.ear"); // no collateral effects on the BDA
assertExpectedClasses(ear2BDA, PlainJavaBean.class, CrmWebBean.class);
// Assert on business classes that are not yet part of existing BDAs
bda = war1Deployment.loadBeanDeploymentArchive(externalWebBeanClass);
assertSame(ear1BDA, bda);
assertBDAId(ear1BDA, "full.ear");
assertExpectedClasses(ear1BDA, ExternalWebBean.class, A.class);
bda = war2Deployment.loadBeanDeploymentArchive(externalWebBeanClass);
assertSame(ear1BDA, bda);
bda = ejbJarDeployment.loadBeanDeploymentArchive(externalWebBeanClass);
assertSame(ear1BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(externalWebBeanClass);
assertSame(ear1BDA, bda);
bda = ear2Deployment.loadBeanDeploymentArchive(externalWebBeanClass);
assertSame(ear1BDA, bda);
assertBDAId(ear1BDA, "full.ear"); // no collateral effects on the BDA
assertExpectedClasses(ear1BDA, ExternalWebBean.class, A.class);
bda = ear1Deployment.loadBeanDeploymentArchive(bClass);
assertSame(ear1BDA, bda);
assertBDAId(ear1BDA, "full.ear");
assertExpectedClasses(ear1BDA, ExternalWebBean.class, A.class, B.class);
bda = war1Deployment.loadBeanDeploymentArchive(bClass);
assertSame(ear1BDA, bda);
bda = war2Deployment.loadBeanDeploymentArchive(bClass);
assertSame(ear1BDA, bda);
bda = ejbJarDeployment.loadBeanDeploymentArchive(bClass);
assertSame(ear1BDA, bda);
bda = ear2Deployment.loadBeanDeploymentArchive(bClass);
assertSame(ear1BDA, bda);
assertBDAId(ear1BDA, "full.ear"); // no collateral effects on the BDA
assertExpectedClasses(ear1BDA, ExternalWebBean.class, A.class, B.class);
bda = ejbJarDeployment.loadBeanDeploymentArchive(someUtilClass);
assertSame(ear2BDA, bda);
assertBDAId(ear2BDA, "ejbWLibs.ear");
assertExpectedClasses(ear2BDA, PlainJavaBean.class, SomeUtil.class, CrmWebBean.class);
bda = war1Deployment.loadBeanDeploymentArchive(someUtilClass);
assertSame(ear2BDA, bda);
bda = war2Deployment.loadBeanDeploymentArchive(someUtilClass);
assertSame(ear2BDA, bda);
bda = ear1Deployment.loadBeanDeploymentArchive(someUtilClass);
assertSame(ear2BDA, bda);
bda = ear2Deployment.loadBeanDeploymentArchive(someUtilClass);
assertSame(ear2BDA, bda);
assertBDAId(ear2BDA, "ejbWLibs.ear"); // no collateraleffects on the BDA
assertExpectedClasses(ear2BDA, PlainJavaBean.class, SomeUtil.class, CrmWebBean.class);
}