use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenEmptyWithoutError.
@Test
public void testIncrementalCompilationAddErrorThenEmptyWithoutError() throws Exception {
// BZ-1009369
// Invalid. Type "Smurf" is unknown
String drl1 = "Smurf";
// Valid
String drl2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
// Add file with error - expect 2 build messages
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add empty file - expect no "added" messages and no "removed" messages
kfs.write("src/main/resources/r2.drl", "");
IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
assertEquals(0, addResults1.getRemovedMessages().size());
// Update file with no errors - expect no "added" messages and no "removed" messages
kfs.write("src/main/resources/r2.drl", drl2);
IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults2.getAddedMessages().size());
assertEquals(0, addResults2.getRemovedMessages().size());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class CommonTestMethodBase method createJar.
public static byte[] createJar(KieServices ks, String kmoduleContent, Predicate<String> classFilter, ReleaseId releaseId, Resource... resources) {
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmoduleContent);
for (int i = 0; i < resources.length; i++) {
if (resources[i] != null) {
kfs.write(resources[i]);
}
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
((InternalKieBuilder) kieBuilder).buildAll(classFilter);
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 IncrementalCompilationTest method testIncrementalCompilationDuplicateXLSResources.
@Test
public void testIncrementalCompilationDuplicateXLSResources() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
InputStream in1 = null;
InputStream in2 = null;
try {
// Add XLS decision table
in1 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
kfs.write("src/main/resources/incrementalBuild1.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in1));
// Expect no errors
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add the same XLS decision table again as a different resource
in2 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
kfs.write("src/main/resources/incrementalBuild2.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in2));
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/incrementalBuild2.dtable.xls").build();
// Expect duplicate rule errors
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
// Check errors on a full build
List<Message> messages = ks.newKieBuilder(kfs).buildAll().getResults().getMessages();
assertFalse(messages.isEmpty());
} finally {
if (in1 != null) {
in1.close();
}
if (in2 != null) {
in2.close();
}
}
}
use of org.kie.internal.builder.InternalKieBuilder 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(2, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
assertEquals(11, kSession.getObjects(new ClassObjectFilter(kSession.getKieBase().getFactType(packageName, "Synapse").getFactClass())).size());
kSession.dispose();
checkGeneratedRules();
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class GuidedDTableParsingIntegrationTest method testGuidedDTableWithNoDSLIncrementalCompilation.
@Test
public void testGuidedDTableWithNoDSLIncrementalCompilation() {
// DROOLS-1544
String typeDrl = "package org.drools.test\n" + "declare LoanApplication\n" + " amount : int\n" + "end";
String brokenDrlGenerated = "<decision-table52>\n" + " <tableName>Pricing loans</tableName>\n" + " <rowNumberCol>\n" + " <hideColumn>false</hideColumn>\n" + " <width>-1</width>\n" + " </rowNumberCol>\n" + " <descriptionCol>\n" + " <hideColumn>false</hideColumn>\n" + " <width>-1</width>\n" + " </descriptionCol>\n" + " <metadataCols/>\n" + " <attributeCols/>\n" + " <conditionPatterns>\n" + " <Pattern52>\n" + " <factType>org.drools.test.LoanApplication</factType>\n" + " <boundName>application</boundName>\n" + " <isNegated>false</isNegated>\n" + " <conditions>\n" + " <condition-column52>\n" + " <typedDefaultValue>\n" + " <valueString></valueString>\n" + " <dataType>STRING</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </typedDefaultValue>\n" + " <hideColumn>false</hideColumn>\n" + " <width>-1</width>\n" + " <header>aa</header>\n" + " <constraintValueType>1</constraintValueType>\n" + " <factField>amount</factField>\n" + " <fieldType>Integer</fieldType>\n" + " <operator>==</operator>\n" + " <valueList>a,b</valueList>\n" + " <parameters/>\n" + " </condition-column52>\n" + " </conditions>\n" + " <window>\n" + " <parameters/>\n" + " </window>\n" + " <entryPointName></entryPointName>\n" + " </Pattern52>\n" + " </conditionPatterns>\n" + " <actionCols/>\n" + " <auditLog>\n" + " <filter class=\"org.drools.guvnor.client.modeldriven.dt52.auditlog.DecisionTableAuditLogFilter\">\n" + " <acceptedTypes>\n" + " <entry>\n" + " <string>INSERT_ROW</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>INSERT_COLUMN</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>DELETE_ROW</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>DELETE_COLUMN</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>UPDATE_COLUMN</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " </acceptedTypes>\n" + " </filter>\n" + " <entries/>\n" + " </auditLog>\n" + " <imports>\n" + " <imports/>\n" + " </imports>\n" + " <packageName>mortgages.mortgages</packageName>\n" + " <tableFormat>EXTENDED_ENTRY</tableFormat>\n" + " <hitPolicy>NONE</hitPolicy>\n" + " <data>\n" + " <list>\n" + " <value>\n" + " <valueNumeric class=\"int\">1</valueNumeric>\n" + " <valueString></valueString>\n" + " <dataType>NUMERIC_INTEGER</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </value>\n" + " <value>\n" + " <valueString></valueString>\n" + " <dataType>STRING</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </value>\n" + " <value>\n" + " <valueString>a</valueString>\n" + " <dataType>STRING</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </value>\n" + " </list>\n" + " </data>\n" + "</decision-table52>";
String correctDrlGenerated = "<decision-table52>\n" + " <tableName>Pricing loans</tableName>\n" + " <rowNumberCol>\n" + " <hideColumn>false</hideColumn>\n" + " <width>-1</width>\n" + " </rowNumberCol>\n" + " <descriptionCol>\n" + " <hideColumn>false</hideColumn>\n" + " <width>-1</width>\n" + " </descriptionCol>\n" + " <metadataCols/>\n" + " <attributeCols/>\n" + " <conditionPatterns>\n" + " <Pattern52>\n" + " <factType>org.drools.test.LoanApplication</factType>\n" + " <boundName>application</boundName>\n" + " <isNegated>false</isNegated>\n" + " <conditions>\n" + " <condition-column52>\n" + " <typedDefaultValue>\n" + " <valueString></valueString>\n" + " <dataType>STRING</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </typedDefaultValue>\n" + " <hideColumn>false</hideColumn>\n" + " <width>-1</width>\n" + " <header>aa</header>\n" + " <constraintValueType>1</constraintValueType>\n" + " <factField>amount</factField>\n" + " <fieldType>Integer</fieldType>\n" + " <operator>==</operator>\n" + " <valueList>a,b</valueList>\n" + " <parameters/>\n" + " </condition-column52>\n" + " </conditions>\n" + " <window>\n" + " <parameters/>\n" + " </window>\n" + " <entryPointName></entryPointName>\n" + " </Pattern52>\n" + " </conditionPatterns>\n" + " <actionCols/>\n" + " <auditLog>\n" + " <filter class=\"org.drools.guvnor.client.modeldriven.dt52.auditlog.DecisionTableAuditLogFilter\">\n" + " <acceptedTypes>\n" + " <entry>\n" + " <string>INSERT_ROW</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>INSERT_COLUMN</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>DELETE_ROW</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>DELETE_COLUMN</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " <entry>\n" + " <string>UPDATE_COLUMN</string>\n" + " <boolean>false</boolean>\n" + " </entry>\n" + " </acceptedTypes>\n" + " </filter>\n" + " <entries/>\n" + " </auditLog>\n" + " <imports>\n" + " <imports/>\n" + " </imports>\n" + " <packageName>mortgages.mortgages</packageName>\n" + " <tableFormat>EXTENDED_ENTRY</tableFormat>\n" + " <hitPolicy>NONE</hitPolicy>\n" + " <data>\n" + " <list>\n" + " <value>\n" + " <valueNumeric class=\"int\">1</valueNumeric>\n" + " <valueString></valueString>\n" + " <dataType>NUMERIC_INTEGER</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </value>\n" + " <value>\n" + " <valueString></valueString>\n" + " <dataType>STRING</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </value>\n" + " <value>\n" + " <valueNumeric class=\"int\">1000</valueNumeric>\n" + " <dataType>NUMERIC_INTEGER</dataType>\n" + " <isOtherwise>false</isOtherwise>\n" + " </value>\n" + " </list>\n" + " </data>\n" + "</decision-table52>";
// Build the module with a broken DRL file
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/org/drools/test/personDrl.drl", typeDrl).write("src/main/resources/dt1.gdst", brokenDrlGenerated);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results buildResults = kieBuilder.getResults();
int errorsNr = buildResults.getMessages(Message.Level.ERROR).size();
Assert.assertTrue("Expected build failure", errorsNr > 0);
// Fix the DRL file
kfs.write("src/main/resources/dt1.gdst", correctDrlGenerated);
IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/dt1.gdst").build();
assertEquals(0, results.getAddedMessages().size());
assertEquals(errorsNr, results.getRemovedMessages().size());
}
Aggregations