Search in sources :

Example 26 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class PMMLUsageDemoTest method invokePmmlWithTraitMissing.

@Test
public void invokePmmlWithTraitMissing() {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ResourceFactory.newClassPathResource(pmmlSource).setResourceType(ResourceType.PMML));
    Results res = ks.newKieBuilder(kfs).buildAll().getResults();
    if (res.hasMessages(Message.Level.ERROR)) {
        System.out.println(res.getMessages(Message.Level.ERROR));
    }
    assertEquals(0, res.getMessages(Message.Level.ERROR).size());
    KieSession kSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    kSession.insert("trigger");
    kSession.fireAllRules();
    System.out.println(reportWMObjects(kSession));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) QueryResults(org.kie.api.runtime.rule.QueryResults) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 27 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class AdapterTest method testCustomInputAdapter.

@Test
public void testCustomInputAdapter() {
    String source = PMML4Helper.pmmlDefaultPackageName().replace(".", "/") + "/" + "mock_cold_adapter.xml";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ResourceFactory.newClassPathResource(source).setResourceType(ResourceType.PMML));
    Results res = ks.newKieBuilder(kfs).buildAll().getResults();
    if (res.hasMessages(Message.Level.ERROR)) {
        System.out.println(res.getMessages(Message.Level.ERROR));
    }
    assertEquals(0, res.getMessages(Message.Level.ERROR).size());
    KieBase kieBase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
    FactType ft = kieBase.getFactType("test", "MyAdapter");
    assertTrue(ft != null);
    assertTrue(ft.getFactClass().isInterface());
    FactType fto = kieBase.getFactType("test", "MyOutAdapter");
    assertTrue(fto != null);
    assertTrue(fto.getFactClass().isInterface());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) FactType(org.kie.api.definition.type.FactType) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 28 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class DrlxCompiler method createKieContainer.

private static KieContainer createKieContainer(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) {
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException(results.getMessages().toString());
    }
    return ks.newKieContainer(releaseId);
}
Also used : Results(org.kie.api.builder.Results) KieBuilder(org.kie.api.builder.KieBuilder)

Example 29 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class CompilationFailuresTest method testUseNotExistingEnum.

@Test
public void testUseNotExistingEnum() {
    String drl = "import " + NumberRestriction.class.getCanonicalName() + "\n" + "rule R when\n" + "    NumberRestriction( valueType == Field.INT || == Field.DOUBLE )\n" + "then\n" + "end\n";
    Results results = getCompilationResults(drl);
    assertFalse(results.getMessages(Message.Level.ERROR).isEmpty());
}
Also used : Results(org.kie.api.builder.Results) Test(org.junit.Test)

Example 30 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class ExternalObjectModelTest method testWithInitialScore.

@Test
public void testWithInitialScore() throws Exception {
    ScorecardCompiler scorecardCompiler2 = new ScorecardCompiler(EXTERNAL_OBJECT_MODEL);
    PMML pmmlDocument2 = null;
    String drl2 = null;
    if (scorecardCompiler2.compileFromExcel(PMMLDocumentTest.class.getResourceAsStream("/scoremodel_externalmodel.xls"), "scorecards_initialscore")) {
        pmmlDocument2 = scorecardCompiler2.getPMMLDocument();
        assertNotNull(pmmlDocument2);
        drl2 = scorecardCompiler2.getDRL();
        PMML4Compiler.dumpModel(pmmlDocument2, System.out);
    } else {
        fail("failed to parse scoremodel Excel.");
    }
    assertNotNull(pmmlDocument2);
    assertTrue(drl2 != null && !drl2.isEmpty());
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ks.getResources().newByteArrayResource(drl2.getBytes()).setSourcePath("test_scorecard_rules.drl").setResourceType(ResourceType.DRL));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    Results res = kieBuilder.buildAll().getResults();
    System.err.println(res.getMessages());
    KieContainer kieContainer = ks.newKieContainer(kieBuilder.getKieModule().getReleaseId());
    KieBase kbase = kieContainer.getKieBase();
    KieSession session = kbase.newKieSession();
    Applicant applicant = new Applicant();
    applicant.setAge(10);
    session.insert(applicant);
    // session.addEventListener(new DebugWorkingMemoryEventListener());
    session.fireAllRules();
    session.dispose();
    // occupation = 0, age = 30, validLicence -1, initialScore=100
    assertEquals(129.0, applicant.getTotalScore(), 0.0);
    session = kbase.newKieSession();
    applicant = new Applicant();
    applicant.setOccupation("SKYDIVER");
    applicant.setAge(0);
    session.insert(applicant);
    session.fireAllRules();
    session.dispose();
    // occupation = -10, age = +10, validLicense = -1, initialScore=100;
    assertEquals(99.0, applicant.getTotalScore(), 0.0);
    session = kbase.newKieSession();
    applicant = new Applicant();
    applicant.setResidenceState("AP");
    applicant.setOccupation("TEACHER");
    applicant.setAge(20);
    applicant.setValidLicense(true);
    session.insert(applicant);
    session.fireAllRules();
    session.dispose();
    // occupation = +10, age = +40, state = -10, validLicense = 1, initialScore=100
    assertEquals(141.0, applicant.getTotalScore(), 0.0);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieBase(org.kie.api.KieBase) PMML(org.dmg.pmml.pmml_4_2.descr.PMML) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder) Applicant(org.drools.scorecards.example.Applicant) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

Results (org.kie.api.builder.Results)92 Test (org.junit.Test)81 KieServices (org.kie.api.KieServices)72 KieFileSystem (org.kie.api.builder.KieFileSystem)60 KieContainer (org.kie.api.runtime.KieContainer)36 KieBuilder (org.kie.api.builder.KieBuilder)32 KieSession (org.kie.api.runtime.KieSession)25 IncrementalResults (org.kie.internal.builder.IncrementalResults)20 ReleaseId (org.kie.api.builder.ReleaseId)19 QueryResults (org.kie.api.runtime.rule.QueryResults)17 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)15 KieBase (org.kie.api.KieBase)14 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)11 KieHelper (org.kie.internal.utils.KieHelper)11 KieModuleModel (org.kie.api.builder.model.KieModuleModel)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7