Search in sources :

Example 16 with TestContainer

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

the class NaiveClusterTest method testVariableBeanDeploymentStructureNotVerified.

@Test
public void testVariableBeanDeploymentStructureNotVerified() 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);
    System.setProperty(ConfigurationKey.BEAN_IDENTIFIER_INDEX_OPTIMIZATION.get(), "false");
    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 17 with TestContainer

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

the class NaiveClusterTest method testConversationReplication.

@Test(description = "A simple test to check conversation replication")
public void testConversationReplication() throws Exception {
    TestContainer container1 = bootstrapContainer(1, Collections.singletonList(Baz.class));
    BeanManagerImpl beanManager1 = getBeanManager(container1);
    TestContainer container2 = bootstrapContainer(2, Collections.singletonList(Baz.class));
    BeanManagerImpl beanManager2 = getBeanManager(container2);
    use(1);
    // Set up the conversation context
    BoundRequest request1 = new BoundRequestImpl(container1.getSessionStore());
    BoundConversationContext conversationContext1 = Utils.getReference(beanManager1, BoundConversationContext.class);
    conversationContext1.associate(request1);
    conversationContext1.activate();
    // Set a value into Baz1
    Baz baz1 = Utils.getReference(beanManager1, Baz.class);
    baz1.setName("pete");
    // Begin the conversation
    Conversation conversation1 = Utils.getReference(beanManager1, Conversation.class);
    conversation1.begin();
    // refetch the test bean and check it has the right value
    baz1 = Utils.getReference(beanManager1, Baz.class);
    assert baz1.getName().equals("pete");
    // Simulate ending the request (from the POV of the conversation only!)
    assert !conversation1.isTransient();
    String cid = conversation1.getId();
    conversationContext1.invalidate();
    conversationContext1.deactivate();
    conversationContext1.dissociate(request1);
    // and start another, propagating the conversation
    request1 = new BoundRequestImpl(container1.getSessionStore());
    conversationContext1.associate(request1);
    conversationContext1.activate(cid);
    // refetch the test bean and check it has the right value
    baz1 = Utils.getReference(beanManager1, Baz.class);
    assert baz1.getName().equals("pete");
    assert !conversation1.isTransient();
    replicateSession(1, container1, 2, container2);
    use(2);
    // Set up the conversation context
    BoundRequest request2 = new BoundRequestImpl(container2.getSessionStore());
    BoundConversationContext conversationContext2 = Utils.getReference(beanManager2, BoundConversationContext.class);
    conversationContext2.associate(request2);
    conversationContext2.activate(cid);
    Baz baz2 = Utils.getReference(beanManager2, Baz.class);
    assert baz2.getName().equals("pete");
    Conversation conversation2 = Utils.getReference(beanManager2, Conversation.class);
    assert !conversation2.isTransient();
    use(2);
    container2.stopContainer();
    use(1);
    container1.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) BoundConversationContext(org.jboss.weld.context.bound.BoundConversationContext) BoundRequest(org.jboss.weld.context.bound.BoundRequest) Conversation(javax.enterprise.context.Conversation) Test(org.testng.annotations.Test) AbstractClusterTest(org.jboss.weld.mock.cluster.AbstractClusterTest)

Example 18 with TestContainer

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

the class ContainerStatusTest method testStatus.

@Test
public void testStatus() {
    TestContainer container = new TestContainer();
    Assert.assertFalse(Container.available());
    container.getBootstrap().startContainer(Environments.SE, container.getDeployment());
    Assert.assertFalse(Container.available());
    Assert.assertEquals(ContainerState.STARTING, Container.instance().getState());
    container.getBootstrap().startInitialization();
    Assert.assertFalse(Container.available());
    Assert.assertEquals(ContainerState.STARTING, Container.instance().getState());
    container.getBootstrap().deployBeans();
    Assert.assertTrue(Container.available());
    Assert.assertEquals(ContainerState.DEPLOYED, Container.instance().getState());
    container.getBootstrap().validateBeans();
    Assert.assertEquals(ContainerState.VALIDATED, Container.instance().getState());
    Assert.assertTrue(Container.available());
    container.getBootstrap().endInitialization();
    Assert.assertTrue(Container.available());
    Assert.assertEquals(ContainerState.INITIALIZED, Container.instance().getState());
    container.stopContainer();
    Assert.assertFalse(Container.available());
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) Test(org.testng.annotations.Test)

Example 19 with TestContainer

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

the class ThreadLocalTestCase method ensureNoThreadLocalLeakOnContexts.

@Test
public void ensureNoThreadLocalLeakOnContexts() throws Exception {
    TestContainer container = new TestContainer(Foo.class, ThreadLocalTestCase.class);
    container.startContainer();
    BeanManager manager = getBeanManager(container);
    Bean<?> testBean = manager.resolve(manager.getBeans(ThreadLocalTestCase.class));
    try {
        manager.getReference(testBean, ThreadLocalTestCase.class, manager.createCreationalContext(testBean));
    } catch (RuntimeException e) {
    // Ignore, expected
    }
    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)

Example 20 with TestContainer

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

the class NonBdaExtensionTest method test.

/*
    * description = "WELD-233"
    */
@Test
public void test() {
    // Create the BDA in which we will deploy Observer1 and Foo. This is equivalent to a war or ejb jar
    final BeanDeploymentArchiveImpl bda1 = new BeanDeploymentArchiveImpl("1", Observer1.class, Foo.class);
    // Create the BDA to return from loadBeanDeploymentArchive for Observer2, this is probably a library, though could be another war or ejb jar
    // bda2 is accessible from bda1, but isn't added to it's accessibility graph by default. This similar to an archive which doesn't contain a beans.xml but does contain an extension
    final BeanDeploymentArchive bda2 = new BeanDeploymentArchiveImpl("2", Observer2.class);
    // Create a deployment, that we can use to mirror the structure of one Extension inside a BDA, and one outside
    Deployment deployment = new FlatDeployment(bda1, new Observer1(), new Observer2(), new CountingObserver1(), new CountingObserver2()) {

        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            // Return bda2 if it is Observer2. Stick anything else which this test isn't about in bda1
            if (beanClass.equals(Observer2.class)) {
                // If Observer2 is requested, then we need to add bda2 to the accessibility graph of bda1
                bda1.getBeanDeploymentArchives().add(bda2);
                return bda2;
            } else {
                return bda1;
            }
        }
    };
    TestContainer container = new TestContainer(deployment);
    // Cause the container to deploy the beans etc.
    container.startContainer();
    // Get the bean manager for bda1 and bda2
    BeanManager beanManager1 = container.getBeanManager(bda1);
    BeanManager beanManager2 = container.getBeanManager(bda2);
    Observer1 observer1 = Utils.getReference(beanManager1, Observer1.class);
    Assert.assertTrue(observer1.isBeforeBeanDiscoveryCalled());
    Assert.assertEquals(beanManager1, observer1.getBeforeBeanDiscoveryBeanManager());
    Assert.assertTrue(observer1.isAfterBeanDiscoveryCalled());
    Assert.assertTrue(observer1.isAfterDeploymentValidationCalled());
    Assert.assertTrue(observer1.isProcessInjectionTargetCalled());
    Assert.assertTrue(observer1.isProcessManagedBeanCalled());
    Assert.assertTrue(observer1.isProcessProducerCalled());
    Assert.assertEquals(1, beanManager2.getBeans(Observer2.class).size());
    // Also check that the accessibility graph has been updated
    Assert.assertEquals(1, beanManager1.getBeans(Observer2.class).size());
    Observer2 observer2 = Utils.getReference(beanManager2, Observer2.class);
    Assert.assertTrue(observer2.isBeforeBeanDiscoveryCalled());
    Assert.assertEquals(beanManager2, observer2.getBeforeBeanDiscoveryBeanManager());
    Assert.assertTrue(observer2.isAfterBeanDiscoveryCalled());
    Assert.assertTrue(observer2.isAfterDeploymentValidationCalled());
    Assert.assertTrue(observer2.isProcessInjectionTargetCalled());
    Assert.assertTrue(observer2.isProcessManagedBeanCalled());
    Assert.assertTrue(observer2.isProcessProducerCalled());
    container.stopContainer();
}
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) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Deployment(org.jboss.weld.bootstrap.spi.Deployment) 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