Search in sources :

Example 81 with KieBuilder

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();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) ModelMarker(org.kie.pmml.pmml_4_2.ModelMarker) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 82 with KieBuilder

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();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) ModelMarker(org.kie.pmml.pmml_4_2.ModelMarker) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 83 with KieBuilder

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 84 with KieBuilder

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;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint)

Example 85 with KieBuilder

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());
}
Also used : TypeMetaInfo(org.drools.core.rule.TypeMetaInfo) KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieModule(org.kie.api.builder.KieModule) KieModuleMetaData(org.kie.scanner.KieModuleMetaData) Test(org.junit.Test)

Aggregations

KieBuilder (org.kie.api.builder.KieBuilder)211 KieFileSystem (org.kie.api.builder.KieFileSystem)179 KieServices (org.kie.api.KieServices)145 Test (org.junit.Test)134 KieSession (org.kie.api.runtime.KieSession)59 KieModuleModel (org.kie.api.builder.model.KieModuleModel)57 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)54 KieContainer (org.kie.api.runtime.KieContainer)48 IncrementalResults (org.kie.internal.builder.IncrementalResults)35 ReleaseId (org.kie.api.builder.ReleaseId)34 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)33 Results (org.kie.api.builder.Results)32 Message (org.kie.api.builder.Message)30 KieBase (org.kie.api.KieBase)29 ArrayList (java.util.ArrayList)22 KieBaseModel (org.kie.api.builder.model.KieBaseModel)22 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)21 Resource (org.kie.api.io.Resource)19 FactType (org.kie.api.definition.type.FactType)16 KieModule (org.kie.api.builder.KieModule)12