Search in sources :

Example 1 with TestContainer

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

the class SubclassedComponentDescriptorTest method prepareContainer.

@BeforeClass
public void prepareContainer() {
    final EjbDescriptor<Foo> fooDescriptor = new EjbDescriptorImpl<Foo>(Foo.class, Foo.class, EnhancedFoo.class, SessionBeanType.STATEFUL);
    final EjbDescriptor<Bar> barDescriptor = new EjbDescriptorImpl<Bar>(Bar.class, BarLocal.class, EnhancedBar.class, SessionBeanType.STATEFUL);
    final EjbDescriptor<Baz> bazDescriptor = new EjbDescriptorImpl<Baz>(Baz.class, Baz.class, EnhancedBaz.class, null);
    final BeanDeploymentArchive bda = new BeanDeploymentArchiveImpl("1", Foo.class, Bar.class, BarLocal.class, BarDecorator.class, BarInterceptor.class, BarInterceptorBinding.class, Baz.class) {

        @Override
        public Collection<EjbDescriptor<?>> getEjbs() {
            return ImmutableSet.<EjbDescriptor<?>>of(fooDescriptor, barDescriptor, bazDescriptor);
        }
    };
    final Deployment deployment = new FlatDeployment(bda) {

        @Override
        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            return bda;
        }

        @Override
        protected void configureServices(Environment environment) {
            super.configureServices(environment);
            getServices().add(EjbServices.class, new MockEjbServices());
        }
    };
    container = new TestContainer(deployment).startContainer();
    manager = (BeanManagerImpl) container.getBeanManager(bda);
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) Deployment(org.jboss.weld.bootstrap.spi.Deployment) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) EjbDescriptor(org.jboss.weld.ejb.spi.EjbDescriptor) MockEjbServices(org.jboss.weld.mock.MockEjbServices) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) Environment(org.jboss.weld.bootstrap.api.Environment) AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with TestContainer

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

the class NaiveClusterTest method testMultipleDependentObjectsSessionReplication.

@Test
public void testMultipleDependentObjectsSessionReplication() throws Exception {
    Collection<Class<?>> classes = Arrays.<Class<?>>asList(Stable.class, Horse.class, Fodder.class);
    TestContainer container1 = bootstrapContainer(1, classes);
    BeanManagerImpl beanManager1 = getBeanManager(container1);
    Bean<?> stableBean1 = beanManager1.resolve(beanManager1.getBeans(Stable.class));
    TestContainer container2 = bootstrapContainer(2, classes);
    BeanManagerImpl beanManager2 = getBeanManager(container2);
    Bean<?> stableBean2 = beanManager2.resolve(beanManager2.getBeans(Stable.class));
    use(1);
    // Set a value into Foo1
    Stable stable1 = (Stable) beanManager1.getReference(stableBean1, Stable.class, beanManager1.createCreationalContext(stableBean1));
    stable1.getFodder().setAmount(10);
    stable1.getHorse().setName("George");
    replicateSession(1, container1, 2, container2);
    use(2);
    Stable stable2 = (Stable) beanManager2.getReference(stableBean2, Stable.class, beanManager2.createCreationalContext(stableBean2));
    assert stable2.getFodder().getAmount() == stable1.getFodder().getAmount();
    assert stable2.getHorse().getName() == null;
    use(1);
    assert stable1.getFodder().getAmount() == 10;
    assert stable1.getHorse().getName().equals("George");
    use(2);
    stable2.getFodder().setAmount(11);
    replicateSession(2, container2, 1, container1);
    use(1);
    stable1.getFodder().getAmount();
    assert stable1.getFodder().getAmount() == 11;
    use(1);
    container1.stopContainer();
    use(2);
    container2.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Test(org.testng.annotations.Test) AbstractClusterTest(org.jboss.weld.mock.cluster.AbstractClusterTest)

Example 3 with TestContainer

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

the class NaiveClusterTest method testVariableBeanDeploymentStructure.

@Test(expectedExceptions = IllegalStateException.class)
public void testVariableBeanDeploymentStructure() throws Exception {
    Collection<Class<?>> classes1 = Arrays.<Class<?>>asList(Stable.class, Horse.class, Fodder.class);
    Collection<Class<?>> classes2 = Arrays.<Class<?>>asList(Stable.class, Horse.class, Fodder.class, Foo.class);
    TestContainer container1 = bootstrapContainer(1, classes1);
    BeanManagerImpl beanManager1 = getBeanManager(container1);
    Bean<?> stableBean1 = beanManager1.resolve(beanManager1.getBeans(Stable.class));
    TestContainer container2 = bootstrapContainer(2, classes2);
    use(1);
    // Set a value into Foo1
    Stable stable1 = (Stable) beanManager1.getReference(stableBean1, Stable.class, beanManager1.createCreationalContext(stableBean1));
    stable1.getFodder().setAmount(10);
    stable1.getHorse().setName("George");
    try {
        replicateSession(1, container1, 2, container2);
    } finally {
        use(1);
        container1.stopContainer();
        use(2);
        container2.stopContainer();
    }
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Test(org.testng.annotations.Test) AbstractClusterTest(org.jboss.weld.mock.cluster.AbstractClusterTest)

Example 4 with TestContainer

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

the class SwitchableContainerTest method test.

@Test
public void test() {
    // Bootstrap container 1
    SwitchableSingletonProvider.use(1);
    TestContainer container1 = new TestContainer(Foo.class);
    container1.startContainer();
    container1.ensureRequestActive();
    BeanManagerImpl beanManager1 = getBeanManager(container1);
    Bean<?> fooBean1 = beanManager1.resolve(beanManager1.getBeans(Foo.class));
    Foo foo1 = (Foo) beanManager1.getReference(fooBean1, Foo.class, beanManager1.createCreationalContext(fooBean1));
    foo1.setName("container 1");
    // Bootstrap container 2
    SwitchableSingletonProvider.use(2);
    TestContainer container2 = new TestContainer(Foo.class);
    container2.startContainer();
    container2.ensureRequestActive();
    BeanManagerImpl beanManager2 = getBeanManager(container2);
    Bean<?> fooBean2 = beanManager2.resolve(beanManager2.getBeans(Foo.class));
    Foo foo2 = (Foo) beanManager2.getReference(fooBean2, Foo.class, beanManager2.createCreationalContext(fooBean2));
    foo2.setName("container 2");
    // Switch to container 1 and check value
    SwitchableSingletonProvider.use(1);
    foo1 = (Foo) beanManager1.getReference(fooBean1, Foo.class, beanManager1.createCreationalContext(fooBean1));
    assert foo1.getName().equals("container 1");
    // Switch to container 2 and check value
    SwitchableSingletonProvider.use(2);
    foo2 = (Foo) beanManager2.getReference(fooBean2, Foo.class, beanManager2.createCreationalContext(fooBean2));
    assert foo2.getName().equals("container 2");
    SwitchableSingletonProvider.use(1);
    container1.stopContainer();
    SwitchableSingletonProvider.use(2);
    container2.stopContainer();
    SingletonProvider.reset();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) AbstractClusterTest(org.jboss.weld.mock.cluster.AbstractClusterTest) Test(org.testng.annotations.Test)

Example 5 with TestContainer

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

the class ThreadLocalTestCase method ensureNoThreadLocalLeakOnInjectionPoints.

@Test
public void ensureNoThreadLocalLeakOnInjectionPoints() throws Exception {
    TestContainer container = new TestContainer(Bar.class, Baz.class);
    container.startContainer();
    BeanManager manager = getBeanManager(container);
    Bean<?> testBean = manager.resolve(manager.getBeans(Baz.class));
    Baz baz = cast(manager.getReference(testBean, Baz.class, manager.createCreationalContext(testBean)));
    baz.getBar().ping();
    container.stopContainer();
    verifyThreadLocals();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) 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