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();
}
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);
}
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();
}
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();
}
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();
}
Aggregations