Search in sources :

Example 11 with TestContainer

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

the class DuplicateBeanArchiveIdTest method test.

@Test(expectedExceptions = { DeploymentException.class })
public void test() {
    // Override equals/hashcode - bda is used in a map
    final BeanDeploymentArchive bda1 = new BeanDeploymentArchiveImpl("1", Foo.class) {

        @Override
        public boolean equals(Object obj) {
            return (this == obj);
        }

        @Override
        public int hashCode() {
            return System.identityHashCode(this);
        }
    };
    final BeanDeploymentArchive bda2 = new BeanDeploymentArchiveImpl("1", Bar.class) {

        @Override
        public boolean equals(Object obj) {
            return (this == obj);
        }

        @Override
        public int hashCode() {
            return System.identityHashCode(this);
        }
    };
    Deployment deployment = new FlatDeployment(new BeanDeploymentArchive[] { bda1, bda2 }) {

        @Override
        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            return loadBeanDeploymentArchive(beanClass);
        }
    };
    TestContainer container = new TestContainer(deployment);
    container.startContainer();
    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) Test(org.testng.annotations.Test)

Example 12 with TestContainer

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

the class AtInjectTCK method suite.

/**
 * Create JUnit TestSuite
 *
 * @return
 */
public static Test suite() {
    // Create and start the TestContainer, which takes care of starting the container, deploying the
    // classes, starting the contexts etc.
    TestContainer container = new TestContainer(// The classes to deploy as beans
    Convertible.class, Seat.class, V8Engine.class, Cupholder.class, FuelTank.class, Tire.class, // Producer Methods allowing to expose DriversSeat, SpareTire, @Named("spare") SpareTire, @Drivers Seat
    Producers.class);
    container.startContainer();
    // Our entry point is the single bean deployment archive
    BeanManager beanManager = container.getBeanManager(container.getDeployment().getBeanDeploymentArchives().iterator().next());
    // Obtain a reference to the Car and pass it to the TCK to generate the testsuite
    Bean<?> bean = beanManager.resolve(beanManager.getBeans(Car.class));
    Car instance = (Car) beanManager.getReference(bean, Car.class, beanManager.createCreationalContext(bean));
    return Tck.testsFor(instance, false, /* supportsStatic */
    true);
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) Car(org.atinject.tck.auto.Car) BeanManager(javax.enterprise.inject.spi.BeanManager)

Example 13 with TestContainer

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

the class NaiveClusterTest method testSessionReplicationWorksIfBeanIdIndexDisabled.

@Test
public void testSessionReplicationWorksIfBeanIdIndexDisabled() 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);
    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);
    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);
    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 14 with TestContainer

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

the class NaiveClusterTest method testSessionReplication.

@Test
public void testSessionReplication() 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);
    TestContainer container1 = bootstrapContainer(1, classes1);
    BeanManagerImpl beanManager1 = getBeanManager(container1);
    Bean<?> stableBean1 = beanManager1.resolve(beanManager1.getBeans(Stable.class));
    TestContainer container2 = bootstrapContainer(2, classes2);
    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);
    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 15 with TestContainer

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

the class NaiveClusterTest method testSimpleSessionReplication.

@Test(description = "A simple test to check session replication, doesn't carefully check if a bean ids are correct")
public void testSimpleSessionReplication() throws Exception {
    TestContainer container1 = bootstrapContainer(1, Collections.singletonList(Foo.class));
    BeanManagerImpl beanManager1 = getBeanManager(container1);
    Bean<?> fooBean1 = beanManager1.resolve(beanManager1.getBeans(Foo.class));
    TestContainer container2 = bootstrapContainer(2, Collections.singletonList(Foo.class));
    BeanManagerImpl beanManager2 = getBeanManager(container2);
    Bean<?> fooBean2 = beanManager2.resolve(beanManager2.getBeans(Foo.class));
    use(1);
    // Set a value into Foo1
    Foo foo1 = (Foo) beanManager1.getReference(fooBean1, Foo.class, beanManager1.createCreationalContext(fooBean1));
    foo1.setName("container 1");
    replicateSession(1, container1, 2, container2);
    use(2);
    Foo foo2 = (Foo) beanManager2.getReference(fooBean2, Foo.class, beanManager2.createCreationalContext(fooBean2));
    assert foo2.getName().equals("container 1");
    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) Test(org.testng.annotations.Test) AbstractClusterTest(org.jboss.weld.mock.cluster.AbstractClusterTest)

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