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));
}
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);
}
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);
}
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);
}
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));
}
Aggregations