Search in sources :

Example 71 with WeldContainer

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

the class ThreadScopedActiveInterceptorTest method threadScopeActivatedWithInterceptorAtTypeLeve.

@Test
public void threadScopeActivatedWithInterceptorAtTypeLeve() {
    try (WeldContainer container = new Weld().initialize()) {
        Bar bar = container.select(Bar.class).get();
        Assert.assertEquals(2, bar.doubleIncrement());
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 72 with WeldContainer

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

the class DevelopmentModeDisabledSmokeTest method testDevelopmentMode.

@SuppressWarnings("unchecked")
@Test
public void testDevelopmentMode() {
    try (WeldContainer container = new Weld().initialize()) {
        assertTrue(container.select(ProbeExtension.class).isUnsatisfied());
        BeanManager beanManager = container.getBeanManager();
        Bean<Omega> bean = (Bean<Omega>) beanManager.resolve(beanManager.getBeans(Omega.class));
        assertFalse(bean.getStereotypes().contains(MonitoredComponent.class));
        container.select(Omega.class).get().ping();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) MonitoredComponent(org.jboss.weld.probe.MonitoredComponent) Weld(org.jboss.weld.environment.se.Weld) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 73 with WeldContainer

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

the class DevelopmentModeEnabledSmokeTest method testDevelopmentMode.

@SuppressWarnings("unchecked")
@Test
public void testDevelopmentMode() {
    try (WeldContainer container = new Weld().initialize()) {
        assertNotNull(container.select(ProbeExtension.class).get());
        BeanManager beanManager = container.getBeanManager();
        Bean<Omega> bean = (Bean<Omega>) beanManager.resolve(beanManager.getBeans(Omega.class));
        assertTrue(bean.getStereotypes().contains(MonitoredComponent.class));
        container.select(Omega.class).get().ping();
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) MonitoredComponent(org.jboss.weld.probe.MonitoredComponent) Weld(org.jboss.weld.environment.se.Weld) Bean(javax.enterprise.inject.spi.Bean) Test(org.junit.Test)

Example 74 with WeldContainer

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

the class WeldInstanceTest method testHandlers.

@Test
public void testHandlers() {
    ActionSequence.reset();
    try (WeldContainer container = new Weld().initialize()) {
        WeldInstance<Processor> instance = container.select(Processor.class);
        assertTrue(instance.isAmbiguous());
        for (Handler<Processor> handler : instance.handlers()) {
            handler.get().ping();
            if (handler.getBean().getScope().equals(Dependent.class)) {
                handler.destroy();
            }
        }
        assertEquals(3, ActionSequence.getSequenceSize());
        ActionSequence.assertSequenceDataContainsAll("firstPing", "secondPing", "firstDestroy");
        ActionSequence.reset();
        assertTrue(instance.isAmbiguous());
        for (Iterator<Handler<Processor>> iterator = instance.handlers().iterator(); iterator.hasNext(); ) {
            try (Handler<Processor> handler = iterator.next()) {
                handler.get().ping();
            }
        }
        assertEquals(4, ActionSequence.getSequenceSize());
        ActionSequence.assertSequenceDataContainsAll("firstPing", "secondPing", "firstDestroy", "secondDestroy");
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Handler(org.jboss.weld.inject.WeldInstance.Handler) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 75 with WeldContainer

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

the class WeldInstanceTest method testGetHandler.

@Test
public void testGetHandler() {
    ActionSequence.reset();
    try (WeldContainer container = new Weld().initialize()) {
        Bean<?> alphaBean = container.getBeanManager().resolve(container.getBeanManager().getBeans(Alpha.class));
        WeldInstance<Alpha> instance = container.select(Alpha.class);
        Handler<Alpha> alpha1 = instance.getHandler();
        assertEquals(alphaBean, alpha1.getBean());
        assertEquals(Dependent.class, alpha1.getBean().getScope());
        // Contextual reference is obtained lazily
        assertNull(ActionSequence.getSequenceData());
        String alpha2Id;
        // Test try-with-resource
        try (Handler<Alpha> alpha2 = instance.getHandler()) {
            assertNull(ActionSequence.getSequenceData());
            alpha2Id = alpha2.get().getId();
            assertFalse(alpha1.get().getId().equals(alpha2Id));
        }
        List<String> sequence = ActionSequence.getSequenceData();
        assertEquals(3, sequence.size());
        assertEquals("c" + alpha2Id, sequence.get(0));
        assertEquals("c" + alpha1.get().getId(), sequence.get(1));
        assertEquals("d" + alpha2Id, sequence.get(2));
        alpha1.destroy();
        // Alpha1 destroyed
        sequence = ActionSequence.getSequenceData();
        assertEquals(4, sequence.size());
        assertEquals("d" + alpha1.get().getId(), sequence.get(3));
        // Subsequent invocations are no-op
        alpha1.destroy();
        // Test normal scoped bean is also destroyed
        WeldInstance<Bravo> bravoInstance = container.select(Bravo.class);
        String bravoId = bravoInstance.get().getId();
        try (Handler<Bravo> bravo = bravoInstance.getHandler()) {
            assertEquals(bravoId, bravo.get().getId());
            ActionSequence.reset();
        }
        sequence = ActionSequence.getSequenceData();
        assertEquals(1, sequence.size());
        assertEquals("d" + bravoId, sequence.get(0));
    }
}
Also used : 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