use of org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment in project core by weld.
the class TransitiveResolutionTest method testTypicalEarStructure.
/*
* description = "WELD-236"
*/
@Test
public void testTypicalEarStructure() {
// Create the BDA in which we will deploy Foo. This is equivalent to a ejb
// jar
final BeanDeploymentArchiveImpl ejbJar = new BeanDeploymentArchiveImpl("ejb-jar", Foo.class);
// Create the BDA in which we will deploy Bar. This is equivalent to a war
final BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war", Bar.class);
// The war can access the ejb jar
war.getBeanDeploymentArchives().add(ejbJar);
// Create a deployment, any other classes are put into the ejb-jar (not
// relevant to test)
Deployment deployment = new FlatDeployment(new BeanDeploymentArchive[] { war, ejbJar }) {
public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
return ejbJar;
}
};
TestContainer container = new TestContainer(deployment);
container.startContainer();
container.ensureRequestActive();
// Get the bean manager for war and ejb jar
BeanManager warBeanManager = container.getBeanManager(war);
BeanManager ejbJarBeanManager = container.getBeanManager(ejbJar);
Assert.assertEquals(1, warBeanManager.getBeans(Bar.class).size());
Assert.assertEquals(1, warBeanManager.getBeans(Foo.class).size());
Assert.assertEquals(1, ejbJarBeanManager.getBeans(Foo.class).size());
Assert.assertEquals(0, ejbJarBeanManager.getBeans(Bar.class).size());
Bar bar = Utils.getReference(warBeanManager, Bar.class);
Assert.assertNotNull(bar.getFoo());
Assert.assertNotNull(bar.getBeanManager());
Assert.assertEquals(warBeanManager, bar.getBeanManager());
Assert.assertEquals(ejbJarBeanManager, bar.getFoo().getBeanManager());
container.stopContainer();
}
use of org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment in project core by weld.
the class TransitiveResolutionTest method testInterceptorEnabledInWarButPackagedInEjbJar.
/*
* WELD-507
*/
@Test
public void testInterceptorEnabledInWarButPackagedInEjbJar() {
// Create the BDA in which we will deploy Foo. This is equivalent to a ejb
// jar
final BeanDeploymentArchiveImpl ejbJar = new BeanDeploymentArchiveImpl("ejb-jar", Basic.class, BasicInterceptor.class, Simple.class);
// Create the BDA in which we will deploy Bar. This is equivalent to a war
BeansXml beansXml = new BeansXmlImpl(null, null, null, Collections.singletonList(BasicInterceptor.class.getName()));
final BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war", beansXml, Complex.class);
// The war can access the ejb jar
war.getBeanDeploymentArchives().add(ejbJar);
// Create a deployment, any other classes are put into the ejb-jar (not
// relevant to test)
Deployment deployment = new FlatDeployment(new BeanDeploymentArchive[] { ejbJar, war }) {
public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
return ejbJar;
}
};
TestContainer container = new TestContainer(deployment);
container.startContainer();
container.ensureRequestActive();
// Get the bean manager for war and ejb jar
BeanManager warBeanManager = container.getBeanManager(war);
BeanManager ejbJarBeanManager = container.getBeanManager(ejbJar);
BasicInterceptor.reset();
Simple simple = getReference(ejbJarBeanManager, Simple.class);
simple.ping("14");
Assert.assertNull(BasicInterceptor.getTarget());
BasicInterceptor.reset();
Complex complex = getReference(warBeanManager, Complex.class);
complex.ping("14");
Assert.assertNotNull(BasicInterceptor.getTarget());
Assert.assertTrue(BasicInterceptor.getTarget() instanceof Complex);
assertEquals("14", ((Complex) BasicInterceptor.getTarget()).getId());
container.stopContainer();
}
Aggregations