Search in sources :

Example 51 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class DecisionTableTest method testCSVWithDateAttributes.

@Test
public void testCSVWithDateAttributes() {
    final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("sample_dates.csv", getClass(), DecisionTableInputType.CSV);
    testDecisionTableWithDateAttributes(decisionTable);
}
Also used : Resource(org.kie.api.io.Resource) Test(org.junit.Test)

Example 52 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class DecisionTableTest method testActivationGroup.

@Test
public void testActivationGroup() {
    final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("agenda-group.csv", getClass(), DecisionTableInputType.CSV);
    final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable);
    final KieSession ksession = kbase.newKieSession();
    final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
    ksession.addEventListener(listener);
    // only one rule from activation group may fire
    ksession.insert("activationGroup");
    ksession.fireAllRules();
    Assertions.assertThat(listener.isRuleFired("c1")).isFalse();
    Assertions.assertThat(listener.isRuleFired("c2")).isTrue();
    Assertions.assertThat(listener.isRuleFired("c3")).isFalse();
}
Also used : TrackingAgendaEventListener(org.drools.testcoverage.common.listener.TrackingAgendaEventListener) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 53 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class DecisionTableTest method testMultipleTableXLS.

@Test
public void testMultipleTableXLS() {
    final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("multiple_tables.xls", getClass(), DecisionTableInputType.XLS);
    final KieBase kbase = KieBaseUtil.getKieBaseFromResources(kieBaseTestConfiguration, decisionTable);
    Assertions.assertThat(2).isEqualTo(kbase.getKiePackages().size());
    final KieSession session = kbase.newKieSession();
    // testing person object from the first table
    final Person person = new Person("Paul");
    person.setId(1);
    Assertions.assertThat(person.getName()).isEqualTo("Paul");
    Assertions.assertThat(person.getId()).isEqualTo(1);
    // testing second person, he should be renamed by rules in the second
    // table
    final Person person2 = new Person("Helmut von Seireit");
    person2.setId(1000);
    Assertions.assertThat(person2.getName()).isEqualTo("Helmut von Seireit");
    Assertions.assertThat(person2.getId()).isEqualTo(1000);
    session.insert(person);
    session.insert(person2);
    session.fireAllRules();
    Assertions.assertThat(person.getName()).isEqualTo("Paul");
    Assertions.assertThat(person.getId()).isEqualTo(2);
    Assertions.assertThat(person2.getName()).isEqualTo("Wilhelm von Seireit");
    Assertions.assertThat(person2.getId()).isEqualTo(1000);
    session.dispose();
}
Also used : KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.testcoverage.common.model.Person) Test(org.junit.Test)

Example 54 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class DecisionTableTest method testSimpleCSV.

@Test
public void testSimpleCSV() {
    final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("sample.csv", getClass(), DecisionTableInputType.CSV);
    testSimpleDecisionTable(decisionTable);
}
Also used : Resource(org.kie.api.io.Resource) Test(org.junit.Test)

Example 55 with Resource

use of org.kie.api.io.Resource in project drools by kiegroup.

the class DecisionTableTest method testEmptyActionInCSV.

@Test(expected = DecisionTableParseException.class)
public void testEmptyActionInCSV() {
    final Resource decisionTable = ResourceUtil.getDecisionTableResourceFromClasspath("emptyAction.csv", getClass(), DecisionTableInputType.CSV);
    KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, decisionTable);
}
Also used : Resource(org.kie.api.io.Resource) Test(org.junit.Test)

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