use of org.kie.api.builder.KieScanner 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.builder.KieScanner 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.builder.KieScanner 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);
}
use of org.kie.api.builder.KieScanner in project drools by kiegroup.
the class MavenDeployTest method testKScannerWithDeployUsingDistributionManagement.
@Test
public void testKScannerWithDeployUsingDistributionManagement() throws IOException {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy-dist", "1.0-SNAPSHOT");
Path m2Folder = Files.createTempDirectory("temp-m2-dist");
Path settingsXmlPath = generateSettingsXml(m2Folder);
String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
try {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
MavenSettings.reinitSettings();
InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
// create a ksesion and check it works as expected
KieSession ksession = kieContainer.newKieSession("KSession1");
checkKSession(ksession, "rule1", "rule2");
// create a new kjar
InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
// deploy it on maven
repository.deployArtifact(releaseId, kJar2, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
// 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.newKieSession("KSession1");
checkKSession(ksession2, "rule2", "rule3");
ks.getRepository().removeKieModule(releaseId);
} finally {
if (oldSettingsXmlPath == null) {
System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
} else {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
}
MavenSettings.reinitSettings();
}
}
use of org.kie.api.builder.KieScanner in project drools by kiegroup.
the class MavenDeployTest method testDeploy.
@Test
public void testDeploy() throws IOException {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy", "1.0-SNAPSHOT");
Path m2Folder = Files.createTempDirectory("temp-m2");
Path settingsXmlPath = generateSettingsXml(m2Folder);
String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
try {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
MavenSettings.reinitSettings();
InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieMavenRepository repository = getKieMavenRepository();
RemoteRepository remote = createRemoteRepository(m2Folder);
repository.deployArtifact(remote, releaseId, kJar1, createKPom(m2Folder, releaseId).toFile());
// create a ksesion and check it works as expected
KieSession ksession = kieContainer.newKieSession("KSession1");
checkKSession(ksession, "rule1", "rule2");
// create a new kjar
InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
// deploy it on maven
repository.deployArtifact(remote, releaseId, kJar2, createKPom(m2Folder, releaseId).toFile());
// 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.newKieSession("KSession1");
checkKSession(ksession2, "rule2", "rule3");
ks.getRepository().removeKieModule(releaseId);
} finally {
if (oldSettingsXmlPath == null) {
System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
} else {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
}
MavenSettings.reinitSettings();
}
}
Aggregations