@Test
  @Ignore
  public void testKScannerWithKJarContainingClasses() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFactory kf = KieFactory.Factory.get();
    GAV gav = kf.newGav("org.kie", "scanner-test", "1.0-SNAPSHOT");

    InternalKieModule kJar1 = createKieJarWithClass(ks, kf, gav, 2, 7);

    MavenRepository repository = getMavenRepository();
    repository.deployArtifact(gav, kJar1, kPom);

    KieContainer kieContainer = ks.getKieContainer(gav);
    KieScanner scanner = ks.newKieScanner(kieContainer);

    KieSession ksession = kieContainer.getKieSession("KSession1");
    checkKSession(ksession, 14);

    InternalKieModule kJar2 = createKieJarWithClass(ks, kf, gav, 3, 5);
    repository.deployArtifact(gav, kJar2, kPom);

    scanner.scanNow();

    KieSession ksession2 = kieContainer.getKieSession("KSession1");
    checkKSession(ksession2, 15);
  }
  @Test
  @Ignore
  public void testKScanner() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFactory kf = KieFactory.Factory.get();
    GAV gav = kf.newGav("org.kie", "scanner-test", "1.0-SNAPSHOT");

    InternalKieModule kJar1 = createKieJar(ks, kf, gav, "rule1", "rule2");
    KieContainer kieContainer = ks.getKieContainer(gav);

    MavenRepository repository = getMavenRepository();
    repository.deployArtifact(gav, kJar1, kPom);

    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.getKieSession("KSession1");
    checkKSession(ksession, "rule1", "rule2");

    // create a new kjar
    InternalKieModule kJar2 = createKieJar(ks, kf, gav, "rule2", "rule3");

    // deploy it on maven
    repository.deployArtifact(gav, kJar2, kPom);

    // since I am not calling start() on the scanner it means it won't have automatic scheduled
    // scanning
    KieScanner scanner = ks.newKieScanner(kieContainer);

    // scan the maven repo to get the new kjar version and deploy it on the kcontainer
    scanner.scanNow();

    // create a ksesion and check it works as expected
    KieSession ksession2 = kieContainer.getKieSession("KSession1");
    checkKSession(ksession2, "rule2", "rule3");
  }
  @Test
  @Ignore
  public void testScannerOnPomProject() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFactory kf = KieFactory.Factory.get();
    GAV gav1 = kf.newGav("org.kie", "scanner-test", "1.0");
    GAV gav2 = kf.newGav("org.kie", "scanner-test", "2.0");

    MavenRepository repository = getMavenRepository();
    repository.deployPomArtifact("org.kie", "scanner-master-test", "1.0", createMasterKPom());

    resetFileManager();

    InternalKieModule kJar1 = createKieJarWithClass(ks, kf, gav1, 2, 7);
    repository.deployArtifact(gav1, kJar1, createKPom(gav1));

    KieContainer kieContainer =
        ks.getKieContainer(kf.newGav("org.kie", "scanner-master-test", "1.0"));
    KieSession ksession = kieContainer.getKieSession("KSession1");
    checkKSession(ksession, 14);

    KieScanner scanner = ks.newKieScanner(kieContainer);

    InternalKieModule kJar2 = createKieJarWithClass(ks, kf, gav2, 3, 5);
    repository.deployArtifact(gav2, kJar2, createKPom(gav1));

    scanner.scanNow();

    KieSession ksession2 = kieContainer.getKieSession("KSession1");
    checkKSession(ksession2, 15);
  }
  @Test
  @Ignore
  public void testLoadKieJarFromMavenRepo() throws Exception {
    // This test depends from the former one (UGLY!) and must be run immediately after it
    KieServices ks = KieServices.Factory.get();
    KieFactory kf = KieFactory.Factory.get();

    KieContainer kieContainer =
        ks.getKieContainer(kf.newGav("org.kie", "scanner-test", "1.0-SNAPSHOT"));

    KieSession ksession2 = kieContainer.getKieSession("KSession1");
    checkKSession(ksession2, 15);
  }
  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();
  }
  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();
  }