use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class DroolsAbstractPMMLTest method getModelSession.
protected KieSession getModelSession(String[] pmmlSources, boolean verbose) {
KieServices ks = KieServices.Factory.get();
KieRepository kr = ks.getRepository();
KieFileSystem kfs = ks.newKieFileSystem();
for (int j = 0; j < pmmlSources.length; j++) {
Resource res = ResourceFactory.newClassPathResource(pmmlSources[j]).setResourceType(ResourceType.PMML);
kfs.write(res);
}
KieModuleModel model = ks.newKieModuleModel();
model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).setDefault(true).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.STREAM);
kfs.writeKModuleXML(model.toXML());
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(Message.Level.ERROR)) {
throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
}
KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
KieBase kieBase = kContainer.getKieBase();
setKbase(kieBase);
return kieBase.newKieSession();
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class PMMLErrorTest method testNoErrorDuringGeneration.
@Test
public void testNoErrorDuringGeneration() {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(pmml.getBytes()).setResourceType(ResourceType.PMML).setSourcePath("pmml.pmml"));
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
assertEquals(0, kb.getResults().getMessages(Message.Level.ERROR).size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class PMMLErrorTest method testErrorDuringGeneration.
@Test
public void testErrorDuringGeneration() {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(pmlm.getBytes()).setResourceType(ResourceType.PMML).setSourcePath("pmlm.pmml"));
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
assertEquals(1, kb.getResults().getMessages(Message.Level.ERROR).size());
}
use of org.kie.api.builder.KieFileSystem 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.KieFileSystem 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());
}
Aggregations