Search in sources :

Example 46 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class DeclarationTest method testGetFieldValue.

@Test
public void testGetFieldValue() {
    final InternalReadAccessor extractor = store.getReader(Cheese.class, "type");
    final Pattern pattern = new Pattern(5, new ClassObjectType(Cheese.class));
    // Bind the extractor to a decleration
    // Declarations know the pattern they derive their value from
    final Declaration declaration = new Declaration("typeOfCheese", extractor, pattern);
    // Create some facts
    final Cheese cheddar = new Cheese("cheddar", 5);
    // Check we can extract Declarations correctly
    assertEquals("cheddar", declaration.getValue(null, cheddar));
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) Cheese(org.drools.core.test.model.Cheese) Test(org.junit.Test)

Example 47 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor 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 48 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class BaseMannersTest method getBoundVariableConstraint.

private BetaNodeFieldConstraint getBoundVariableConstraint(final Pattern pattern, final String fieldName, final Declaration declaration, final String operator) {
    final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
    final InternalReadAccessor extractor = store.getReader(clazz, fieldName);
    String expression = fieldName + " " + operator + " " + declaration.getIdentifier();
    return new MvelConstraintTestUtil(expression, declaration, extractor);
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) MvelConstraintTestUtil(org.drools.core.rule.MvelConstraintTestUtil)

Example 49 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class BaseMannersTest method setFieldDeclaration.

private void setFieldDeclaration(final Pattern pattern, final String fieldName, final String identifier) {
    final Class clazz = ((ClassObjectType) pattern.getObjectType()).getClassType();
    final InternalReadAccessor extractor = store.getReader(clazz, fieldName);
    pattern.addDeclaration(identifier).setReadAccessor(extractor);
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor)

Example 50 with InternalReadAccessor

use of org.drools.core.spi.InternalReadAccessor in project drools by kiegroup.

the class BaseClassFieldAccessorFactoryTest method testSelfReference.

@Test
public void testSelfReference() throws Exception {
    final InternalReadAccessor ex = store.getReader(BeanInherit.class, "this");
    final TestBean bean = new TestBean();
    assertEquals(bean, ex.getValue(null, bean));
}
Also used : InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) Test(org.junit.Test)

Aggregations

InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)58 Declaration (org.drools.core.rule.Declaration)27 Test (org.junit.Test)27 ClassObjectType (org.drools.core.base.ClassObjectType)26 Pattern (org.drools.core.rule.Pattern)23 Cheese (org.drools.core.test.model.Cheese)15 MvelConstraintTestUtil (org.drools.core.rule.MvelConstraintTestUtil)14 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)10 InternalFactHandle (org.drools.core.common.InternalFactHandle)9 FieldValue (org.drools.core.spi.FieldValue)9 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)8 TypeDeclaration (org.drools.core.rule.TypeDeclaration)7 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)7 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)7 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)6 KnowledgePackageImpl (org.drools.core.definitions.impl.KnowledgePackageImpl)6 LeftTupleImpl (org.drools.core.reteoo.LeftTupleImpl)6 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)6 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)5 ClassFieldAccessorStore (org.drools.core.base.ClassFieldAccessorStore)5