@Test
  public void testKieModuleMetaDataInMemoryWithJavaClassDefaultPackage() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId = ks.newReleaseId("org.kie", "javaDefaultPackage", "1.0-SNAPSHOT");
    final KieModuleModel kproj = ks.newKieModuleModel();

    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML())
        .writePomXML(generatePomXml(releaseId))
        .write("src/main/java/test/Bean.java", createJavaSource());

    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    assertTrue(messages.isEmpty());

    final KieModule kieModule = kieBuilder.getKieModule();
    final KieModuleMetaData kieModuleMetaData =
        KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);

    // The call to kieModuleMetaData.getClass() assumes a Java file has an explicit package
    final Class<?> beanClass = kieModuleMetaData.getClass("", "test.Bean");
    assertNotNull(beanClass);

    final TypeMetaInfo beanMetaInfo = kieModuleMetaData.getTypeMetaInfo(beanClass);
    assertNotNull(beanMetaInfo);
  }
  private KieModuleModel createKieProjectWithPackages(KieServices ks, String pkg) {
    KieModuleModel kmodule = ks.newKieModuleModel();
    kmodule
        .newKieBaseModel("KBase")
        .addPackage(pkg)
        .setDefault(true)
        .newKieSessionModel("defaultSession")
        .setDefault(true);

    return kmodule;
  }
Exemplo n.º 3
0
  public static KieModule buildAndInstallKieModuleIntoRepo(
      final ReleaseId releaseId,
      final KieBaseTestConfiguration kieBaseConfiguration,
      final Resource... resources) {
    final KieServices kieServices = KieServices.Factory.get();

    final KieModuleModel module = kieServices.newKieModuleModel();
    final KieBaseModel base = kieBaseConfiguration.getKieBaseModel(module);
    final KieFileSystem fileSystem = getKieFileSystemWithKieModule(module, releaseId, resources);
    final KieBuilder builder = getKieBuilderFromKieFileSystem(fileSystem, true);
    final KieModule kieModule = builder.getKieModule();
    kieServices.getRepository().addKieModule(kieModule);
    return kieModule;
  }
Exemplo n.º 4
0
  /**
   * This method loads the rule base associated with the Drools event processor.
   *
   * @return The knowledge base
   */
  private KieBase loadRuleBase() {
    String droolsRuleBase = getRuleName() + ".drl";

    try {
      KieServices ks = KieServices.Factory.get();
      KieRepository kr = ks.getRepository();

      KieModuleModel kmm = ks.newKieModuleModel();
      KieBaseModel kbm =
          kmm.newKieBaseModel(getRuleName())
              .setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
              .setEventProcessingMode(EventProcessingOption.STREAM);
      kbm.setDefault(true);

      KieFileSystem kfs = ks.newKieFileSystem();
      kfs.write(
          "src/main/resources/" + kbm.getName() + "/rule1.drl",
          ks.getResources().newClassPathResource(droolsRuleBase));
      kfs.writeKModuleXML(kmm.toXML());

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

      KieContainer container = ks.newKieContainer(kr.getDefaultReleaseId());
      KieBase kbase = container.getKieBase();
      // TODO: hack it for now, this attribute should be supported in the following drools6 release.
      System.setProperty("kie.mbean", "enabled");
      return kbase;

    } catch (Throwable e) {
      LOG.log(
          Level.SEVERE,
          MessageFormat.format(
              java.util.PropertyResourceBundle.getBundle("ep-drools.Messages")
                  .getString("EP-DROOLS-1"),
              droolsRuleBase,
              getRuleName()),
          e);
    }

    return (null);
  }
Exemplo n.º 5
0
  public void init() {
    final KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmodule = ks.newKieModuleModel();

    KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true);
    baseModel.newKieSessionModel("defaultKSession").setDefault(true);

    kfs.writeKModuleXML(kmodule.toXML());
    kfs.write(
        ks.getResources()
            .newClassPathResource(
                "decimalSeparator.xls",
                this.getClass())); // README when path is set then test works
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(
        0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());

    ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
  }
  protected KieFileSystem createKieFileSystemWithKProject(KieServices ks) {
    KieModuleModel kproj = ks.newKieModuleModel();

    KieBaseModel kieBaseModel1 =
        kproj
            .newKieBaseModel("defaultKieBase")
            .setDefault(true)
            .addPackage("*")
            .setEqualsBehavior(EqualityBehaviorOption.EQUALITY)
            .setEventProcessingMode(EventProcessingOption.STREAM);

    kieBaseModel1
        .newKieSessionModel("defaultKieSession")
        .setDefault(true)
        .setType(KieSessionModel.KieSessionType.STATEFUL)
        .setClockType(ClockTypeOption.get("realtime"))
        .newWorkItemHandlerModel(
            "Log", "new org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler()");
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML());
    return kfs;
  }