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));
}
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());
}
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);
}
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());
}
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);
}
Aggregations