Search in sources :

Example 6 with TestContainer

use of org.jboss.arquillian.container.weld.embedded.mock.TestContainer in project core by weld.

the class AbstractClusterTest method bootstrapContainer.

protected TestContainer bootstrapContainer(int id, Collection<Class<?>> classes) {
    // Bootstrap container
    SwitchableSingletonProvider.use(id);
    TestContainer container = new TestContainer(new FlatDeployment(new BeanDeploymentArchiveImpl(classes)));
    container.getDeployment().getServices().add(ProxyServices.class, new SwitchableCLProxyServices());
    container.startContainer();
    container.ensureRequestActive();
    return container;
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)

Example 7 with TestContainer

use of org.jboss.arquillian.container.weld.embedded.mock.TestContainer in project core by weld.

the class InjectionServicesTest method testInjectionOfTarget.

@Test
public void testInjectionOfTarget() {
    TestContainer container = new TestContainer(Foo.class, Bar.class);
    CheckableInjectionServices ijs = new CheckableInjectionServices();
    for (BeanDeploymentArchive bda : container.getDeployment().getBeanDeploymentArchives()) {
        bda.getServices().add(InjectionServices.class, ijs);
    }
    container.startContainer();
    container.ensureRequestActive();
    BeanManager manager = getBeanManager(container);
    Bean<?> bean = manager.resolve(manager.getBeans(Foo.class));
    ijs.reset();
    Foo foo = (Foo) manager.getReference(bean, Foo.class, manager.createCreationalContext(bean));
    Assert.assertTrue(ijs.isBefore());
    Assert.assertTrue(ijs.isAfter());
    Assert.assertTrue(ijs.isInjectedAfter());
    Assert.assertTrue(ijs.isInjectionTargetCorrect());
    Assert.assertEquals(ijs.getAroundInjectForFooCalled(), 1);
    Assert.assertEquals(ijs.getAroundInjectForBarCalled(), 1);
    Assert.assertNotNull(foo.getBar());
    Assert.assertEquals("hi!", foo.getMessage());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.testng.annotations.Test)

Example 8 with TestContainer

use of org.jboss.arquillian.container.weld.embedded.mock.TestContainer in project core by weld.

the class TransitiveResolutionTest method testDecoratorEnabledInWarButPackagedInEjbJar.

/*
    * WELD-507
    */
@Test
public void testDecoratorEnabledInWarButPackagedInEjbJar() {
    // Create the BDA in which we will deploy Foo. This is equivalent to a ejb
    // jar
    final BeanDeploymentArchiveImpl ejbJar = new BeanDeploymentArchiveImpl("ejb-jar", Blah.class, BlahDecorator.class, BlahImpl.class);
    // Create the BDA in which we will deploy Bar. This is equivalent to a war
    BeansXml beansXml = new BeansXmlImpl(null, null, Collections.singletonList(BlahDecorator.class.getName()), null);
    final BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war", beansXml, BlahImpl2.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);
    BasicInterceptor.reset();
    Blah blah = getReference(ejbJarBeanManager, Blah.class);
    blah.ping(10);
    assertEquals(10, blah.getI());
    BasicInterceptor.reset();
    blah = getReference(warBeanManager, Blah.class, new AnnotationLiteral<Baz>() {
    });
    blah.ping(10);
    assertEquals(11, blah.getI());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) AnnotationLiteral(javax.enterprise.util.AnnotationLiteral) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.testng.annotations.Test)

Example 9 with TestContainer

use of org.jboss.arquillian.container.weld.embedded.mock.TestContainer in project core by weld.

the class TransitiveResolutionTest method testBeansXmlIsolation.

/*
    * description = "WELD-319"
    */
@Test
public void testBeansXmlIsolation() {
    BeanDeploymentArchiveImpl jar1 = new BeanDeploymentArchiveImpl("first-jar", new BeansXmlImpl(Collections.singletonList(Alt.class.getName()), null, null, null), Alt.class);
    BeanDeploymentArchiveImpl jar2 = new BeanDeploymentArchiveImpl("second-jar", Alt2.class);
    BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war");
    war.getBeanDeploymentArchives().add(jar1);
    war.getBeanDeploymentArchives().add(jar2);
    Deployment deployment = new FlatDeployment(war);
    TestContainer container = null;
    try {
        container = new TestContainer(deployment).startContainer().ensureRequestActive();
        BeanManagerImpl warBeanManager = (BeanManagerImpl) container.getBeanManager(war);
        BeanManagerImpl jar1BeanManager = (BeanManagerImpl) container.getBeanManager(jar1);
        BeanManagerImpl jar2BeanManager = (BeanManagerImpl) container.getBeanManager(jar2);
        Assert.assertTrue(warBeanManager.getEnabled().getAlternativeClasses().isEmpty());
        Assert.assertFalse(jar1BeanManager.getEnabled().getAlternativeClasses().isEmpty());
        Assert.assertTrue(jar2BeanManager.getEnabled().getAlternativeClasses().isEmpty());
    } finally {
        if (container != null) {
            container.stopContainer();
        }
    }
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Test(org.testng.annotations.Test)

Example 10 with TestContainer

use of org.jboss.arquillian.container.weld.embedded.mock.TestContainer in project core by weld.

the class TransitiveResolutionTest method testBeansXmlMultipleEnabling.

/*
    * description = "WELD-319"
    */
@Test
public void testBeansXmlMultipleEnabling() {
    BeanDeploymentArchiveImpl jar1 = new BeanDeploymentArchiveImpl("first-jar", new BeansXmlImpl(Collections.singletonList(Alt.class.getName()), null, null, null), Alt.class);
    BeanDeploymentArchiveImpl jar2 = new BeanDeploymentArchiveImpl("second-jar", new BeansXmlImpl(Collections.singletonList(Alt2.class.getName()), Collections.<String>emptyList(), null, null), Alt2.class);
    BeanDeploymentArchiveImpl war = new BeanDeploymentArchiveImpl("war");
    war.getBeanDeploymentArchives().add(jar1);
    war.getBeanDeploymentArchives().add(jar2);
    Deployment deployment = new FlatDeployment(war);
    TestContainer container = null;
    try {
        container = new TestContainer(deployment).startContainer().ensureRequestActive();
        BeanManagerImpl warBeanManager = (BeanManagerImpl) container.getBeanManager(war);
        BeanManagerImpl jar1BeanManager = (BeanManagerImpl) container.getBeanManager(jar1);
        BeanManagerImpl jar2BeanManager = (BeanManagerImpl) container.getBeanManager(jar2);
        Assert.assertTrue(warBeanManager.getEnabled().getAlternativeClasses().isEmpty());
        Assert.assertFalse(jar1BeanManager.getEnabled().getAlternativeClasses().isEmpty());
        Assert.assertFalse(jar2BeanManager.getEnabled().getAlternativeClasses().isEmpty());
    } finally {
        if (container != null) {
            container.stopContainer();
        }
    }
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Test(org.testng.annotations.Test)

Aggregations

TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)24 Test (org.testng.annotations.Test)21 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)11 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)11 Deployment (org.jboss.weld.bootstrap.spi.Deployment)10 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)10 BeanManager (javax.enterprise.inject.spi.BeanManager)9 AbstractClusterTest (org.jboss.weld.mock.cluster.AbstractClusterTest)8 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)6 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)2 Conversation (javax.enterprise.context.Conversation)1 AnnotationLiteral (javax.enterprise.util.AnnotationLiteral)1 Car (org.atinject.tck.auto.Car)1 Environment (org.jboss.weld.bootstrap.api.Environment)1 BoundConversationContext (org.jboss.weld.context.bound.BoundConversationContext)1 BoundRequest (org.jboss.weld.context.bound.BoundRequest)1 EjbDescriptor (org.jboss.weld.ejb.spi.EjbDescriptor)1 MockEjbServices (org.jboss.weld.mock.MockEjbServices)1 AfterClass (org.testng.annotations.AfterClass)1 BeforeClass (org.testng.annotations.BeforeClass)1