use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class SingletonContextTest method testSingletonBeanLifecycle.
@Test
public void testSingletonBeanLifecycle() {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
assertEquals("bar", container.instance().select(Translator.class).get().translate("hello"));
assertTrue(Translator.isInitCallbackInvoked);
assertTrue(Dictionary.isInitCallbackInvoked);
weld.shutdown();
assertTrue(Translator.isDestroyCallbackInvoked);
assertTrue(Dictionary.isDestroyCallbackInvoked);
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class OptimizedCleanupTest method testDisabled.
@Test
public void testDisabled() {
TestExtension.PIT_OBSERVED.set(false);
try (WeldContainer container = new Weld().disableIsolation().addExtension(new TestExtension()).property(Weld.ALLOW_OPTIMIZED_CLEANUP, Boolean.FALSE).initialize()) {
BeanManagerImpl beanManager = BeanManagerProxy.unwrap(container.getBeanManager());
Bean<?> fooBean = beanManager.resolve(beanManager.getBeans(Foo.class));
assertEquals(ApplicationScoped.class, fooBean.getScope());
assertTrue(TestExtension.PIT_OBSERVED.get());
// Find TestExtension.observeFooPit
assertTrue(beanManager.getObservers().stream().anyMatch(o -> o.getBeanClass().equals(TestExtension.class)));
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class OptimizedCleanupTest method testEnabled.
@Test
public void testEnabled() {
TestExtension.PIT_OBSERVED.set(false);
try (WeldContainer container = new Weld().disableIsolation().addExtension(new TestExtension()).property(Weld.ALLOW_OPTIMIZED_CLEANUP, Boolean.TRUE).initialize()) {
BeanManagerImpl beanManager = BeanManagerProxy.unwrap(container.getBeanManager());
Bean<?> fooBean = beanManager.resolve(beanManager.getBeans(Foo.class));
assertEquals(ApplicationScoped.class, fooBean.getScope());
assertTrue(TestExtension.PIT_OBSERVED.get());
// Container lifecycle event observers should be removed
assertTrue(beanManager.getObservers().isEmpty());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class RequestScopedActiveInterceptorTest method requestScopedActiveForAllMethodsInInterceptedClass.
@Test
public void requestScopedActiveForAllMethodsInInterceptedClass() {
try (WeldContainer container = new Weld().initialize()) {
Baz baz = container.select(Baz.class).get();
Assert.assertEquals(3, baz.ping());
}
}
use of org.jboss.weld.environment.se.WeldContainer in project core by weld.
the class RequestScopedActiveInterceptorTest method requestScopedNotActive.
@Test
public void requestScopedNotActive() {
try (WeldContainer container = new Weld().initialize()) {
Foo foo = container.select(Foo.class).get();
foo.notInterceptedCall();
Assert.fail();
} catch (ContextNotActiveException e) {
// expected exception
}
}
Aggregations