use of org.drools.core.common.NamedEntryPoint in project drools by kiegroup.
the class DefeasibilityTest method testDefeaterPositiveVsNegative.
@Test(timeout = 10000)
public void testDefeaterPositiveVsNegative() {
KieSession kSession = getSession("org/drools/compiler/beliefsystem/defeasible/defeatersPosNeg.drl");
ArrayList list = new ArrayList();
kSession.setGlobal("list", list);
kSession.fireAllRules();
TruthMaintenanceSystem tms = ((NamedEntryPoint) kSession.getEntryPoint("DEFAULT")).getTruthMaintenanceSystem();
FactType Xtype = kSession.getKieBase().getFactType("org.drools.defeasible", "X");
ObjectHashMap keys = tms.getEqualityKeyMap();
Iterator iter = keys.iterator();
ObjectHashMap.ObjectEntry entry;
while ((entry = (ObjectHashMap.ObjectEntry) iter.next()) != null) {
EqualityKey key = (EqualityKey) entry.getValue();
Object fact = key.getFactHandle().getObject();
Class factClass = fact.getClass();
if (factClass == Xtype.getFactClass()) {
Integer val = (Integer) Xtype.get(fact, "id");
switch(val) {
case -1:
checkStatus(key, 2, DefeasibilityStatus.UNDECIDABLY);
break;
case 3:
checkStatus(key, 1, DefeasibilityStatus.DEFEATEDLY);
break;
case -35:
checkStatus(key, 3, DefeasibilityStatus.UNDECIDABLY);
break;
case 44:
checkStatus(key, 2, DefeasibilityStatus.DEFEASIBLY);
break;
default:
fail("Unrecognized fact");
}
} else {
fail("Unrecognized object has been logically justified : " + factClass);
}
}
assertEquals(1, list.size());
assertTrue(list.contains(-44));
assertTrue(!list.contains(-35));
assertEquals(2, kSession.getFactCount());
assertEquals(1, getNegativeObjects(kSession).size());
}
use of org.drools.core.common.NamedEntryPoint in project drools by kiegroup.
the class ReteooWorkingMemoryTest method testBasicWorkingMemoryActions.
/*
* @see JBRULES-356
*/
@Test
@Ignore
public void testBasicWorkingMemoryActions() {
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final TruthMaintenanceSystem tms = ((NamedEntryPoint) ksession.getWorkingMemoryEntryPoint(EntryPointId.DEFAULT.getEntryPointId())).getTruthMaintenanceSystem();
final String string = "test";
FactHandle fd = ksession.insert(string);
FactHandle fz = ksession.getTruthMaintenanceSystem().insert(string, null, null, new MockActivation());
assertEquals(1, tms.getEqualityKeyMap().size());
EqualityKey key = tms.get(string);
assertSame(fz, key.getFactHandle());
assertEquals(2, key.size());
ksession.update(fd, string);
assertEquals(1, tms.getEqualityKeyMap().size());
key = tms.get(string);
assertSame(fz, key.getFactHandle());
assertEquals(2, key.size());
ksession.retract(fd);
assertEquals(1, tms.getEqualityKeyMap().size());
key = tms.get(string);
fd = ksession.insert(string);
assertEquals(1, tms.getEqualityKeyMap().size());
assertEquals(1, tms.getEqualityKeyMap().size());
key = tms.get(string);
assertSame(fd, key.getFactHandle());
assertEquals(1, key.size());
}
use of org.drools.core.common.NamedEntryPoint in project drools by kiegroup.
the class TraitTest method testAlphaNodeSharing.
@Test
public void testAlphaNodeSharing() {
String drl = "package test; " + "import " + Entity.class.getName() + " " + "declare trait Person\n" + " name : String\n" + "end\n" + "rule Init " + "when " + "then " + " don( new Entity(), Person.class ); " + "end\n" + "rule One when" + " $core: Entity( this isA Person ) " + "then " + "end " + "rule Two when" + " $core: Entity( this isA Person ) " + "then " + "end " + "\n";
final KieBase kbase = getKieBaseFromString(drl);
TraitFactory.setMode(mode, kbase);
KieSession kSession = kbase.newKieSession();
assertEquals(3, kSession.fireAllRules());
NamedEntryPoint nep = ((NamedEntryPoint) kSession.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId()));
ObjectTypeNode otn = nep.getEntryPointNode().getObjectTypeNodes().get(new ClassObjectType(Entity.class));
assertNotNull(otn);
assertEquals(1, otn.getObjectSinkPropagator().getSinks().length);
}
use of org.drools.core.common.NamedEntryPoint in project drools by kiegroup.
the class FactHandleMarshallingTest method createEventFactHandle.
private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
// EntryPointNode
Rete rete = kBase.getRete();
NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, (ObjectSource) rete, EntryPointId.DEFAULT);
WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
EventFactHandle factHandle = new EventFactHandle(1, (Object) new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
return factHandle;
}
use of org.drools.core.common.NamedEntryPoint in project drools by kiegroup.
the class TruthMaintenanceTest method testLogicalInsertionsWithModify.
@Test(timeout = 10000)
public // @Ignore("in Java 8, the byte[] generated by serialization are not the same and requires investigation")
void testLogicalInsertionsWithModify() throws Exception {
KieBase kbase = loadKnowledgeBase("test_LogicalInsertionsWithUpdate.drl");
KieSession ksession = kbase.newKieSession();
final Person p = new Person("person");
p.setAge(2);
FactHandle h = ksession.insert(p);
assertEquals(1, ksession.getObjects().size());
ksession.fireAllRules();
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, false);
assertEquals(2, ksession.getObjects().size());
Collection l = ksession.getObjects(new ClassObjectFilter(CheeseEqual.class));
assertEquals(1, l.size());
assertEquals(2, ((CheeseEqual) l.iterator().next()).getPrice());
h = getFactHandle(h, ksession);
ksession.retract(h);
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, false);
assertEquals(0, ksession.getObjects().size());
TruthMaintenanceSystem tms = ((NamedEntryPoint) ksession.getEntryPoint(EntryPointId.DEFAULT.getEntryPointId())).getTruthMaintenanceSystem();
final java.lang.reflect.Field field = tms.getClass().getDeclaredField("equalityKeyMap");
field.setAccessible(true);
final ObjectHashMap m = (ObjectHashMap) field.get(tms);
field.setAccessible(false);
assertEquals("assertMap should be empty", 0, m.size());
}
Aggregations