use of org.kie.api.io.Resource in project drools by kiegroup.
the class DumpGeneratedDrlTest method testDTableWithNullSrcPathIsCorrectlyDumped.
@Test
public void testDTableWithNullSrcPathIsCorrectlyDumped() {
DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dtconf.setInputType(DecisionTableInputType.CSV);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Resource resource = ResourceFactory.newByteArrayResource(DUMMY_DTABLE_CSV_SOURCE.getBytes(IoUtils.UTF8_CHARSET));
kbuilder.add(resource, ResourceType.DTABLE, dtconf);
if (kbuilder.hasErrors()) {
Assert.fail("Unexpected Drools compilation errors: " + kbuilder.getErrors().toString());
}
assertGeneratedDrlExists(dumpDir, null);
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class DumpGeneratedDrlTest method testGeneratedDrlFromIsDumpedIfSpecified.
@Test
public void testGeneratedDrlFromIsDumpedIfSpecified() {
DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dtconf.setInputType(DecisionTableInputType.CSV);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Resource resource = ResourceFactory.newByteArrayResource(DUMMY_DTABLE_CSV_SOURCE.getBytes(IoUtils.UTF8_CHARSET));
resource.setSourcePath("some/source/path/dummy-dtable.csv");
kbuilder.add(resource, ResourceType.DTABLE, dtconf);
if (kbuilder.hasErrors()) {
Assert.fail("Unexpected Drools compilation errors: " + kbuilder.getErrors().toString());
}
assertGeneratedDrlExists(dumpDir, "some_source_path_dummy-dtable.csv.drl");
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class SpreadsheetIntegrationExampleTest method testExecuteUsingKieAPI.
@Test
public void testExecuteUsingKieAPI() throws Exception {
// get the resource
Resource dt = ResourceFactory.newClassPathResource("/data/IntegrationExampleTest.xls", getClass());
// create the builder
KieSession ksession = getKieSession(dt);
ksession.insert(new Cheese("stilton", 42));
ksession.insert(new Person("michael", "stilton", 42));
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Old man stilton", list.get(0));
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class SpreadsheetIntegrationExampleTest method testBooleanField.
@Test
public void testBooleanField() throws Exception {
Resource dt = ResourceFactory.newClassPathResource("/data/ShopRules.xls", getClass());
KieSession ksession = getKieSession(dt);
Person p = new Person("michael", "stilton", 42);
ksession.insert(p);
ksession.fireAllRules();
assertTrue(p.getCanBuyAlcohol());
}
use of org.kie.api.io.Resource in project drools by kiegroup.
the class ResourceHandler method end.
public Object end(String uri, String localName, ExtensibleXmlParser parser) throws SAXException {
final Element element = parser.endElementBuilder();
final Collection collection = (Collection) parser.getParent();
final Resource resource = (Resource) parser.getCurrent();
collection.add(resource);
return resource;
}
Aggregations