use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithModuleOverride.
@Test
public void testIncrementalCompilationWithModuleOverride() {
final String drl1 = "package org.test.compiler; " + "global java.util.List list; " + "rule A when $s : String() then System.out.println( 'AAA' + $s ); list.add( 'A' + $s ); end " + "";
final String drl2 = "package totally.unrelated.pack; " + "global java.util.List list; " + "rule B when $s : String() then System.out.println( 'BBB' + $s ); list.add( 'B' + $s ); end " + "";
final String drl3 = "package totally.unrelated.pack; " + "global java.util.List list; " + "rule C when $s : String() then System.out.println( 'CCC' + $s ); list.add( 'C' + $s ); end " + "";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
final ReleaseId id = ks.newReleaseId("org.test", "foo", "1.0-SNAPSHOT");
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
kfs.generateAndWritePomXML(id);
kfs.write(ks.getResources().newReaderResource(new StringReader(drl1)).setResourceType(ResourceType.DRL).setSourcePath("drl1.drl"));
kieBuilder.buildAll(DrlProject.class);
final KieContainer kc = ks.newKieContainer(id);
final KieSession ksession = kc.newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
ksession.insert("X");
ksession.fireAllRules();
assertTrue(list.contains("AX"));
final KieFileSystem kfs2 = ks.newKieFileSystem();
final KieBuilder kieBuilder2 = ks.newKieBuilder(kfs2);
kfs2.generateAndWritePomXML(id);
kfs2.write(ks.getResources().newReaderResource(new StringReader(drl2)).setResourceType(ResourceType.DRL).setSourcePath("drla.drl"));
kieBuilder2.buildAll(DrlProject.class);
final KieContainer kc2 = ks.newKieContainer(id);
final KieSession ksession2 = kc2.newKieSession();
ksession2.setGlobal("list", list);
ksession2.insert("X");
ksession2.fireAllRules();
kfs2.write(ks.getResources().newReaderResource(new StringReader(drl3)).setResourceType(ResourceType.DRL).setSourcePath("drlb.drl"));
final IncrementalResults results = ((InternalKieBuilder) kieBuilder2).incrementalBuild();
assertEquals(0, results.getAddedMessages().size());
kc2.updateToVersion(id);
ksession2.fireAllRules();
assertEquals(Arrays.asList("AX", "BX", "CX"), list);
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class MessageImplTests method testMessageWithIncrementalBuild.
@Test
public void testMessageWithIncrementalBuild() throws Exception {
// Some suitably duff DSL to generate errors
String dsl1 = "bananna\n";
// Some suitably valid DRL
String drl1 = "import org.drools.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
// Some suitably valid DRL
String drl2 = "rule R2\n" + "when\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl1).write("src/main/resources/drl.dslr", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results fullBuildResults = kieBuilder.getResults();
assertEquals(3, fullBuildResults.getMessages().size());
kfs.write("src/main/resources/r2.drl", drl2);
IncrementalResults incrementalBuildResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, incrementalBuildResults.getAddedMessages().size());
assertEquals(0, incrementalBuildResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class MultipleModelTest method testIncrementalBuilding.
@Test
public void testIncrementalBuilding() throws Exception {
ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("org.test", "test", "1.0.0-SNAPSHOT");
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieBuilder kb = ks.newKieBuilder(kfs);
kfs.generateAndWritePomXML(releaseId1);
kfs.write(ResourceFactory.newClassPathResource(source1).setResourceType(ResourceType.PMML));
kb.buildAll();
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession kSession = kc.newKieSession();
setKbase(kSession.getKieBase());
kSession.fireAllRules();
kfs.write(ResourceFactory.newClassPathResource(source2).setResourceType(ResourceType.PMML));
IncrementalResults results = ((InternalKieBuilder) kb).incrementalBuild();
kc.updateToVersion(releaseId1);
kSession.fireAllRules();
assertEquals(1, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
assertEquals(9, kSession.getObjects(new ClassObjectFilter(kSession.getKieBase().getFactType(packageName, "Synapse").getFactClass())).size());
kSession.dispose();
checkGeneratedRules();
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class RuleTemplateModelIncrementalCompilationTests method testRuleTemplateIncrementalCompilationAddValidUpdateWithInvalid.
@Test
public void testRuleTemplateIncrementalCompilationAddValidUpdateWithInvalid() throws Exception {
// DROOLS-360
// Valid
// package org.mortgages;
// rule "t1_0"
// when
// Applicant( age == 22 )
// 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" + " </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>";
// Smurf is unknown
// package org.mortgages;
// rule "t1_0"
// when
// Applicant( age == 22 )
// Smurf()
// 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" + " <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>";
KieServices ks = KieServices.Factory.get();
// Add valid definition
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.template", drl1_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
List<Message> messages = kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR);
assertEquals(0, messages.size());
// Update with invalid definition - expect 1 "added" error message
kfs.write("src/main/resources/r1.template", drl1_2);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.template").build();
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults 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());
}
Aggregations