Search in sources :

Example 41 with WeldContainer

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

the class WeldSEProviderTest method testDependentInstanceDestroyedDuringShutdown.

@Test
public void testDependentInstanceDestroyedDuringShutdown() {
    Baz.DISPOSED.set(false);
    try (WeldContainer weldContainer = new Weld().disableDiscovery().beanClasses(Baz.class).initialize()) {
        assertTrue(CDI.current().select(Baz.class).get().ping());
        assertFalse(Baz.DISPOSED.get());
    }
    assertTrue(Baz.DISPOSED.get());
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 42 with WeldContainer

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

the class WeldSEProviderTest method testMultipleContainers.

@Test
public void testMultipleContainers() {
    Weld weld = new Weld().disableDiscovery();
    try {
        WeldContainer weldContainer1 = weld.containerId("foo").beanClasses(Foo.class).initialize();
        WeldContainer weldContainer2 = weld.containerId("bar").beanClasses(Bar.class).initialize();
        // The caller cannot be used to determine the right container - the first one is returned
        assertCdi(CDI.current(), weldContainer1.getId());
        // Foo is caller
        assertCdi(weldContainer1.select(Foo.class).get().getCurrent(), weldContainer1.getId());
        // Bar is caller
        assertCdi(weldContainer2.select(Bar.class).get().getCurrent(), weldContainer2.getId());
    } finally {
        weld.shutdown();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 43 with WeldContainer

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

the class PostConstructInheritanceTest method testPostConstructInherited.

@Test
public void testPostConstructInherited() {
    Weld weld = new Weld();
    try {
        Plant.postConstructCalled = false;
        WeldContainer weldContainer = weld.initialize();
        weldContainer.instance().select(Tree.class).get();
        assertTrue(Plant.postConstructCalled);
    } finally {
        weld.shutdown();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 44 with WeldContainer

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

the class InterceptorEnabledForAppAndArchiveTest method testInitialization.

@Test
public void testInitialization() {
    try (WeldContainer container = new Weld().disableDiscovery().beanClasses(TransasctionalService.class, TransactionalInterceptor.class).addInterceptor(TransactionalInterceptor.class).initialize()) {
        ActionSequence.reset();
        container.select(TransasctionalService.class).get().ping();
        ActionSequence.assertSequenceDataEquals(TransactionalInterceptor.class.getName());
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 45 with WeldContainer

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

the class InjectionPointTest method testInjectionPoint.

@Test
public void testInjectionPoint() throws Exception {
    try (WeldContainer weld = new Weld().disableDiscovery().beanClasses(Foo.class).initialize()) {
        final InjectionPoint ip = weld.select(Foo.class).get().getIp();
        assertEquals(Foo.class, ip.getType());
    }
}
Also used : InjectionPoint(javax.enterprise.inject.spi.InjectionPoint) WeldContainer(org.jboss.weld.environment.se.WeldContainer) 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