use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieRepositoryScannerTest method testKScannerWithExclusion.
@Test
@Ignore("avoid use external dependency")
public void testKScannerWithExclusion() throws Exception {
String pom = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd\">\n" + " <modelVersion>4.0.0</modelVersion>\n" + "\n" + " <groupId>org.kie</groupId>\n" + " <artifactId>test-with-exc</artifactId>\n" + " <version>1.0-SNAPSHOT</version>\n" + " \n" + " <dependencies>\n" + " <dependency>\n" + " <groupId>io.swagger</groupId>\n" + " <artifactId>swagger-jaxrs</artifactId>\n" + " <version>1.5.0</version>\n" + " <exclusions>\n" + " <exclusion>\n" + " <groupId>com.fasterxml.jackson.jaxrs</groupId>\n" + " <artifactId>*</artifactId>\n" + " </exclusion>\n" + " </exclusions>\n" + " </dependency>\n" + " </dependencies>\n" + "</project>";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseIdWithExc = ks.newReleaseId("org.kie", "test-with-exc", "1.0-SNAPSHOT");
InternalKieModule kJar = createKieJarWithPom(ks, releaseIdWithExc, false, "rule1", pom);
KieContainer kieContainer = ks.newKieContainer(releaseIdWithExc);
try {
Class.forName("com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider", true, kieContainer.getClassLoader());
fail("the excluded class shouldn't be present");
} catch (ClassNotFoundException e) {
}
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieRepositoryScannerTest method testKScannerWithDependencies.
@Test
@Ignore("used only for check performances")
public void testKScannerWithDependencies() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseIdNoDep = ks.newReleaseId("org.kie", "test-no-dep", "1.0-SNAPSHOT");
ReleaseId releaseIdWithDep = ks.newReleaseId("org.kie", "test-with-dep", "1.0-SNAPSHOT");
long start = System.nanoTime();
InternalKieModule kJar1 = createKieJar(ks, releaseIdNoDep, false, "rule1");
KieContainer kieContainer1 = ks.newKieContainer(releaseIdNoDep);
System.out.println("done in " + (System.nanoTime() - start));
ReleaseId dep1 = ks.newReleaseId("org.slf4j", "slf4j-api", "1.7.2");
ReleaseId dep2 = ks.newReleaseId("com.google.gwt", "gwt-user", "2.7.0");
ReleaseId dep3 = ks.newReleaseId("org.hibernate", "hibernate-validator", "4.1.0.Final");
start = System.nanoTime();
InternalKieModule kJar2 = createKieJarWithDependencies(ks, releaseIdWithDep, false, "rule1", dep1, dep2, dep3);
KieContainer kieContainer2 = ks.newKieContainer(releaseIdWithDep);
System.out.println("done in " + (System.nanoTime() - start));
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieRepositoryScannerTest method testKScannerWithGDRL.
@Test
public void testKScannerWithGDRL() throws Exception {
// BZ-1310261
String rule1 = "import java.util.List;\n" + "rule R when\n" + " $s : String()\n" + "then\n" + " list.add(\"Hello \" + $s);\n" + "end";
String rule2 = "import java.util.List;\n" + "rule R when\n" + " $s : String()\n" + "then\n" + " list.add(\"Hi \" + $s);\n" + "end";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJarWithGDRL(ks, releaseId, rule1);
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieMavenRepository repository = getKieMavenRepository();
repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
// create a ksesion and check it works as expected
KieSession ksession = kieContainer.newKieSession("KSession1");
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert("Mario");
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Hello Mario", list.get(0));
list.clear();
ksession.dispose();
// create a new kjar
InternalKieModule kJar2 = createKieJarWithGDRL(ks, releaseId, rule2);
// deploy it on maven
repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
// 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
// create a ksesion and check it works as expected
ksession = kieContainer.newKieSession("KSession1");
list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert("Mario");
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Hi Mario", list.get(0));
list.clear();
ksession.dispose();
ks.getRepository().removeKieModule(releaseId);
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieRepositoryScannerTest method testScanIncludedAndIncludingDependency.
@Test
@Ignore
public void testScanIncludedAndIncludingDependency() throws Exception {
KieMavenRepository repository = getKieMavenRepository();
KieServices ks = KieServices.Factory.get();
ReleaseId containerReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-container", "1.0.0-SNAPSHOT");
ReleaseId includedReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-project", "1.0.0-SNAPSHOT");
InternalKieModule kJar1 = createKieJar(ks, includedReleaseId, "rule1");
repository.installArtifact(includedReleaseId, kJar1, createKPom(fileManager, includedReleaseId));
resetFileManager();
InternalKieModule containerKJar = createIncludingKJar(containerReleaseId, includedReleaseId, "ruleX");
repository.installArtifact(containerReleaseId, containerKJar, createKPom(fileManager, containerReleaseId, includedReleaseId));
KieContainer kieContainer = ks.newKieContainer(containerReleaseId);
KieSession ksession = kieContainer.newKieSession("KSession2");
checkKSession(ksession, "rule1", "ruleX");
resetFileManager();
KieScanner scanner = ks.newKieScanner(kieContainer);
InternalKieModule kJar2 = createKieJar(ks, includedReleaseId, "rule2");
repository.installArtifact(includedReleaseId, kJar2, createKPom(fileManager, includedReleaseId));
resetFileManager();
InternalKieModule containerKJar2 = createIncludingKJar(containerReleaseId, includedReleaseId, "ruleY");
repository.installArtifact(containerReleaseId, containerKJar2, createKPom(fileManager, containerReleaseId, includedReleaseId));
resetFileManager();
scanner.scanNow();
KieSession ksession2 = kieContainer.newKieSession("KSession2");
checkKSession(ksession2, "rule2", "ruleY");
ks.getRepository().removeKieModule(containerReleaseId);
ks.getRepository().removeKieModule(includedReleaseId);
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieScannerIncrementalCompilationTest method checkIncrementalCompilation.
private void checkIncrementalCompilation(boolean useJavaInDrl) throws IOException {
KieServices ks = KieServices.Factory.get();
KieMavenRepository repository = getKieMavenRepository();
InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId, FIRST_VALUE, useJavaInDrl);
repository.installArtifact(releaseId, kJar1, createKPom(releaseId));
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieScanner scanner = ks.newKieScanner(kieContainer);
checkValue(kieContainer, FIRST_VALUE);
InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId, SECOND_VALUE, useJavaInDrl);
repository.installArtifact(releaseId, kJar2, createKPom(releaseId));
scanner.scanNow();
checkValue(kieContainer, SECOND_VALUE);
ks.getRepository().removeKieModule(releaseId);
}
Aggregations