コード例 #1
0
  private InternalKieModule createKieJar(KieServices ks, KieFactory kf, GAV gav, String... rules)
      throws IOException {
    KieFileSystem kfs = kf.newKieFileSystem();
    for (String rule : rules) {
      String file = "org/test/" + rule + ".drl";
      kfs.write("src/main/resources/KBase1/" + file, createDRL(rule));
    }

    KieModuleModel kproj = kf.newKieModuleModel();

    KieBaseModel kieBaseModel1 =
        kproj
            .newKieBaseModel("KBase1")
            .setEqualsBehavior(AssertBehaviorOption.EQUALITY)
            .setEventProcessingMode(EventProcessingOption.STREAM);

    KieSessionModel ksession1 =
        kieBaseModel1
            .newKieSessionModel("KSession1")
            .setType(KieSessionType.STATEFUL)
            .setClockType(ClockTypeOption.get("realtime"));

    kfs.writeKModuleXML(kproj.toXML());
    kfs.writePomXML(getPom(gav));

    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    assertTrue(kieBuilder.build().getInsertedMessages().isEmpty());
    return (InternalKieModule) kieBuilder.getKieModule();
  }
コード例 #2
0
  private InternalKieModule createKieJarWithClass(
      KieServices ks, KieFactory kf, GAV gav, int value, int factor) throws IOException {
    KieFileSystem kieFileSystem = kf.newKieFileSystem();

    KieModuleModel kproj = kf.newKieModuleModel();

    KieBaseModel kieBaseModel1 =
        kproj
            .newKieBaseModel("KBase1")
            .setEqualsBehavior(AssertBehaviorOption.EQUALITY)
            .setEventProcessingMode(EventProcessingOption.STREAM);

    KieSessionModel ksession1 =
        kieBaseModel1
            .newKieSessionModel("KSession1")
            .setType(KieSessionType.STATEFUL)
            .setClockType(ClockTypeOption.get("realtime"));

    kieFileSystem
        .writeKModuleXML(kproj.toXML())
        .writePomXML(getPom(gav))
        .write(
            "src/main/resources/" + kieBaseModel1.getName() + "/rule1.drl",
            createDRLForJavaSource(value))
        .write("src/main/java/org/kie/test/Bean.java", createJavaSource(factor));

    KieBuilder kieBuilder = ks.newKieBuilder(kieFileSystem);
    assertTrue(kieBuilder.build().getInsertedMessages().isEmpty());
    return (InternalKieModule) kieBuilder.getKieModule();
  }
コード例 #3
0
  @Test
  public void testFailingHelloWorld() throws Exception {
    String drl =
        "package org.drools\n"
            + "rule R1 when\n"
            + "   $m : Message( mesage == \"Hello World\" )\n"
            + "then\n"
            + "end\n";

    KieServices ks = KieServices.Factory.get();

    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);

    KieBuilder kb = ks.newKieBuilder(kfs).buildAll();

    assertEquals(1, kb.getResults().getMessages().size());
  }