Search in sources :

Example 11 with BuildContext

use of org.drools.core.reteoo.builder.BuildContext in project drools by kiegroup.

the class QueryElementNodeTest method setUp.

@Before
public void setUp() {
    this.kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    this.buildContext = new BuildContext(kBase);
    this.buildContext.setRule(new RuleImpl());
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    this.context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    this.workingMemory = new InstrumentedWorkingMemory(0, this.kBase);
}
Also used : PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Before(org.junit.Before)

Example 12 with BuildContext

use of org.drools.core.reteoo.builder.BuildContext in project drools by kiegroup.

the class ReteTest method testNotShadowed.

@Test
@Ignore
public void testNotShadowed() {
    Properties properties = new Properties();
    properties.setProperty("drools.shadowProxyExcludes", "org.drools.core.test.model.Cheese");
    RuleBaseConfiguration conf = new RuleBaseConfiguration(properties);
    InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(conf);
    buildContext = new BuildContext(kBase);
    final StatefulKnowledgeSessionImpl ksession = new StatefulKnowledgeSessionImpl(1L, kBase);
    // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
    final Rete rete = kBase.getRete();
    final EntryPointNode entryPoint = new EntryPointNode(0, rete, buildContext);
    entryPoint.attach(buildContext);
    final ObjectTypeNode objectTypeNode = new ObjectTypeNode(1, entryPoint, new ClassObjectType(Cheese.class), buildContext);
    objectTypeNode.attach(buildContext);
    final MockObjectSink sink1 = new MockObjectSink();
    objectTypeNode.addObjectSink(sink1);
    // There are no String ObjectTypeNodes, make sure its not propagated
    final Cheese cheese = new Cheese("brie", 15);
    final DefaultFactHandle h1 = new DefaultFactHandle(1, cheese);
    rete.assertObject(h1, pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null), ksession);
    ksession.fireAllRules();
    final Object[] results = (Object[]) sink1.getAsserted().get(0);
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) Cheese(org.drools.core.test.model.Cheese) Properties(java.util.Properties) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) BuildContext(org.drools.core.reteoo.builder.BuildContext) StatefulKnowledgeSessionImpl(org.drools.core.impl.StatefulKnowledgeSessionImpl) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with BuildContext

use of org.drools.core.reteoo.builder.BuildContext in project drools by kiegroup.

the class ReteTest method setUp.

@Before
public void setUp() throws Exception {
    this.kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    this.pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    this.buildContext = new BuildContext(kBase);
    this.entryPoint = buildContext.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next();
    ;
}
Also used : BuildContext(org.drools.core.reteoo.builder.BuildContext) Before(org.junit.Before)

Example 14 with BuildContext

use of org.drools.core.reteoo.builder.BuildContext in project drools by kiegroup.

the class RuleUnlinkingTest method setUp.

public void setUp(int type) {
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
    buildContext = new BuildContext(kBase);
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
    liaNode = new LeftInputAdapterNode(5, otn, buildContext);
    n1 = (BetaNode) createNetworkNode(10, type, liaNode, null);
    n2 = (BetaNode) createNetworkNode(11, type, n1, null);
    n3 = (BetaNode) createNetworkNode(12, type, n2, null);
    rule1 = new RuleImpl("rule1");
    rule1.setActivationListener("agenda");
    rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
    n4 = (BetaNode) createNetworkNode(13, type, n3, null);
    n5 = (BetaNode) createNetworkNode(14, type, n4, null);
    rule2 = new RuleImpl("rule2");
    rule2.setActivationListener("agenda");
    rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
    n6 = (BetaNode) createNetworkNode(15, type, n5, null);
    n7 = (BetaNode) createNetworkNode(16, type, n6, null);
    n8 = (BetaNode) createNetworkNode(17, type, n7, null);
    rule3 = new RuleImpl("rule3");
    rule3.setActivationListener("agenda");
    rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
    // n1 -> n2 -> n3 -> r1
    // \
    // n4 -> n5 -> r2
    // \
    // n6 -> n7 -> n8 -> r3
    liaNode.addAssociation(rule1);
    liaNode.addAssociation(rule2);
    liaNode.addAssociation(rule3);
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule1);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule1);
    n3.addAssociation(rule2);
    n3.addAssociation(rule3);
    n4.addAssociation(rule2);
    n4.addAssociation(rule3);
    n5.addAssociation(rule2);
    n5.addAssociation(rule3);
    n6.addAssociation(rule3);
    n7.addAssociation(rule3);
    n8.addAssociation(rule3);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) ClassObjectType(org.drools.core.base.ClassObjectType) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Example 15 with BuildContext

use of org.drools.core.reteoo.builder.BuildContext in project drools by kiegroup.

the class RuleUnlinkingWithSegmentMemoryTest method setUp.

public void setUp(int type) {
    KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
    buildContext = new BuildContext(kBase);
    PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
    context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
    ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
    lian = new LeftInputAdapterNode(5, otn, buildContext);
    n1 = (BetaNode) createNetworkNode(10, type, lian, null);
    n2 = (BetaNode) createNetworkNode(11, type, n1, null);
    n3 = (BetaNode) createNetworkNode(12, type, n2, null);
    rule1 = new RuleImpl("rule1");
    rule1.setActivationListener("agenda");
    rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
    n4 = (BetaNode) createNetworkNode(13, type, n3, null);
    n5 = (BetaNode) createNetworkNode(14, type, n4, null);
    rule2 = new RuleImpl("rule2");
    rule2.setActivationListener("agenda");
    rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
    n6 = (BetaNode) createNetworkNode(15, type, n5, null);
    n7 = (BetaNode) createNetworkNode(16, type, n6, null);
    n8 = (BetaNode) createNetworkNode(17, type, n7, null);
    rule3 = new RuleImpl("rule3");
    rule3.setActivationListener("agenda");
    rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
    lian.addAssociation(rule1);
    lian.addAssociation(rule2);
    lian.addAssociation(rule3);
    n1.addAssociation(rule1);
    n1.addAssociation(rule2);
    n1.addAssociation(rule3);
    n2.addAssociation(rule1);
    n2.addAssociation(rule2);
    n2.addAssociation(rule3);
    n3.addAssociation(rule1);
    n3.addAssociation(rule2);
    n3.addAssociation(rule3);
    n4.addAssociation(rule2);
    n4.addAssociation(rule3);
    n5.addAssociation(rule2);
    n5.addAssociation(rule3);
    n6.addAssociation(rule3);
    n7.addAssociation(rule3);
    n8.addAssociation(rule3);
}
Also used : KieBaseConfiguration(org.kie.api.KieBaseConfiguration) PropagationContextFactory(org.drools.core.common.PropagationContextFactory) BuildContext(org.drools.core.reteoo.builder.BuildContext) ClassObjectType(org.drools.core.base.ClassObjectType) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl)

Aggregations

BuildContext (org.drools.core.reteoo.builder.BuildContext)23 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)16 Test (org.junit.Test)11 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)9 PropagationContextFactory (org.drools.core.common.PropagationContextFactory)8 StatefulKnowledgeSessionImpl (org.drools.core.impl.StatefulKnowledgeSessionImpl)8 ClassObjectType (org.drools.core.base.ClassObjectType)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)7 RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)5 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)5 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)5 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)4 RuleTerminalNode (org.drools.core.reteoo.RuleTerminalNode)4 MVELDialectRuntimeData (org.drools.core.rule.MVELDialectRuntimeData)4 Cheese (org.drools.core.test.model.Cheese)4 Before (org.junit.Before)4 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)4 HashMap (java.util.HashMap)3 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)3 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)3