use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class RuleTemplateModelIncrementalCompilationTests method testRuleTemplateIncrementalCompilationAddInvalidUpdateWithValid.
@Test
public void testRuleTemplateIncrementalCompilationAddInvalidUpdateWithValid() throws Exception {
// Smurf is unknown
// package org.mortgages;
// rule "t1_0"
// when
// Applicant( age == 22 )
// Smurf()
// then
// end
String drl1_1 = "<rule>\n" + " <name>t1</name>\n" + " <modelVersion>1.0</modelVersion>\n" + " <attributes/>\n" + " <metadataList/>\n" + " <lhs>\n" + " <fact>\n" + " <constraintList>\n" + " <constraints>\n" + " <fieldConstraint>\n" + " <value>$default</value>\n" + " <operator>==</operator>\n" + " <constraintValueType>7</constraintValueType>\n" + " <expression>\n" + " <parts/>\n" + " </expression>\n" + " <parameters/>\n" + " <factType>Applicant</factType>\n" + " <fieldName>age</fieldName>\n" + " <fieldType>Integer</fieldType>\n" + " </fieldConstraint>\n" + " </constraints>\n" + " </constraintList>\n" + " <factType>Applicant</factType>\n" + " <isNegated>false</isNegated>\n" + " <window>\n" + " <parameters/>\n" + " </window>\n" + " </fact>\n" + " <freeForm>\n" + " <text>Smurf()</text>\n" + " </freeForm>\n" + " </lhs>\n" + " <rhs/>\n" + " <imports>\n" + " <imports/>\n" + " </imports>\n" + " <packageName>org.drools.workbench.models.guided.template.backend</packageName>\n" + " <isNegated>false</isNegated>\n" + " <table>\n" + " <entry>\n" + " <string>__ID_KOL_NAME__</string>\n" + " <list>\n" + " <string>1</string>\n" + " </list>\n" + " </entry>\n" + " <entry>\n" + " <string>$default</string>\n" + " <list>\n" + " <string>22</string>\n" + " </list>\n" + " </entry>\n" + " </table>\n" + " <idCol>1</idCol>\n" + " <rowsCount>1</rowsCount>\n" + "</rule>";
// Valid
// package org.mortgages;
// rule "t1_0"
// when
// Applicant( age == 22 )
// then
// end
String drl1_2 = "<rule>\n" + " <name>t1</name>\n" + " <modelVersion>1.0</modelVersion>\n" + " <attributes/>\n" + " <metadataList/>\n" + " <lhs>\n" + " <fact>\n" + " <constraintList>\n" + " <constraints>\n" + " <fieldConstraint>\n" + " <value>$default</value>\n" + " <operator>==</operator>\n" + " <constraintValueType>7</constraintValueType>\n" + " <expression>\n" + " <parts/>\n" + " </expression>\n" + " <parameters/>\n" + " <factType>Applicant</factType>\n" + " <fieldName>age</fieldName>\n" + " <fieldType>Integer</fieldType>\n" + " </fieldConstraint>\n" + " </constraints>\n" + " </constraintList>\n" + " <factType>Applicant</factType>\n" + " <isNegated>false</isNegated>\n" + " <window>\n" + " <parameters/>\n" + " </window>\n" + " </fact>\n" + " </lhs>\n" + " <rhs/>\n" + " <imports>\n" + " <imports/>\n" + " </imports>\n" + " <packageName>org.drools.workbench.models.guided.template.backend</packageName>\n" + " <isNegated>false</isNegated>\n" + " <table>\n" + " <entry>\n" + " <string>__ID_KOL_NAME__</string>\n" + " <list>\n" + " <string>1</string>\n" + " </list>\n" + " </entry>\n" + " <entry>\n" + " <string>$default</string>\n" + " <list>\n" + " <string>22</string>\n" + " </list>\n" + " </entry>\n" + " </table>\n" + " <idCol>1</idCol>\n" + " <rowsCount>1</rowsCount>\n" + "</rule>";
KieServices ks = KieServices.Factory.get();
// Add invalid definition
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.template", drl1_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Update file with valid definition - expect 1 "removed" error message
kfs.write("src/main/resources/r1.template", drl1_2);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.template").build();
assertEquals(0, addResults.getAddedMessages().size());
assertEquals(1, addResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class KieHelper method createJar.
public static byte[] createJar(KieServices ks, ReleaseId releaseId, Resource... resources) {
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId);
for (int i = 0; i < resources.length; i++) {
if (resources[i] != null) {
kfs.write(resources[i]);
}
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
((InternalKieBuilder) kieBuilder).buildAll(o -> true);
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method testIncrementalCompilationFirstBuildHasErrors.
@Test
public void testIncrementalCompilationFirstBuildHasErrors() throws Exception {
KieServices ks = KieServices.Factory.get();
// Malformed POM - No Version information
ReleaseId releaseId = ks.newReleaseId("org.kie", "incremental-test-with-invalid pom", "");
KieFileSystem kfs = createKieFileSystemWithKProject(ks);
kfs.writePomXML(getPom(releaseId));
// Valid
String drl1 = "rule R1 when\n" + " $s : String()\n" + "then\n" + "end\n";
// Invalid
String drl2 = "rule R2 when\n" + " $s : Strin( )\n" + "then\n" + "end\n";
// Write Rule 1 - No DRL errors, but POM is in error
kfs.write("src/main/resources/KBase1/r1.drl", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add file with error - expect 1 "added" error message
kfs.write("src/main/resources/KBase1/r2.drl", drl2);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/KBase1/r2.drl").build();
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithFunctionThenRule.
@Test
public void checkIncrementalCompilationWithFunctionThenRule() throws Exception {
String rule = "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/function.drl", function);
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/rule.drl", rule);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/rule.drl").build();
assertEquals(0, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
}
Aggregations