use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class ContainerEventsTest method testContainerEventsToString.
@Test
public void testContainerEventsToString() {
String id = "007";
ActionSequence.reset();
try (WeldContainer container = new Weld(id).disableDiscovery().beanClasses(ContainerEventToStringObserver.class).initialize()) {
assertFalse(container.select(ContainerEventToStringObserver.class).isUnsatisfied());
}
assertEquals(expectedToStringResult("ContainerInitialized", id), ContainerEventToStringObserver.containerInitializedToString);
assertEquals(expectedToStringResult("ContainerShutdown", id), ContainerEventToStringObserver.containerShutdownToString);
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class ContainerInstanceTest method testDependentInstanceDestroy.
@Test
public void testDependentInstanceDestroy() {
Foo.DESTROYED.set(false);
try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Foo.class).initialize()) {
// We only use one container - CDI instance is unambiguous
Foo foo = CDI.current().select(Foo.class).get();
CDI.current().destroy(foo);
// We should be able to destroy a dependent bean instance obtained by CDI
assertTrue(Foo.DESTROYED.get());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldSEProviderTest method testSingleContainer.
@Test
public void testSingleContainer() {
try (WeldContainer weldContainer = new Weld().disableDiscovery().beanClasses(Foo.class).initialize()) {
assertCdi(CDI.current(), weldContainer.getId());
assertCdi(weldContainer.select(Foo.class).get().getCurrent(), weldContainer.getId());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldBuilderTest method testSyntheticBeanArchive.
@Test
public void testSyntheticBeanArchive() throws Exception {
Weld weld = new Weld().disableDiscovery();
try (WeldContainer container = weld.containerId("FOO").beanClasses(Foo.class, Bar.class, Cat.class).initialize()) {
assertEquals(10, container.select(Foo.class).get().getVal());
assertTrue(container.select(Bar.class).isUnsatisfied());
assertTrue(container.select(Cat.class).isUnsatisfied());
assertTrue(container.select(Qux.class).isUnsatisfied());
}
// Test AutoCloseable
assertNull(WeldContainer.instance("FOO"));
// Test alternatives selected for the synthetic BDA
try (WeldContainer container = weld.beanClasses(Foo.class, Bar.class, Cat.class).alternatives(Bar.class).alternativeStereotypes(AlternativeStereotype.class).initialize()) {
assertEquals(10, container.select(Foo.class).get().getVal());
assertEquals(1, container.select(Bar.class).get().getVal());
assertEquals(5, container.select(Cat.class).get().getVal());
}
// Test interceptor enabled for the synthetic BDA
try (WeldContainer container = weld.reset().beanClasses(Qux.class, MonitoringInterceptor.class).interceptors(MonitoringInterceptor.class).initialize()) {
assertEquals(Integer.valueOf(11), container.select(Qux.class).get().ping());
}
// Test decorator enabled for the synthetic BDA
try (WeldContainer container = weld.reset().beanClasses(Foo.class, CoolDecorator.class).decorators(CoolDecorator.class).initialize()) {
assertEquals("NOK", container.select(Foo.class).get().methodToBeDecorated());
}
// Test addBeanClass()
try (WeldContainer container = weld.reset().beanClasses(Bar.class).addBeanClass(Foo.class).alternatives(Bar.class).initialize()) {
assertEquals(10, container.select(Foo.class).get().getVal());
assertEquals(1, container.select(Bar.class).get().getVal());
assertTrue(container.select(Baz.class).isUnsatisfied());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class WeldBuilderTest method testReset.
@Test
public void testReset() {
Weld weld = new Weld().containerId("FOO").disableDiscovery().property(ConfigurationKey.BEAN_IDENTIFIER_INDEX_OPTIMIZATION.get(), true).beanClasses(Foo.class);
weld.reset();
assertFalse(weld.isDiscoveryEnabled());
assertEquals("FOO", weld.getContainerId());
try (WeldContainer container = weld.beanClasses(Bar.class).initialize()) {
assertTrue(container.select(Foo.class).isUnsatisfied());
assertTrue(container.select(BeanManagerImpl.class).get().getServices().get(WeldConfiguration.class).getBooleanProperty(ConfigurationKey.BEAN_IDENTIFIER_INDEX_OPTIMIZATION));
}
}
Aggregations