Search in sources :

Example 16 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class FloatClassFieldExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    this.reader = store.getReader(TestBean.class, "floatAttr");
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) TestBean(org.drools.core.base.TestBean) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) Before(org.junit.Before)

Example 17 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class ShortClassFieldExtractorTest method setUp.

@Before
public void setUp() throws Exception {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    this.reader = store.getReader(TestBean.class, "shortAttr");
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) TestBean(org.drools.core.base.TestBean) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) Before(org.junit.Before)

Example 18 with ClassFieldAccessorStore

use of org.drools.core.base.ClassFieldAccessorStore in project drools by kiegroup.

the class BaseBetaConstraintsTest method getConstraint.

protected BetaNodeFieldConstraint getConstraint(String identifier, Operator operator, String fieldName, Class clazz) {
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    InternalReadAccessor extractor = store.getReader(clazz, fieldName);
    Declaration declaration = new Declaration(identifier, extractor, new Pattern(0, new ClassObjectType(clazz)));
    String expression = fieldName + " " + operator.getOperatorString() + " " + identifier;
    return new MvelConstraintTestUtil(expression, operator.getOperatorString(), 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.core.base.ClassFieldAccessorStore) Declaration(org.drools.core.rule.Declaration) MvelConstraintTestUtil(org.drools.core.rule.MvelConstraintTestUtil)

Example 19 with ClassFieldAccessorStore

use of org.drools.core.base.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 = (InternalKnowledgeBase) 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);
    final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
    final FieldValue field = FieldFactory.getInstance().getFieldValue("cheddar");
    final MvelConstraint constraint = new MvelConstraintTestUtil("type == \"cheddar\"", field, extractor);
    pattern.addConstraint(constraint);
    rule1.addPattern(pattern);
    rule1.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) 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);
    final FieldValue field2 = FieldFactory.getInstance().getFieldValue("stilton");
    final MvelConstraint constraint2 = new MvelConstraintTestUtil("type == \"stilton\"", field, extractor);
    pattern2.addConstraint(constraint2);
    rule2.addPattern(pattern2);
    rule2.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) throws Exception {
        }

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

        public void writeExternal(ObjectOutput out) throws IOException {
        }

        public String getName() {
            return "default";
        }
    });
    pkg = new KnowledgePackageImpl("org.drools.test1");
    pkg.addRule(rule1);
    pkg.addRule(rule2);
}
Also used : Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectOutput(java.io.ObjectOutput) WorkingMemory(org.drools.core.WorkingMemory) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) Consequence(org.drools.core.spi.Consequence) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) IOException(java.io.IOException) MvelConstraintTestUtil(org.drools.core.rule.MvelConstraintTestUtil) IOException(java.io.IOException) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) ClassFieldReader(org.drools.core.base.ClassFieldReader) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper) FieldValue(org.drools.core.spi.FieldValue) ObjectInput(java.io.ObjectInput) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) Before(org.junit.Before)

Example 20 with ClassFieldAccessorStore

use of org.drools.core.base.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);
    final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
    final FieldValue field = FieldFactory.getInstance().getFieldValue("cheddar");
    final MvelConstraint constraint = new MvelConstraintTestUtil("type == \"cheddar\"", field, extractor);
    pattern.addConstraint(constraint);
    rule1.addPattern(pattern);
    rule1.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) 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);
    final FieldValue field2 = FieldFactory.getInstance().getFieldValue("stilton");
    final MvelConstraint constraint2 = new MvelConstraintTestUtil("type == \"stilton\"", field, extractor);
    pattern2.addConstraint(constraint2);
    rule2.addPattern(pattern2);
    rule2.setConsequence(new Consequence() {

        private static final long serialVersionUID = 510l;

        public void evaluate(final KnowledgeHelper knowledgeHelper, final WorkingMemory workingMemory) throws Exception {
        }

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

        public void writeExternal(ObjectOutput out) throws IOException {
        }

        public String getName() {
            return "default";
        }
    });
    pkg = new KnowledgePackageImpl("org.drools.test1");
    pkg.addRule(rule1);
    pkg.addRule(rule2);
}
Also used : Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) ObjectOutput(java.io.ObjectOutput) WorkingMemory(org.drools.core.WorkingMemory) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) Consequence(org.drools.core.spi.Consequence) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) ClassFieldAccessorStore(org.drools.core.base.ClassFieldAccessorStore) IOException(java.io.IOException) MvelConstraintTestUtil(org.drools.core.rule.MvelConstraintTestUtil) IOException(java.io.IOException) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) ClassFieldReader(org.drools.core.base.ClassFieldReader) KnowledgeHelper(org.drools.core.spi.KnowledgeHelper) FieldValue(org.drools.core.spi.FieldValue) ObjectInput(java.io.ObjectInput) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) Before(org.junit.Before)

Aggregations

ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)20 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)17 Before (org.junit.Before)11 TestBean (org.drools.core.base.TestBean)9 ClassObjectType (org.drools.core.base.ClassObjectType)6 Pattern (org.drools.core.rule.Pattern)6 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)5 Declaration (org.drools.core.rule.Declaration)4 IOException (java.io.IOException)2 ObjectInput (java.io.ObjectInput)2 ObjectOutput (java.io.ObjectOutput)2 WorkingMemory (org.drools.core.WorkingMemory)2 ClassFieldAccessor (org.drools.core.base.ClassFieldAccessor)2 ClassFieldReader (org.drools.core.base.ClassFieldReader)2 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)2 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)2 ClassDefinition (org.drools.core.factmodel.ClassDefinition)2 FieldDefinition (org.drools.core.factmodel.FieldDefinition)2 PackageClassLoader (org.drools.core.rule.JavaDialectRuntimeData.PackageClassLoader)2