Search in sources :

Example 86 with WeldContainer

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

Example 87 with WeldContainer

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

Example 88 with WeldContainer

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

Example 89 with WeldContainer

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

Example 90 with WeldContainer

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));
    }
}
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)

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