Search in sources :

Example 6 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TypeDeclarationTest method testTypeDeclarationWithInnerClasses.

@Test
public void testTypeDeclarationWithInnerClasses() {
    // DROOLS-150
    String str = "";
    str += "package org.drools.compiler;\n" + "\n" + "import org.drools.compiler.compiler.TypeDeclarationTest.EventBar.*;\n" + "" + "declare Foo\n" + " @role( event )\n" + "end\n" + "" + "rule R when Foo() then end";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newByteArrayResource(str.getBytes()), ResourceType.DRL);
    System.err.println(kbuilder.getErrors());
    assertFalse(kbuilder.hasErrors());
    InternalKnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
    kBase.addPackages(kbuilder.getKnowledgePackages());
    KieSession knowledgeSession = kBase.newKieSession();
    FactHandle handle = knowledgeSession.insert(new EventBar.Foo());
    assertTrue(handle instanceof EventFactHandle);
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) FactHandle(org.kie.api.runtime.rule.FactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 7 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TypeDeclarationTest method testMultipleAnnotationDeclarations.

@Test
public void testMultipleAnnotationDeclarations() {
    String str1 = "";
    str1 += "package org.kie1 " + "" + "declare Foo \n" + "    name : String " + "    age : int " + "end ";
    String str2 = "";
    str2 += "package org.kie2 " + "" + "declare org.kie1.Foo " + "    @role(event) " + "end ";
    String str3 = "";
    str3 += "package org.kie3 " + "" + "declare org.kie1.Foo " + "    @propertyReactive " + "end ";
    String str4 = "" + "package org.kie4; " + "import org.kie1.Foo; " + "" + "rule Check " + "when " + " $f : Foo( name == 'bar' ) " + "then " + " modify( $f ) { setAge( 99 ); } " + "end ";
    KieHelper helper = new KieHelper();
    helper.addContent(str1, ResourceType.DRL);
    helper.addContent(str2, ResourceType.DRL);
    helper.addContent(str3, ResourceType.DRL);
    helper.addContent(str4, ResourceType.DRL);
    List<Message> msg = helper.verify().getMessages(Message.Level.ERROR);
    System.out.println(msg);
    assertEquals(0, msg.size());
    KieBase kieBase = helper.build();
    FactType type = kieBase.getFactType("org.kie1", "Foo");
    assertEquals(2, type.getFields().size());
    Object foo = null;
    try {
        foo = type.newInstance();
        type.set(foo, "name", "bar");
        assertEquals("bar", type.get(foo, "name"));
    } catch (InstantiationException e) {
        fail(e.getMessage());
    } catch (IllegalAccessException e) {
        fail(e.getMessage());
    }
    KieSession session = kieBase.newKieSession();
    FactHandle handle = session.insert(foo);
    int n = session.fireAllRules(5);
    assertTrue(handle instanceof EventFactHandle);
    assertEquals(1, n);
    assertEquals(99, type.get(foo, "age"));
}
Also used : Message(org.kie.api.builder.Message) FactHandle(org.kie.api.runtime.rule.FactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) KieHelper(org.kie.internal.utils.KieHelper) FactType(org.kie.api.definition.type.FactType) KieBase(org.kie.api.KieBase) EventFactHandle(org.drools.core.common.EventFactHandle) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 8 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class DroolsAbstractPMMLTest method reportWMObjects.

public String reportWMObjects(KieSession session) {
    PriorityQueue<String> queue = new PriorityQueue<String>();
    for (FactHandle fh : session.getFactHandles()) {
        Object o;
        if (fh instanceof EventFactHandle) {
            EventFactHandle efh = (EventFactHandle) fh;
            queue.add("\t " + efh.getStartTimestamp() + "\t" + efh.getObject().toString() + "\n");
        } else {
            o = ((DefaultFactHandle) fh).getObject();
            queue.add("\t " + o.toString() + " >> " + System.identityHashCode(o.getClass()) + "\n");
        }
    }
    String ans = " ---------------- WM " + session.getObjects().size() + " --------------\n";
    while (!queue.isEmpty()) ans += queue.poll();
    ans += " ---------------- END WM -----------\n";
    return ans;
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) PriorityQueue(java.util.PriorityQueue)

Example 9 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class ConstrainedDataDictionaryTest method testProperties.

@Test
public void testProperties() throws Exception {
    getKSession().getEntryPoint("in_Vallued").insert(1);
    getKSession().getEntryPoint("in_Intervalled").insert(8.3);
    getKSession().getEntryPoint("in_Cat").insert("aa");
    getKSession().getEntryPoint("in_Sort").insert(1);
    getKSession().fireAllRules();
    Collection<EventFactHandle> fact1 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Vallued").getFactClass()));
    assertEquals(1, fact1.size());
    // assertEquals(true, getKbase().getFactType(packageName, "Vallued").get(fact1.iterator().next().getObject(), "continuous"));
    Collection<EventFactHandle> fact2 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Intervalled").getFactClass()));
    assertEquals(1, fact2.size());
    // assertEquals(true, getKbase().getFactType(packageName,"Intervalled").get(fact2.iterator().next().getObject(),"continuous"));
    Collection<EventFactHandle> fact3 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Cat").getFactClass()));
    assertEquals(1, fact3.size());
    // assertEquals(true, getKbase().getFactType(packageName,"Cat").get(fact3.iterator().next().getObject(),"categorical"));
    Collection<EventFactHandle> fact4 = getKSession().getFactHandles(new ClassObjectFilter(getKbase().getFactType(packageName, "Sort").getFactClass()));
    assertEquals(1, fact4.size());
    // assertEquals(true, getKbase().getFactType(packageName,"Sort").get(fact4.iterator().next().getObject(),"ordinal"));
    checkGeneratedRules();
}
Also used : ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) EventFactHandle(org.drools.core.common.EventFactHandle) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 10 with EventFactHandle

use of org.drools.core.common.EventFactHandle in project drools by kiegroup.

the class TemporalEvaluatorFactoryTest method testStartedBy.

@Test
public void testStartedBy() {
    registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
    EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle bar = new EventFactHandle(2, "bar", 1, 2, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle drool = new EventFactHandle(1, "drool", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    EventFactHandle mole = new EventFactHandle(1, "mole", 1, 1, 6, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
    final Object[][] data = { { foo, "startedby", bar, Boolean.TRUE }, { foo, "startedby", drool, Boolean.FALSE }, { foo, "startedby", mole, Boolean.FALSE }, { bar, "startedby", foo, Boolean.FALSE }, { foo, "not startedby", bar, Boolean.FALSE }, { foo, "not startedby", drool, Boolean.TRUE }, { foo, "not startedby", mole, Boolean.TRUE }, { bar, "not startedby", foo, Boolean.TRUE }, { foo, "startedby[1]", bar, Boolean.TRUE }, { foo, "startedby[1]", drool, Boolean.FALSE }, { foo, "startedby[1]", mole, Boolean.TRUE }, { bar, "startedby[1]", foo, Boolean.FALSE }, { foo, "not startedby[1]", bar, Boolean.FALSE }, { foo, "not startedby[1]", drool, Boolean.TRUE }, { foo, "not startedby[1]", mole, Boolean.FALSE }, { bar, "not startedby[1]", foo, Boolean.TRUE }, { foo, "startedby[3]", mole, Boolean.TRUE } };
    runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
Also used : DisconnectedWorkingMemoryEntryPoint(org.drools.core.common.DisconnectedWorkingMemoryEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) DuringEvaluatorDefinition(org.drools.core.base.evaluators.DuringEvaluatorDefinition) Test(org.junit.Test)

Aggregations

EventFactHandle (org.drools.core.common.EventFactHandle)86 Test (org.junit.Test)51 KieSession (org.kie.api.runtime.KieSession)23 KieBase (org.kie.api.KieBase)18 InternalFactHandle (org.drools.core.common.InternalFactHandle)16 DisconnectedWorkingMemoryEntryPoint (org.drools.core.common.DisconnectedWorkingMemoryEntryPoint)13 DisconnectedWorkingMemoryEntryPoint (org.drools.kiesession.entrypoints.DisconnectedWorkingMemoryEntryPoint)13 FactHandle (org.kie.api.runtime.rule.FactHandle)11 DuringEvaluatorDefinition (org.drools.core.base.evaluators.DuringEvaluatorDefinition)10 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)10 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)6 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)5 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)5 PropagationContext (org.drools.core.spi.PropagationContext)5 StockTick (org.drools.testcoverage.common.model.StockTick)5 EntryPointId (org.drools.core.rule.EntryPointId)4 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4