Search in sources :

Example 36 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project core by weld.

the class RequestScopedActiveInterceptorTest method requestScopedActive.

@Test
public void requestScopedActive() {
    try (WeldContainer container = new Weld().initialize()) {
        Foo foo = container.select(Foo.class).get();
        foo.ping();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 37 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project core by weld.

the class ContainerInstanceTest method testDependentInstanceDestroyedDuringShutdown.

@Test
public void testDependentInstanceDestroyedDuringShutdown() {
    Foo.DESTROYED.set(false);
    try (WeldContainer container = new Weld().disableDiscovery().beanClasses(Foo.class).initialize()) {
        CDI.current().select(Foo.class).get();
    }
    // Dependent bean instances obtained by CDI should be destroyed correctly during shutdown
    assertTrue(Foo.DESTROYED.get());
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 38 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project core by weld.

the class ContainerIsolationTest method testContainerIsolation.

@Test
public void testContainerIsolation() {
    Weld weld1 = new Weld("1");
    WeldContainer weldContainer1 = weld1.initialize();
    Foo foo1 = weldContainer1.instance().select(Foo.class).get();
    Weld weld2 = new Weld("2");
    WeldContainer weldContainer2 = weld2.initialize();
    Foo foo2 = weldContainer2.instance().select(Foo.class).get();
    foo1.setValue(1);
    foo2.setValue(2);
    Assert.assertEquals(1, foo1.getValue());
    Assert.assertEquals(2, foo2.getValue());
    weld1.shutdown();
    Assert.assertEquals(2, foo2.getValue());
    weld2.shutdown();
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 39 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project core by weld.

the class TestExtension method beforeBeanDiscovery.

public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event) {
    CDI<Object> cdi = CDI.current();
    @SuppressWarnings("resource") WeldContainer container = (WeldContainer) cdi;
    assertFalse(container.isRunning());
    try {
        cdi.select(Object.class);
        fail();
    } catch (IllegalStateException expected) {
    }
    beanManagerReference.set(cdi.getBeanManager());
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer)

Example 40 with WeldContainer

use of org.jboss.weld.environment.se.WeldContainer in project core by weld.

the class WeldSEProviderTest method testExtension.

@Test
public void testExtension() {
    TestExtension.reset();
    try (WeldContainer weldContainer = new Weld().disableDiscovery().beanClasses(Foo.class).addExtension(new TestExtension()).initialize()) {
        BeanManager beanManager = TestExtension.beanManagerReference.get();
        assertNotNull(beanManager);
        Bean<?> fooBean = TestExtension.fooBeanReference.get();
        assertNotNull(fooBean);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) 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