示例#1
0
文件: Run.java 项目: joomanger/jee
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   Weld weld = new Weld();
   WeldContainer container = weld.initialize();
   BookService bookService = container.instance().select(BookService.class).get();
   System.out.println("Запсукаемся...");
   bookService.test();
 }
 public void startUp() {
   // As per BRDRLPersistence.marshalRHS()
   String dateFormatProperty = System.getProperty("drools.dateformat");
   if (dateFormatProperty == null || dateFormatProperty.length() == 0)
     System.setProperty("drools.dateformat", "dd-MM-yyyy");
   weld = new Weld();
   weldContainer = weld.initialize();
   exporter = weldContainer.instance().select(JcrExporter.class).get();
 }
  public static CliContext buildContext(InputReader input) {

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

    CliContext context = new CliContext(weld, container, input);

    return context;
  }
  @Test
  public void shouldCheckNumberIsMOCK() {
    Weld weld = new Weld();
    WeldContainer container = weld.initialize();

    BookService bookService = container.instance().select(BookService.class).get();
    Book book = bookService.createBook("title", 19.99F, "best book");

    Assert.assertTrue(book.getNumber().startsWith("Mock"));
  }
 static {
   weld = new Weld();
   container = weld.initialize();
   Runtime.getRuntime()
       .addShutdownHook(
           new Thread(
               new Runnable() {
                 @Override
                 public void run() {
                   weld.shutdown();
                 }
               }));
 }
示例#6
0
  public static void main(String[] args) {
    // MyFactory m = MyFactory.getInstance();

    // MyService service = m.getMyServiceImpl();

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

    MyService service = container.select(MyService.class).get();
    System.out.println(service.getValue());

    Scanner s = new Scanner(System.in);
    s.nextInt();

    container.shutdown();
  }
  @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();
  }
示例#8
0
  @Test
  @Ignore
  public void test1() {
    final List<String> classes = new ArrayList<String>();
    classes.add(TestClass.class.getName());
    classes.add(TestClassImpl.class.getName());

    Weld weldContainer =
        new Weld() {
          @Override
          protected Deployment createDeployment(
              ResourceLoader resourceLoader, Bootstrap bootstrap) {
            return new TestWeldSEDeployment(resourceLoader, bootstrap, classes);
          }
        };

    WeldContainer weld = weldContainer.initialize();
    TestClass bean = weld.instance().select(TestClass.class).get();

    System.out.println(bean.getKBase1());
  }
 @BeforeClass
 public static void bootstrap() {
   container = weld.initialize();
 }
 @BeforeClass
 public static void init() {
   weld = new Weld();
   container = weld.initialize();
 }
示例#11
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);
    }
  }
示例#12
0
 public WeldJUnitRunner(final Class<Object> klass) throws InitializationError {
   super(klass);
   this.klass = klass;
   this.weld = new Weld();
   this.container = weld.initialize();
 }