Search in sources :

Example 1 with WeldContainer

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

the class CDILiquibaseTest method shouldRunWhenShouldRunIsTrue.

@Test
public void shouldRunWhenShouldRunIsTrue() {
    System.setProperty("liquibase.shouldRun", "true");
    WeldContainer weld = new Weld().initialize();
    CDILiquibase cdiLiquibase = weld.instance().select(CDILiquibase.class).get();
    assertNotNull(cdiLiquibase);
    assertTrue(cdiLiquibase.isInitialized());
    assertTrue(cdiLiquibase.isUpdateSuccessful());
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 2 with WeldContainer

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

the class CDILiquibaseTest method shouldntRunWhenShouldRunIsFalse.

@Test
public void shouldntRunWhenShouldRunIsFalse() {
    System.setProperty("liquibase.shouldRun", "false");
    WeldContainer weld = new Weld().initialize();
    CDILiquibase cdiLiquibase = weld.instance().select(CDILiquibase.class).get();
    assertNotNull(cdiLiquibase);
    assertFalse(cdiLiquibase.isInitialized());
    assertFalse(cdiLiquibase.isUpdateSuccessful());
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 3 with WeldContainer

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

the class KieProjectCDITest method createMultpleJarAndFileResources.

@Test
public void createMultpleJarAndFileResources() throws IOException, ClassNotFoundException, InterruptedException {
    createKieModule("jar1", true);
    createKieModule("jar2", true);
    createKieModule("jar3", true);
    createKieModule("fol4", false);
    ClassLoader origCl = Thread.currentThread().getContextClassLoader();
    try {
        java.io.File file1 = fileManager.newFile("jar1-1.0-SNAPSHOT.jar");
        java.io.File file2 = fileManager.newFile("jar2-1.0-SNAPSHOT.jar");
        java.io.File file3 = fileManager.newFile("jar3-1.0-SNAPSHOT.jar");
        java.io.File fol4 = fileManager.newFile("fol4-1.0-SNAPSHOT");
        URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { file1.toURI().toURL(), file2.toURI().toURL(), file3.toURI().toURL(), fol4.toURI().toURL() });
        Thread.currentThread().setContextClassLoader(urlClassLoader);
        Enumeration<URL> e = urlClassLoader.getResources(KieModuleModelImpl.KMODULE_JAR_PATH);
        while (e.hasMoreElements()) {
            URL url = e.nextElement();
            System.out.println(url);
        }
        Class cls = Thread.currentThread().getContextClassLoader().loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar1");
        assertNotNull(cls);
        cls = Thread.currentThread().getContextClassLoader().loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar2");
        assertNotNull(cls);
        cls = Thread.currentThread().getContextClassLoader().loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar3");
        assertNotNull(cls);
        Weld weld = CDITestRunner.createWeld(KProjectTestClass.class.getName(), KPTestLiteral.class.getName(), "org.drools.compiler.cdi.test.KProjectTestClassjar1", "org.drools.compiler.cdi.test.KProjectTestClassjar2", "org.drools.compiler.cdi.test.KProjectTestClassjar3", "org.drools.compiler.cdi.test.KProjectTestClassfol4");
        ((KieServicesImpl) KieServices.Factory.get()).nullKieClasspathContainer();
        WeldContainer container = weld.initialize();
        Set<Bean<?>> beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar1"));
        Bean bean = (Bean) beans.toArray()[0];
        KProjectTestClass o1 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o1);
        testEntry(o1, "jar1");
        beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar2"));
        bean = (Bean) beans.toArray()[0];
        KProjectTestClass o2 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o2);
        testEntry(o2, "jar2");
        beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar3"));
        bean = (Bean) beans.toArray()[0];
        KProjectTestClass o3 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o3);
        testEntry(o3, "jar3");
        beans = container.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("fol4"));
        bean = (Bean) beans.toArray()[0];
        KProjectTestClass o4 = (KProjectTestClass) bean.create(container.getBeanManager().createCreationalContext(null));
        assertNotNull(o4);
        testEntry(o4, "fol4");
        weld.shutdown();
    } finally {
        // FIXME Java 7+
        // on Windows, the URLClassLoader will not release all resources,
        // so the attempt to delete the temporary files will fail.
        // an explicit dispose call is needed, but it has not been introduced until Java7+
        // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4950148
        /*
            ((URLClassLoader) Thread.currentThread().getContextClassLoader()).close();
            */
        Thread.currentThread().setContextClassLoader(origCl);
    }
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) URL(java.net.URL) Weld(org.jboss.weld.environment.se.Weld) Bean(javax.enterprise.inject.spi.Bean) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) KieServicesImpl(org.drools.compiler.kie.builder.impl.KieServicesImpl) Test(org.junit.Test)

Example 4 with WeldContainer

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

the class CDITest method testCDI.

@Test
public void testCDI() {
    // DROOLS-34
    Weld w = new Weld();
    WeldContainer wc = w.initialize();
    CDIBean bean = wc.instance().select(CDIBean.class).get();
    bean.test(env);
    w.shutdown();
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld) Test(org.junit.Test)

Example 5 with WeldContainer

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

the class CDIExampleWithInclusion method main.

public static void main(String[] args) {
    Weld w = new Weld();
    WeldContainer wc = w.initialize();
    CDIExampleWithInclusion bean = wc.instance().select(CDIExampleWithInclusion.class).get();
    bean.go(System.out);
    w.shutdown();
}
Also used : WeldContainer(org.jboss.weld.environment.se.WeldContainer) Weld(org.jboss.weld.environment.se.Weld)

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 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 Bean (javax.enterprise.inject.spi.Bean)6 ParameterizedType (java.lang.reflect.ParameterizedType)4 List (java.util.List)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 Foo (org.jboss.weld.environment.se.test.discovery.synthetic.bdm.discoveredPackage.Foo)3 Bar (org.jboss.weld.environment.se.test.discovery.synthetic.bdm.hiddenPackage.Bar)3