Search in sources :

Example 11 with ClassFieldAccessorStore

use of org.drools.mvel.accessors.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.mvel.accessors.ClassFieldAccessorStore) Before(org.junit.Before)

Example 12 with ClassFieldAccessorStore

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

the class LongClassFieldExtractorTest method setUp.

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

Example 13 with ClassFieldAccessorStore

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

the class ObjectClassFieldExtractorTest method testIsNullValue.

@Test
public void testIsNullValue() {
    assertFalse(this.reader.isNullValue(null, this.bean));
    ClassFieldAccessorStore store = new ClassFieldAccessorStore();
    store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
    store.setEagerWire(true);
    InternalReadAccessor nullExtractor = store.getReader(TestBean.class, "nullAttr");
    assertTrue(nullExtractor.isNullValue(null, this.bean));
}
Also used : ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) ClassFieldAccessorStore(org.drools.mvel.accessors.ClassFieldAccessorStore) Test(org.junit.Test)

Example 14 with ClassFieldAccessorStore

use of org.drools.mvel.accessors.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.mvel.accessors.ClassFieldAccessorStore) Before(org.junit.Before)

Example 15 with ClassFieldAccessorStore

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

the class BaseBetaConstraintsTest method getCheeseTypeConstraint.

protected BetaNodeFieldConstraint getCheeseTypeConstraint(final String identifier, Operator operator) {
    if (useLambdaConstraint) {
        Pattern pattern = new Pattern(0, new ClassObjectType(Cheese.class));
        Predicate1<Cheese> predicate;
        if (operator == Operator.BuiltInOperator.EQUAL.getOperator()) {
            predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.areNullSafeEquals(_this.getType(), identifier));
        } else if (operator == Operator.BuiltInOperator.NOT_EQUAL.getOperator()) {
            predicate = new Predicate1.Impl<Cheese>(_this -> !EvaluationUtil.areNullSafeEquals(_this.getType(), identifier));
        } else if (operator == Operator.BuiltInOperator.GREATER.getOperator()) {
            predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.greaterThan(_this.getType(), identifier));
        } else if (operator == Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator()) {
            predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.greaterOrEqual(_this.getType(), identifier));
        } else if (operator == Operator.BuiltInOperator.LESS.getOperator()) {
            predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.lessThan(_this.getType(), identifier));
        } else if (operator == Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator()) {
            predicate = new Predicate1.Impl<Cheese>(_this -> EvaluationUtil.lessOrEqual(_this.getType(), identifier));
        } else {
            throw new RuntimeException(operator + " is not supported");
        }
        return LambdaConstraintTestUtil.createLambdaConstraint1(Cheese.class, pattern, predicate, null);
    } else {
        ClassFieldAccessorStore store = new ClassFieldAccessorStore();
        store.setClassFieldAccessorCache(new ClassFieldAccessorCache(Thread.currentThread().getContextClassLoader()));
        store.setEagerWire(true);
        InternalReadAccessor extractor = store.getReader(Cheese.class, "type");
        Declaration declaration = new Declaration(identifier, extractor, new Pattern(0, new ClassObjectType(Cheese.class)));
        String expression = "type " + operator.getOperatorString() + " " + identifier;
        return new MVELConstraintTestUtil(expression, operator.getOperatorString(), declaration, extractor);
    }
}
Also used : LinkedList(org.drools.core.util.LinkedList) ClassObjectType(org.drools.core.base.ClassObjectType) BetaConstraints(org.drools.core.common.BetaConstraints) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) EvaluatorRegistry(org.drools.compiler.builder.impl.EvaluatorRegistry) Pattern(org.drools.core.rule.Pattern) RunWith(org.junit.runner.RunWith) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) BetaMemory(org.drools.core.reteoo.BetaMemory) ArrayList(java.util.ArrayList) ConstraintType(org.drools.core.util.index.IndexUtil.ConstraintType) Assert.assertSame(org.junit.Assert.assertSame) Declaration(org.drools.core.rule.Declaration) RuleBaseConfiguration(org.drools.core.RuleBaseConfiguration) Index(org.drools.core.util.AbstractHashTable.Index) LinkedListEntry(org.drools.core.util.LinkedListEntry) TupleList(org.drools.core.util.index.TupleList) Parameterized(org.junit.runners.Parameterized) TupleIndexHashTable(org.drools.core.util.index.TupleIndexHashTable) Collection(java.util.Collection) Operator(org.drools.drl.parser.impl.Operator) Assert.assertTrue(org.junit.Assert.assertTrue) FieldIndex(org.drools.core.util.AbstractHashTable.FieldIndex) Predicate1(org.drools.model.functions.Predicate1) EvaluationUtil(org.drools.modelcompiler.util.EvaluationUtil) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) ClassFieldAccessorStore(org.drools.mvel.accessors.ClassFieldAccessorStore) Cheese(org.drools.mvel.model.Cheese) Assert.assertEquals(org.junit.Assert.assertEquals) NodeTypeEnums(org.drools.core.reteoo.NodeTypeEnums) IndexableConstraint(org.drools.core.rule.IndexableConstraint) Pattern(org.drools.core.rule.Pattern) ClassObjectType(org.drools.core.base.ClassObjectType) Cheese(org.drools.mvel.model.Cheese) ClassFieldAccessorStore(org.drools.mvel.accessors.ClassFieldAccessorStore) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) Predicate1(org.drools.model.functions.Predicate1) Declaration(org.drools.core.rule.Declaration)

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