Search in sources :

Example 31 with Resource

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);
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Resource(org.kie.api.io.Resource) Test(org.junit.Test)

Example 32 with Resource

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");
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Resource(org.kie.api.io.Resource) Test(org.junit.Test)

Example 33 with Resource

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));
}
Also used : Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 34 with Resource

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());
}
Also used : Resource(org.kie.api.io.Resource) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 35 with Resource

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;
}
Also used : Element(org.w3c.dom.Element) UrlResource(org.drools.core.io.impl.UrlResource) InternalResource(org.drools.core.io.internal.InternalResource) Resource(org.kie.api.io.Resource) ClassPathResource(org.drools.core.io.impl.ClassPathResource) KnowledgeResource(org.drools.core.io.impl.KnowledgeResource) Collection(java.util.Collection)

Aggregations

Resource (org.kie.api.io.Resource)162 Test (org.junit.Test)100 KieSession (org.kie.api.runtime.KieSession)50 KieServices (org.kie.api.KieServices)43 KieBase (org.kie.api.KieBase)42 ArrayList (java.util.ArrayList)30 KieContainer (org.kie.api.runtime.KieContainer)27 StringReader (java.io.StringReader)23 ReleaseId (org.kie.api.builder.ReleaseId)23 KieBuilder (org.kie.api.builder.KieBuilder)20 KieModule (org.kie.api.builder.KieModule)20 KieFileSystem (org.kie.api.builder.KieFileSystem)19 ClassPathResource (org.drools.core.io.impl.ClassPathResource)18 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)17 FactType (org.kie.api.definition.type.FactType)17 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)16 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)14 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)14 IOException (java.io.IOException)13 PMMLResource (org.drools.compiler.compiler.PMMLResource)11