Search in sources :

Example 11 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class EmptyHeaderTest method testEmptyConditionInXLS.

@Test(expected = DecisionTableParseException.class)
public void testEmptyConditionInXLS() {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("emptyCondition.xls", getClass()), ResourceType.DTABLE, dtconf);
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Test(org.junit.Test)

Example 12 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class EmptyHeaderTest method testEmptyActionInCSV.

@Test(expected = DecisionTableParseException.class)
public void testEmptyActionInCSV() {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.CSV);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("emptyAction.csv", getClass()), ResourceType.DTABLE, dtconf);
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Test(org.junit.Test)

Example 13 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class FixedPatternTest method testFixedPattern.

@Test
public void testFixedPattern() throws FileNotFoundException {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("fixedPattern.xls", getClass()), ResourceType.DTABLE, dtconf);
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = kbase.newKieSession();
    List<Long> list = new ArrayList<Long>();
    ksession.setGlobal("list", list);
    ksession.insert(1L);
    ksession.insert(2);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals(1L, (long) list.get(0));
    ksession.dispose();
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 14 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class SpreadsheetCompilerUnitTest method readKnowledgeBase.

private KieBase readKnowledgeBase(String resource) throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    DecisionTableConfiguration config = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    config.setInputType(DecisionTableInputType.XLS);
    kbuilder.add(ResourceFactory.newClassPathResource(resource, getClass()), ResourceType.DTABLE, config);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (errors.size() > 0) {
        for (KnowledgeBuilderError error : errors) {
            System.err.println(error);
        }
        throw new IllegalArgumentException("Could not parse knowledge.");
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    return kbase;
}
Also used : KnowledgeBuilderError(org.kie.internal.builder.KnowledgeBuilderError) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase)

Example 15 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class SpreadsheetIntegrationExampleTest method testNamedWorksheet.

@Test
public void testNamedWorksheet() throws Exception {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);
    dtconf.setWorksheetName("Tables_2");
    Resource dt = ResourceFactory.newClassPathResource("/data/IntegrationExampleTest.xls", getClass()).setConfiguration(dtconf);
    KieSession ksession = getKieSession(dt);
    // ASSERT AND FIRE
    ksession.insert(new Cheese("cheddar", 42));
    ksession.insert(new Person("michael", "stilton", 25));
    final List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("Young man cheddar", list.get(0));
}
Also used : DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Resource(org.kie.api.io.Resource) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

DecisionTableConfiguration (org.kie.internal.builder.DecisionTableConfiguration)17 Test (org.junit.Test)10 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 ArrayList (java.util.ArrayList)5 Resource (org.kie.api.io.Resource)5 KieSession (org.kie.api.runtime.KieSession)5 DecisionTableConfigurationImpl (org.drools.core.builder.conf.impl.DecisionTableConfigurationImpl)3 Command (org.kie.api.command.Command)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Driver (org.acme.insurance.Driver)1 Policy (org.acme.insurance.Policy)1 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)1 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 ResourceConfigurationImpl (org.drools.core.builder.conf.impl.ResourceConfigurationImpl)1 UrlResource (org.drools.core.io.impl.UrlResource)1