Exemplo n.º 1
0
  @Test
  public void testGo() {
    Weld w = new Weld();
    WeldContainer wc = w.initialize();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(baos);

    CDIInstanceExample bean = wc.instance().select(CDIInstanceExample.class).get();
    bean.go(ps);

    ps.close();

    String actual = new String(baos.toByteArray());
    String expected =
        "" + "Dave: Hello, HAL. Do you read me, HAL?" + NL + "HAL: Dave. I read you." + NL;
    assertEquals(expected, actual);

    w.shutdown();
  }
Exemplo n.º 2
0
 @AfterClass
 public static void shutdown() {
   weld.shutdown();
 }
Exemplo n.º 3
0
  @Test
  public void createMultpleJarAndFileResources()
      throws IOException, ClassNotFoundException, InterruptedException {
    createKProjectJar("jar1", true);
    createKProjectJar("jar2", true);
    createKProjectJar("jar3", true);
    createKProjectJar("fol4", false);

    ClassLoader origCl = Thread.currentThread().getContextClassLoader();
    try {
      java.io.File file1 = fileManager.newFile("jar1.jar");
      java.io.File file2 = fileManager.newFile("jar2.jar");
      java.io.File file3 = fileManager.newFile("jar3.jar");
      java.io.File fol4 = fileManager.newFile("fol4");
      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("META-INF/kproject.xml");
      while (e.hasMoreElements()) {
        URL url = e.nextElement();
        System.out.println(url);
      }

      Class cls =
          Thread.currentThread()
              .getContextClassLoader()
              .loadClass("org.drools.cdi.test.KProjectTestClassjar1");
      assertNotNull(cls);
      cls =
          Thread.currentThread()
              .getContextClassLoader()
              .loadClass("org.drools.cdi.test.KProjectTestClassjar2");
      assertNotNull(cls);
      cls =
          Thread.currentThread()
              .getContextClassLoader()
              .loadClass("org.drools.cdi.test.KProjectTestClassjar3");
      assertNotNull(cls);

      Weld weldContainer = new Weld();
      WeldContainer weld = weldContainer.initialize();

      Set<Bean<?>> beans =
          weld.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar1"));
      Bean bean = (Bean) beans.toArray()[0];
      KProjectTestClass o1 =
          (KProjectTestClass) bean.create(weld.getBeanManager().createCreationalContext(null));
      assertNotNull(o1);
      testEntry(o1, "jar1");

      beans = weld.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar2"));
      bean = (Bean) beans.toArray()[0];
      KProjectTestClass o2 =
          (KProjectTestClass) bean.create(weld.getBeanManager().createCreationalContext(null));
      assertNotNull(o2);
      testEntry(o2, "jar2");

      beans = weld.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("jar3"));
      bean = (Bean) beans.toArray()[0];
      KProjectTestClass o3 =
          (KProjectTestClass) bean.create(weld.getBeanManager().createCreationalContext(null));
      assertNotNull(o3);
      testEntry(o3, "jar3");

      beans = weld.getBeanManager().getBeans(KProjectTestClass.class, new KPTestLiteral("fol4"));
      bean = (Bean) beans.toArray()[0];
      KProjectTestClass o4 =
          (KProjectTestClass) bean.create(weld.getBeanManager().createCreationalContext(null));
      assertNotNull(o4);
      testEntry(o4, "fol4");

      weldContainer.shutdown();
    } finally {
      Thread.currentThread().setContextClassLoader(origCl);
    }
  }
Exemplo n.º 4
0
 public void shutdown() {
   weld.shutdown();
 }