Search in sources :

Example 31 with WeldContainer

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);
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 32 with WeldContainer

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)));
    }
}
Also used : ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) Arquillian(org.jboss.arquillian.junit.Arquillian) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Archive(org.jboss.shrinkwrap.api.Archive) BeanManagerProxy(org.jboss.weld.bean.builtin.BeanManagerProxy) ClassPath(org.jboss.arquillian.container.se.api.ClassPath) WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanArchive(org.jboss.shrinkwrap.api.BeanArchive) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) Deployment(org.jboss.arquillian.container.test.api.Deployment) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Bean(javax.enterprise.inject.spi.Bean) Assert.assertEquals(org.junit.Assert.assertEquals) Weld(org.jboss.weld.environment.se.Weld) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 33 with WeldContainer

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());
    }
}
Also used : BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 34 with WeldContainer

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());
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 35 with WeldContainer

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
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Aggregations

WeldContainer (org.jboss.weld.environment.se.WeldContainer)115 Weld (org.jboss.weld.environment.se.Weld)100 Test (org.junit.Test)98 CountDownLatch (java.util.concurrent.CountDownLatch)8 Bean (javax.enterprise.inject.spi.Bean)8 BeanManager (javax.enterprise.inject.spi.BeanManager)8 Type (java.lang.reflect.Type)7 URLClassLoader (java.net.URLClassLoader)7 ArrayList (java.util.ArrayList)7 URL (java.net.URL)6 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)6 Fabric8Extension (io.fabric8.cdi.Fabric8Extension)4 ParameterizedType (java.lang.reflect.ParameterizedType)4 List (java.util.List)4 CreationalContext (javax.enterprise.context.spi.CreationalContext)4 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 PrintStream (java.io.PrintStream)3 ServiceRegistry (org.jboss.weld.bootstrap.api.ServiceRegistry)3