Search in sources :

Example 1 with FirstClass

use of org.drools.compiler.FirstClass in project drools by kiegroup.

the class BetaTest method testDefaultBetaConstrains.

@Test
public void testDefaultBetaConstrains() throws Exception {
    final KieBase kbase = SerializationHelper.serializeObject(loadKnowledgeBase("test_DefaultBetaConstraint.drl"));
    final KieSession ksession = createKnowledgeSession(kbase);
    final List results = new ArrayList();
    ksession.setGlobal("results", results);
    final FirstClass first = new FirstClass("1", "2", "3", "4", "5");
    final FactHandle handle = ksession.insert(first);
    ksession.fireAllRules();
    assertEquals(1, results.size());
    assertEquals("NOT", results.get(0));
    ksession.insert(new SecondClass());
    ksession.update(handle, first);
    ksession.fireAllRules();
    assertEquals(2, results.size());
    assertEquals("NOT", results.get(1));
    ksession.update(handle, first);
    ksession.insert(new SecondClass(null, "2", "3", "4", "5"));
    ksession.fireAllRules();
    assertEquals(3, results.size());
    assertEquals("NOT", results.get(2));
    ksession.update(handle, first);
    ksession.insert(new SecondClass("1", null, "3", "4", "5"));
    ksession.fireAllRules();
    assertEquals(4, results.size());
    assertEquals("NOT", results.get(3));
    ksession.update(handle, first);
    ksession.insert(new SecondClass("1", "2", null, "4", "5"));
    ksession.fireAllRules();
    assertEquals(5, results.size());
    assertEquals("NOT", results.get(4));
    ksession.update(handle, first);
    ksession.insert(new SecondClass("1", "2", "3", null, "5"));
    ksession.fireAllRules();
    assertEquals(6, results.size());
    assertEquals("NOT", results.get(5));
    ksession.update(handle, first);
    ksession.insert(new SecondClass("1", "2", "3", "4", null));
    ksession.fireAllRules();
    assertEquals(7, results.size());
    assertEquals("NOT", results.get(6));
    ksession.insert(new SecondClass("1", "2", "3", "4", "5"));
    ksession.update(handle, first);
    ksession.fireAllRules();
    assertEquals(8, results.size());
    assertEquals("EQUALS", results.get(7));
}
Also used : FirstClass(org.drools.compiler.FirstClass) FactHandle(org.kie.api.runtime.rule.FactHandle) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) SecondClass(org.drools.compiler.SecondClass) KieSession(org.kie.api.runtime.KieSession) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with FirstClass

use of org.drools.compiler.FirstClass in project drools by kiegroup.

the class ImportsTest method testImportColision.

@Test
public void testImportColision() throws Exception {
    final Collection<KiePackage> kpkgs1 = loadKnowledgePackages("nested1.drl");
    final Collection<KiePackage> kpkgs2 = loadKnowledgePackages("nested2.drl");
    final InternalKnowledgeBase kbase = (InternalKnowledgeBase) loadKnowledgeBase();
    kbase.addPackages(kpkgs1);
    kbase.addPackages(kpkgs2);
    final KieSession ksession = createKnowledgeSession(kbase);
    SerializationHelper.serializeObject(kbase);
    ksession.insert(new FirstClass());
    ksession.insert(new SecondClass());
    ksession.insert(new FirstClass.AlternativeKey());
    ksession.insert(new SecondClass.AlternativeKey());
    ksession.fireAllRules();
}
Also used : KiePackage(org.kie.api.definition.KiePackage) FirstClass(org.drools.compiler.FirstClass) SecondClass(org.drools.compiler.SecondClass) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Aggregations

FirstClass (org.drools.compiler.FirstClass)2 SecondClass (org.drools.compiler.SecondClass)2 Test (org.junit.Test)2 KieSession (org.kie.api.runtime.KieSession)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1 KieBase (org.kie.api.KieBase)1 KiePackage (org.kie.api.definition.KiePackage)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1