use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithMultipleKieBases.
@Test
public void checkIncrementalCompilationWithMultipleKieBases() throws Exception {
String rule = "package org.kie.scanner\n" + "rule R1 when\n" + "then\n" + "end\n";
String invalidRule = "package org.kie.scanner\n" + "rule R2 when\n" + // missing import
" Cheese()\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = createKieFileSystemWithTwoKBases(ks);
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages().size());
kfs.write("src/main/resources/org/kie/scanner/invalidRule.drl", invalidRule);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/invalidRule.drl").build();
assertEquals(2, addResults.getAddedMessages().size());
addResults.getAddedMessages().stream().map(m -> (MessageImpl) m).forEach(m -> assertNotNull(m.getKieBaseName()));
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithRuleFunctionRule.
@Test
public void checkIncrementalCompilationWithRuleFunctionRule() throws Exception {
String rule_1 = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + "end\n";
String rule_2 = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + " System.out.println(MyFunction());\n" + "end\n";
String function = "package org.kie.scanner\n" + "function int MyFunction() {\n" + " return 1;\n" + "}\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/org/kie/scanner/function.drl", function);
IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/function.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
assertEquals(0, addResults1.getRemovedMessages().size());
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule_2);
IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/rule.drl").build();
assertEquals(0, addResults2.getAddedMessages().size());
assertEquals(0, addResults2.getRemovedMessages().size());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleMavenTest method createKieJarWithProperties.
protected InternalKieModule createKieJarWithProperties(KieServices ks, ReleaseId releaseId, boolean isdefault, String droolsVersion, ReleaseId[] dependencies, String... rules) throws IOException {
KieFileSystem kfs = createKieFileSystemWithKProject(ks, isdefault);
kfs.writePomXML(generatePomXmlWithProperties(releaseId, droolsVersion, dependencies));
for (String rule : rules) {
String file = "org/test/" + rule + ".drl";
kfs.write("src/main/resources/KBase1/" + file, createDRL(rule));
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
return (InternalKieModule) kieBuilder.getKieModule();
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleMetaDataTest method testGetPackageNames.
@Test
public void testGetPackageNames() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/test.drl", "package org.test declare Bean end");
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);
assertFalse(kieModuleMetaData.getPackages().isEmpty());
assertTrue(kieModuleMetaData.getPackages().contains("org.test"));
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieModuleMetaDataTest method testKieMavenPluginEmptyProject.
@Test
public void testKieMavenPluginEmptyProject() {
// According to https://bugzilla.redhat.com/show_bug.cgi?id=1049674#c2 the below is the minimal POM required to use KieMavenPlugin.
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("pom.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + " <modelVersion>4.0.0</modelVersion>" + " <groupId>org.kie</groupId>" + " <artifactId>plugin-test</artifactId>" + " <version>1.0</version>" + " <packaging>kjar</packaging>" + " <build>" + " <plugins>" + " <plugin>" + " <groupId>org.kie</groupId>" + " <artifactId>kie-maven-plugin</artifactId>" + " <version>the-test-does-not-need-proper-version-here</version>" + " <extensions>true</extensions>" + " </plugin>" + " </plugins>" + " </build>" + "</project>");
kfs.write("/src/main/resources/META-INF/kmodule.xml", "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"/>");
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);
boolean fail = false;
for (final String packageName : kieModuleMetaData.getPackages()) {
for (final String className : kieModuleMetaData.getClasses(packageName)) {
try {
kieModuleMetaData.getClass(packageName, className);
} catch (Throwable e) {
fail = true;
System.out.println(e);
}
}
}
if (fail) {
fail("See console for details.");
}
}
Aggregations