Search in sources :

Example 16 with ClassFieldAccessorStore

use of org.drools.mvel.accessors.ClassFieldAccessorStore in project drools by kiegroup.

the class BaseTupleIndexHashTableIteratorTest method createFooThisEqualsDBetaConstraintWithMvelConstraint.

private static BetaNodeFieldConstraint createFooThisEqualsDBetaConstraintWithMvelConstraint() {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    InternalReadAccessor extractor = store.getReader(Foo.class, "this");
    Declaration declaration = new Declaration("d", extractor, new Pattern(0, new ClassObjectType(Foo.class)));
    String expression = "this " + Operator.BuiltInOperator.EQUAL.getOperator().getOperatorString() + " d";
    return new MVELConstraintTestUtil(expression, declaration, extractor);
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) ClassFieldAccessorStore(org.drools.mvel.accessors.ClassFieldAccessorStore) Declaration(org.drools.core.rule.Declaration)

Example 17 with ClassFieldAccessorStore

use of org.drools.mvel.accessors.ClassFieldAccessorStore in project drools by kiegroup.

the class RuleBaseEventSupportTest method setUp.

/* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
@Before
public void setUp() throws Exception {
    kBase = KnowledgeBaseFactory.newKnowledgeBase();
    ;
    listener1 = new TestRuleBaseListener("(listener-1) ");
    listener2 = new TestRuleBaseListener("(listener-2) ");
    kBase.addEventListener(listener1);
    kBase.addEventListener(listener2);
    final RuleImpl rule1 = new RuleImpl("test1");
    final ClassObjectType cheeseObjectType = new ClassObjectType(Cheese.class);
    final Pattern pattern = new Pattern(0, cheeseObjectType);
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    AlphaNodeFieldConstraint constraint = ConstraintTestUtil.createCheeseTypeEqualsConstraint(store, "cheddar", useLambdaConstraint);
    pattern.addConstraint(constraint);
    rule1.addPattern(pattern);
    rule1.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final ReteEvaluator reteEvaluator) throws Exception {
        }

        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        }

        public void writeExternal(ObjectOutput out) throws IOException {
        }

        public String getName() {
            return "default";
        }
    });
    final RuleImpl rule2 = new RuleImpl("test2");
    final ClassObjectType cheeseObjectType2 = new ClassObjectType(Cheese.class);
    final Pattern pattern2 = new Pattern(0, cheeseObjectType2);
    AlphaNodeFieldConstraint constraint2 = ConstraintTestUtil.createCheeseTypeEqualsConstraint(store, "stilton", useLambdaConstraint);
    pattern2.addConstraint(constraint2);
    rule2.addPattern(pattern2);
    rule2.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final ReteEvaluator reteEvaluator) throws Exception {
        }

        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        }

        public void writeExternal(ObjectOutput out) throws IOException {
        }

        public String getName() {
            return "default";
        }
    });
    pkg = CoreComponentFactory.get().createKnowledgePackage("org.drools.test1");
    pkg.addRule(rule1);
    pkg.addRule(rule2);
}
Also used : ReteEvaluator(org.drools.core.common.ReteEvaluator) Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectOutput(java.io.ObjectOutput) Consequence(org.drools.core.spi.Consequence) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ClassFieldAccessorStore(org.drools.mvel.accessors.ClassFieldAccessorStore) IOException(java.io.IOException) IOException(java.io.IOException) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper) ObjectInput(java.io.ObjectInput) Before(org.junit.Before)

Example 18 with ClassFieldAccessorStore

use of org.drools.mvel.accessors.ClassFieldAccessorStore in project drools by kiegroup.

the class KnowledgeBaseEventSupportTest method setUp.

/* (non-Javadoc)
     * @see junit.framework.TestCase#setUp()
     */
@Before
public void setUp() throws Exception {
    kbase = KnowledgeBaseFactory.newKnowledgeBase();
    listener1 = new TestRuleBaseListener("(listener-1) ");
    listener2 = new TestRuleBaseListener("(listener-2) ");
    kbase.addEventListener(listener1);
    kbase.addEventListener(listener2);
    final RuleImpl rule1 = new RuleImpl("test1");
    final ClassObjectType cheeseObjectType = new ClassObjectType(Cheese.class);
    final Pattern pattern = new Pattern(0, cheeseObjectType);
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    AlphaNodeFieldConstraint constraint = ConstraintTestUtil.createCheeseTypeEqualsConstraint(store, "cheddar", useLambdaConstraint);
    pattern.addConstraint(constraint);
    rule1.addPattern(pattern);
    rule1.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final ReteEvaluator reteEvaluator) throws Exception {
        }

        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        }

        public void writeExternal(ObjectOutput out) throws IOException {
        }

        public String getName() {
            return "default";
        }
    });
    final RuleImpl rule2 = new RuleImpl("test2");
    final ClassObjectType cheeseObjectType2 = new ClassObjectType(Cheese.class);
    final Pattern pattern2 = new Pattern(0, cheeseObjectType2);
    AlphaNodeFieldConstraint constraint2 = ConstraintTestUtil.createCheeseTypeEqualsConstraint(store, "stilton", useLambdaConstraint);
    pattern2.addConstraint(constraint2);
    rule2.addPattern(pattern2);
    rule2.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final ReteEvaluator reteEvaluator) throws Exception {
        }

        public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
        }

        public void writeExternal(ObjectOutput out) throws IOException {
        }

        public String getName() {
            return "default";
        }
    });
    pkg = CoreComponentFactory.get().createKnowledgePackage("org.drools.test1");
    pkg.addRule(rule1);
    pkg.addRule(rule2);
}
Also used : ReteEvaluator(org.drools.core.common.ReteEvaluator) Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectOutput(java.io.ObjectOutput) Consequence(org.drools.core.spi.Consequence) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ClassFieldAccessorStore(org.drools.mvel.accessors.ClassFieldAccessorStore) IOException(java.io.IOException) IOException(java.io.IOException) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper) ObjectInput(java.io.ObjectInput) Before(org.junit.Before)

Aggregations

ClassFieldAccessorStore (org.drools.mvel.accessors.ClassFieldAccessorStore)18 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)16 Before (org.junit.Before)11 TestBean (org.drools.core.base.TestBean)9 ClassObjectType (org.drools.core.base.ClassObjectType)5 Pattern (org.drools.core.rule.Pattern)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)4 Declaration (org.drools.core.rule.Declaration)3 IOException (java.io.IOException)2 ObjectInput (java.io.ObjectInput)2 ObjectOutput (java.io.ObjectOutput)2 BetaConstraints (org.drools.core.common.BetaConstraints)2 ReteEvaluator (org.drools.core.common.ReteEvaluator)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)2 Consequence (org.drools.core.spi.Consequence)2 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)2 PackageClassLoader (org.drools.wiring.dynamic.PackageClassLoader)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1