Search in sources :

Example 26 with ClassFieldAccessorCache

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

the class ByteClassFieldExtractorTest 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, "byteAttr");
}
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 27 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache 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 28 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache 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 29 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache 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 30 with ClassFieldAccessorCache

use of org.drools.core.base.ClassFieldAccessorCache 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)

Aggregations

ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)34 Before (org.junit.Before)22 ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)17 TestBean (org.drools.core.base.TestBean)9 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)9 ClassObjectType (org.drools.core.base.ClassObjectType)7 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)6 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)6 Pattern (org.drools.core.rule.Pattern)6 WorkingMemory (org.drools.core.WorkingMemory)5 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)5 Consequence (org.drools.core.spi.Consequence)5 KnowledgeHelper (org.drools.core.spi.KnowledgeHelper)5 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)4 IOException (java.io.IOException)3 ObjectInput (java.io.ObjectInput)3 ObjectOutput (java.io.ObjectOutput)3 ClassFieldReader (org.drools.core.base.ClassFieldReader)3 Declaration (org.drools.core.rule.Declaration)3 JavaDialectRuntimeData (org.drools.core.rule.JavaDialectRuntimeData)3