use of org.kie.api.builder.KieBuilder 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.api.builder.KieBuilder in project drools by kiegroup.
the class MultipleModelTest method testCompositeBuilding.
@Test
public void testCompositeBuilding() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newClassPathResource(source1).setResourceType(ResourceType.PMML));
kfs.write(ResourceFactory.newClassPathResource(source2).setResourceType(ResourceType.PMML));
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
KieSession kSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
setKbase(kSession.getKieBase());
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.api.builder.KieBuilder 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());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieBuilderTest method checkKieSession.
private KieSession checkKieSession(Class<? extends KieBuilder.ProjectType> projectClass) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", createDrl("R1"));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
kieBuilder.buildAll(projectClass);
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
ksession.insert("Hello World");
int count = ksession.fireAllRules();
assertEquals(1, count);
return ksession;
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class JavaBeansEventRoleTest method testImportBean.
@Test
public void testImportBean() throws Exception {
String declaration = "package org.drools.compiler;\n" + "public class Bean {}";
String drl = "package some.other.package;\n" + "import org.drools.compiler.Bean;\n" + "declare Bean\n" + " @role(event)\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/java/org/drools/compiler/Bean.java", declaration).write("src/main/resources/bean1.drl", drl);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
final KieModule kieModule = kieBuilder.buildAll().getKieModule();
final KieModuleMetaData kieModuleMetaData = KieModuleMetaData.Factory.newKieModuleMetaData(kieModule);
final String packageName = "org.drools.compiler";
final String className = "Bean";
final Class clazz = kieModuleMetaData.getClass(packageName, className);
final TypeMetaInfo typeMetaInfo = kieModuleMetaData.getTypeMetaInfo(clazz);
assertTrue(typeMetaInfo.isEvent());
}
Aggregations