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