Search in sources :

Example 96 with WeldContainer

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

the class WeldInstanceSelectTypeTest method testInvalidSelect.

@Test
public void testInvalidSelect() {
    Type secondType = SomeOtherBean.class;
    try (WeldContainer container = new Weld().initialize()) {
        // get more specific instance than Object and try again
        WeldInstance<SomeInterface> someInterfaceInstance = container.select(SomeInterface.class);
        // selecting from anything else than Object is not allowed
        try {
            someInterfaceInstance.select(secondType);
            Assert.fail("Selecting by type from any other type than Object should fail with IllegalStateException!");
        } catch (IllegalStateException e) {
        // expected
        }
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 97 with WeldContainer

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

the class WeldInstanceSelectTypeTest method testSelectOnTypedBean.

@Test
public void testSelectOnTypedBean() {
    // typed bean has no Object type, from bean selection perspective, it isn't hierarchical select from WeldInstance<Object>
    Type type = TypedBean.class;
    try (WeldContainer container = new Weld().initialize()) {
        // should work
        TypedBean bean = container.<TypedBean>select(type).get();
        Assert.assertNotNull(bean);
    }
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 98 with WeldContainer

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

the class EEResourceInjectionIgnoredTest method testInjection.

@Test
public void testInjection() {
    try (WeldContainer container = new Weld().initialize()) {
        Golf golf = container.select(Golf.class).get();
        assertNull(golf.getEntityManager());
        assertEquals(10, golf.getDelta().ping());
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 99 with WeldContainer

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

the class ExplicitResourceLoaderExtensionScanningTest method testScanning.

@Test
public void testScanning() {
    ClassLoader classLoader = new URLClassLoader(new URL[] {}, Alpha.class.getClassLoader()) {

        @Override
        public Enumeration<URL> getResources(String name) throws IOException {
            if ("META-INF/services/javax.enterprise.inject.spi.Extension".equals(name)) {
                // Load only AlphaExtension
                return super.getResources("META-INF/services/" + MyExtension.class.getName());
            }
            return super.getResources(name);
        }
    };
    try (WeldContainer container = new Weld().setResourceLoader(new ClassLoaderResourceLoader(classLoader)).initialize()) {
        container.select(Alpha.class).get().ping();
        assertTrue(container.select(Bravo.class).isUnsatisfied());
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) WeldContainer(org.jboss.weld.environment.se.WeldContainer) URLClassLoader(java.net.URLClassLoader) ClassLoaderResourceLoader(org.jboss.weld.resources.ClassLoaderResourceLoader) URL(java.net.URL) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 100 with WeldContainer

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

the class StartMainObserversTest method testObservers.

@Test
public void testObservers() {
    InitObserverTestBean.reset();
    ObserverTestBean.reset();
    WeldContainer container = startMain.go();
    BeanManager manager = container.getBeanManager();
    manager.fireEvent(new CustomEvent());
    assertTrue(ObserverTestBean.isBuiltInObserved());
    assertTrue(ObserverTestBean.isCustomObserved());
    assertTrue(ObserverTestBean.isInitObserved());
    assertTrue(InitObserverTestBean.isInitObserved());
}
Also used : CustomEvent(org.jboss.weld.environment.se.test.beans.CustomEvent) WeldContainer(org.jboss.weld.environment.se.WeldContainer) BeanManager(javax.enterprise.inject.spi.BeanManager) 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