Search in sources :

Example 1 with Predicate1

use of org.drools.model.functions.Predicate1 in project drools by kiegroup.

the class PatternDSLTest method test2AccRewriteToNested.

@Test
public void test2AccRewriteToNested() throws Exception {
    final Global<List> var_results = D.globalOf(List.class, "defaultpkg", "results");
    final Variable<Person> var_$p = D.declarationOf(Person.class);
    Variable<Integer> var_$age = D.declarationOf(Integer.class);
    Variable<Integer> var_$sumOfAges = D.declarationOf(Integer.class);
    Variable<Long> var_$countOfPersons = D.declarationOf(Long.class);
    Predicate1<Long> cp = c -> c > 0;
    Rule rule1 = D.rule("R1").build(D.accumulate(D.pattern(var_$p).bind(var_$age, person -> person.getAge(), D.reactOn("age")), D.accFunction(org.drools.core.base.accumulators.IntegerSumAccumulateFunction::new, var_$age).as(var_$sumOfAges)), D.accumulate(D.pattern(var_$sumOfAges), D.accFunction(org.drools.core.base.accumulators.CountAccumulateFunction::new).as(var_$countOfPersons)), // Filter
    D.pattern(var_$countOfPersons).expr(cp), // Consequence
    D.on(var_$countOfPersons, var_results).execute((drools, i, results) -> {
        Activation activation = (Activation) ((org.drools.modelcompiler.consequence.DroolsImpl) drools).asKnowledgeHelper().getMatch();
        results.add(i + ":" + activation.getObjectsDeep());
    }));
    Model model = new ModelImpl().addRule(rule1).addGlobal(var_results);
    KieBase kbase = KieBaseBuilder.createKieBaseFromModel(model);
    RuleImpl rule = (RuleImpl) kbase.getKiePackage("defaultpkg").getRules().toArray()[0];
    // Should only be a single child
    assertEquals(1, rule.getLhs().getChildren().size());
    // Check correct result type and the filter was moved up
    Pattern p1 = (Pattern) rule.getLhs().getChildren().get(0);
    assertSame(Long.class, ((ClassObjectType) p1.getObjectType()).getClassType());
    LambdaConstraint l0 = (LambdaConstraint) p1.getConstraints().get(0);
    assertSame(cp, ((Predicate1.Impl) l0.getEvaluator().getConstraint().getPredicate1()).getLambda());
    // The second acc was sucessfully nested inside
    Accumulate acc = (Accumulate) p1.getSource();
    assertEquals(1, acc.getNestedElements().size());
    Pattern p2 = (Pattern) acc.getNestedElements().get(0);
    assertSame(Integer.class, ((ClassObjectType) p2.getObjectType()).getClassType());
    KieSession ksession = kbase.newKieSession();
    List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    ksession.insert(new Person("Mark", 42));
    ksession.fireAllRules();
    assertEquals("[1:[1]]", results.toString());
}
Also used : Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Man(org.drools.modelcompiler.domain.Man) Global(org.drools.model.Global) Toy(org.drools.modelcompiler.domain.Toy) PatternDSL.reactOn(org.drools.model.PatternDSL.reactOn) DSL(org.drools.model.DSL) Relationship(org.drools.modelcompiler.domain.Relationship) BaseModelTest.getObjectsIntoList(org.drools.modelcompiler.BaseModelTest.getObjectsIntoList) Query2Def(org.drools.model.Query2Def) PatternDSL.declarationOf(org.drools.model.PatternDSL.declarationOf) Child(org.drools.modelcompiler.domain.Child) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryResults(org.kie.api.runtime.rule.QueryResults) Assertions(org.assertj.core.api.Assertions) KieSession(org.kie.api.runtime.KieSession) QueryImpl(org.drools.core.rule.QueryImpl) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) PatternDSL.rule(org.drools.model.PatternDSL.rule) EventProcessingOption(org.kie.api.conf.EventProcessingOption) Collection(java.util.Collection) Activation(org.drools.core.spi.Activation) Index(org.drools.model.Index) Predicate1(org.drools.model.functions.Predicate1) PatternDSL.on(org.drools.model.PatternDSL.on) PatternDSL.pattern(org.drools.model.PatternDSL.pattern) List(java.util.List) Query(org.drools.model.Query) PatternDSL.or(org.drools.model.PatternDSL.or) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) PatternDSL.globalOf(org.drools.model.PatternDSL.globalOf) Person(org.drools.modelcompiler.domain.Person) PatternDSL.valueOf(org.drools.model.PatternDSL.valueOf) ModelImpl(org.drools.model.impl.ModelImpl) ClassObjectType(org.drools.core.base.ClassObjectType) PatternDSL.execute(org.drools.model.PatternDSL.execute) StockTick(org.drools.modelcompiler.domain.StockTick) Pattern(org.drools.core.rule.Pattern) PatternDSL(org.drools.model.PatternDSL) PatternDSL.after(org.drools.model.PatternDSL.after) ClockType(org.drools.core.ClockType) ArrayList(java.util.ArrayList) Result(org.drools.modelcompiler.domain.Result) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Assert.assertSame(org.junit.Assert.assertSame) Adult(org.drools.modelcompiler.domain.Adult) PatternDSL.alphaIndexedBy(org.drools.model.PatternDSL.alphaIndexedBy) PatternDSL.query(org.drools.model.PatternDSL.query) PatternDSL.reactiveFrom(org.drools.model.PatternDSL.reactiveFrom) KieServices(org.kie.api.KieServices) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Woman(org.drools.modelcompiler.domain.Woman) KieBase(org.kie.api.KieBase) Model(org.drools.model.Model) PatternDSL.and(org.drools.model.PatternDSL.and) ViewItem(org.drools.model.view.ViewItem) Pair(org.apache.commons.math3.util.Pair) Variable(org.drools.model.Variable) D(org.drools.modelcompiler.dsl.pattern.D) IOException(java.io.IOException) Test(org.junit.Test) PatternDSL.accumulate(org.drools.model.PatternDSL.accumulate) PatternDSL.not(org.drools.model.PatternDSL.not) PatternDSL.when(org.drools.model.PatternDSL.when) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) FactHandle(org.kie.api.runtime.rule.FactHandle) PatternDSL.accFunction(org.drools.model.PatternDSL.accFunction) TimeUnit(java.util.concurrent.TimeUnit) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder) ClockTypeOption(org.kie.api.runtime.conf.ClockTypeOption) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.drools.model.Rule) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) PatternDSL.betaIndexedBy(org.drools.model.PatternDSL.betaIndexedBy) Accumulate(org.drools.core.rule.Accumulate) DSL.supply(org.drools.model.DSL.supply) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayList(java.util.ArrayList) Activation(org.drools.core.spi.Activation) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) Accumulate(org.drools.core.rule.Accumulate) KieBase(org.kie.api.KieBase) BaseModelTest.getObjectsIntoList(org.drools.modelcompiler.BaseModelTest.getObjectsIntoList) List(java.util.List) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ModelImpl(org.drools.model.impl.ModelImpl) Pattern(org.drools.core.rule.Pattern) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Model(org.drools.model.Model) Predicate1(org.drools.model.functions.Predicate1) Rule(org.drools.model.Rule) Person(org.drools.modelcompiler.domain.Person) Test(org.junit.Test)

Example 2 with Predicate1

use of org.drools.model.functions.Predicate1 in project drools by kiegroup.

the class ToStringTest method testToString.

/**
 * Users may depend on seeing {@link Rule#toString()} in log files giving useful information, in order to understand
 * the rules that are being created. The format is not required to be backwards compatible - this test merely checks
 * that it does not change unknowingly.
 */
@Test
public void testToString() {
    Variable<Person> markV = declarationOf(Person.class);
    Variable<Integer> markAge = declarationOf(Integer.class);
    Variable<Person> olderV = declarationOf(Person.class);
    Variable<Double> resultAvg = declarationOf(Double.class);
    Variable<Integer> age = declarationOf(Integer.class);
    String person = "Mark";
    Function1<Person, String> nameGetter = Person::getName;
    Function1<Person, Integer> ageGetter = Person::getAge;
    Predicate1<Person> markPredicate = p -> p.getName().equals(person);
    PatternDSL.PatternDef<Person> pattern1 = pattern(markV).expr("exprA", markPredicate, alphaIndexedBy(String.class, Index.ConstraintType.EQUAL, 0, nameGetter, person)).bind(markAge, ageGetter);
    Predicate1<Person> notMarkPredicate = markPredicate.negate();
    Predicate2<Person, Integer> agePredicate = (p1, someAge) -> p1.getAge() > someAge;
    Function1<Integer, Integer> ageCaster = int.class::cast;
    PatternDSL.PatternDef<Person> pattern2 = pattern(olderV).expr("exprB", notMarkPredicate, alphaIndexedBy(String.class, Index.ConstraintType.NOT_EQUAL, 1, nameGetter, person)).expr("exprC", markAge, agePredicate, betaIndexedBy(int.class, Index.ConstraintType.GREATER_THAN, 0, ageGetter, ageCaster));
    AccumulateFunction<AverageAccumulateFunction.AverageData> f = new AverageAccumulateFunction();
    Supplier<AccumulateFunction<AverageAccumulateFunction.AverageData>> accumulateSupplier = () -> f;
    org.drools.model.functions.accumulate.AccumulateFunction actualAccumulate = accFunction(accumulateSupplier, age);
    ExprViewItem<Person> accumulate = accumulate(pattern(olderV).expr("exprD", notMarkPredicate).bind(age, ageGetter), actualAccumulate.as(resultAvg));
    Rule rule = rule("beta").build(pattern1, pattern2, accumulate, on(olderV, markV).execute((drools, p1, p2) -> drools.insert(p1.getName() + " is older than " + p2.getName())));
    String pattern1toString = "PatternImpl (type: PATTERN, inputVars: null, " + "outputVar: " + markV + ", " + "constraint: Constraint for 'exprA' (index: AlphaIndex #0 (EQUAL, left: lambda " + System.identityHashCode(nameGetter) + ", right: " + person + ")))";
    String pattern2toString = "PatternImpl (type: PATTERN, inputVars: null, " + "outputVar: " + olderV + ", " + "constraint: MultipleConstraints (constraints: [" + "Constraint for 'exprB' (index: AlphaIndex #1 (NOT_EQUAL, left: lambda " + System.identityHashCode(nameGetter) + ", right: " + person + ")), " + "Constraint for 'exprC' (index: BetaIndex #0 (GREATER_THAN, left: lambda " + System.identityHashCode(ageGetter) + ", right: lambda " + System.identityHashCode(ageCaster) + "))]))";
    String accumulatePatternToString = "PatternImpl (type: PATTERN, inputVars: null, " + "outputVar: " + olderV + ", " + "constraint: Constraint for 'exprD' (index: null))";
    String accumulateToString = "AccumulatePatternImpl (functions: [" + actualAccumulate + "], " + "condition: " + accumulatePatternToString + ", " + "pattern: " + accumulatePatternToString + ")";
    String consequenceToString = "ConsequenceImpl (variables: [" + olderV + ", " + markV + "], language: java, breaking: false)";
    String expectedToString = "Rule: defaultpkg.beta (" + "view: CompositePatterns of AND (vars: null, patterns: [" + pattern1toString + ", " + pattern2toString + ", " + accumulateToString + ", NamedConsequenceImpl 'default' (breaking: false)], " + "consequences: {default=" + consequenceToString + "}), consequences: {default=" + consequenceToString + "})";
    Assertions.assertThat(rule).hasToString(expectedToString);
}
Also used : PatternDSL.rule(org.drools.model.PatternDSL.rule) Variable(org.drools.model.Variable) AverageAccumulateFunction(org.drools.core.base.accumulators.AverageAccumulateFunction) PatternDSL(org.drools.model.PatternDSL) Test(org.junit.Test) DSL.on(org.drools.model.DSL.on) Index(org.drools.model.Index) Predicate1(org.drools.model.functions.Predicate1) Supplier(java.util.function.Supplier) PatternDSL.pattern(org.drools.model.PatternDSL.pattern) Predicate2(org.drools.model.functions.Predicate2) DSL.accumulate(org.drools.model.DSL.accumulate) Function1(org.drools.model.functions.Function1) DSL.accFunction(org.drools.model.DSL.accFunction) PatternDSL.alphaIndexedBy(org.drools.model.PatternDSL.alphaIndexedBy) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) Rule(org.drools.model.Rule) Assertions(org.assertj.core.api.Assertions) ExprViewItem(org.drools.model.view.ExprViewItem) Person(org.drools.modelcompiler.domain.Person) PatternDSL.betaIndexedBy(org.drools.model.PatternDSL.betaIndexedBy) DSL.declarationOf(org.drools.model.DSL.declarationOf) DSL.accumulate(org.drools.model.DSL.accumulate) AverageAccumulateFunction(org.drools.core.base.accumulators.AverageAccumulateFunction) PatternDSL(org.drools.model.PatternDSL) Rule(org.drools.model.Rule) AverageAccumulateFunction(org.drools.core.base.accumulators.AverageAccumulateFunction) AccumulateFunction(org.kie.api.runtime.rule.AccumulateFunction) Person(org.drools.modelcompiler.domain.Person) Test(org.junit.Test)

Example 3 with Predicate1

use of org.drools.model.functions.Predicate1 in project drools by kiegroup.

the class PatternDSLTest method testPatternsAfterAccMovedToEvalsOnResultPattern.

@Test
public void testPatternsAfterAccMovedToEvalsOnResultPattern() throws Exception {
    final Global<List> var_results = D.globalOf(List.class, "defaultpkg", "results");
    final Variable<String> var_$key = D.declarationOf(String.class);
    final Variable<Person> var_$p = D.declarationOf(Person.class);
    Variable<Integer> var_$age = D.declarationOf(Integer.class);
    Variable<Integer> var_$sumOfAges = D.declarationOf(Integer.class);
    Variable<Long> var_$countOfPersons = D.declarationOf(Long.class);
    Predicate1<Integer> p1 = a -> a > 0;
    Predicate1<Long> p2 = c -> c > 0;
    Rule rule1 = D.rule("R1").build(D.accumulate(// Patterns
    D.pattern(var_$p).bind(var_$age, person -> person.getAge(), D.reactOn("age")), D.accFunction(org.drools.core.base.accumulators.IntegerSumAccumulateFunction::new, var_$age).as(var_$sumOfAges), D.accFunction(org.drools.core.base.accumulators.CountAccumulateFunction::new).as(var_$countOfPersons)), // Filter
    D.pattern(var_$sumOfAges).expr(p1), D.pattern(var_$countOfPersons).expr(p2), // Consequence
    D.on(var_$sumOfAges, var_$countOfPersons, var_results).execute(($ages, $counts, results) -> results.add($ages + ":" + $counts)));
    Model model = new ModelImpl().addRule(rule1).addGlobal(var_results);
    KieBase kbase = KieBaseBuilder.createKieBaseFromModel(model);
    RuleImpl rule = (RuleImpl) kbase.getKiePackage("defaultpkg").getRules().toArray()[0];
    // Ensure there is only a single root child
    assertEquals(1, rule.getLhs().getChildren().size());
    // The expression must be merged up into the acc pattern
    Pattern p = (Pattern) rule.getLhs().getChildren().get(0);
    assertSame(Object[].class, ((ClassObjectType) p.getObjectType()).getClassType());
    LambdaConstraint l0 = (LambdaConstraint) p.getConstraints().get(0);
    assertSame(p1, ((Predicate1.Impl) l0.getEvaluator().getConstraint().getPredicate1()).getLambda());
    LambdaConstraint l1 = (LambdaConstraint) p.getConstraints().get(1);
    assertSame(p2, ((Predicate1.Impl) l1.getEvaluator().getConstraint().getPredicate1()).getLambda());
    KieSession ksession = kbase.newKieSession();
    List<String> results = new ArrayList<String>();
    ksession.setGlobal("results", results);
    ksession.insert(new Person("Mark", 42));
    ksession.fireAllRules();
    assertEquals("[42:1]", results.toString());
}
Also used : Arrays(java.util.Arrays) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) Man(org.drools.modelcompiler.domain.Man) Global(org.drools.model.Global) Toy(org.drools.modelcompiler.domain.Toy) PatternDSL.reactOn(org.drools.model.PatternDSL.reactOn) DSL(org.drools.model.DSL) Relationship(org.drools.modelcompiler.domain.Relationship) BaseModelTest.getObjectsIntoList(org.drools.modelcompiler.BaseModelTest.getObjectsIntoList) Query2Def(org.drools.model.Query2Def) PatternDSL.declarationOf(org.drools.model.PatternDSL.declarationOf) Child(org.drools.modelcompiler.domain.Child) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueryResults(org.kie.api.runtime.rule.QueryResults) Assertions(org.assertj.core.api.Assertions) KieSession(org.kie.api.runtime.KieSession) QueryImpl(org.drools.core.rule.QueryImpl) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) PatternDSL.rule(org.drools.model.PatternDSL.rule) EventProcessingOption(org.kie.api.conf.EventProcessingOption) Collection(java.util.Collection) Activation(org.drools.core.spi.Activation) Index(org.drools.model.Index) Predicate1(org.drools.model.functions.Predicate1) PatternDSL.on(org.drools.model.PatternDSL.on) PatternDSL.pattern(org.drools.model.PatternDSL.pattern) List(java.util.List) Query(org.drools.model.Query) PatternDSL.or(org.drools.model.PatternDSL.or) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) PatternDSL.globalOf(org.drools.model.PatternDSL.globalOf) Person(org.drools.modelcompiler.domain.Person) PatternDSL.valueOf(org.drools.model.PatternDSL.valueOf) ModelImpl(org.drools.model.impl.ModelImpl) ClassObjectType(org.drools.core.base.ClassObjectType) PatternDSL.execute(org.drools.model.PatternDSL.execute) StockTick(org.drools.modelcompiler.domain.StockTick) Pattern(org.drools.core.rule.Pattern) PatternDSL(org.drools.model.PatternDSL) PatternDSL.after(org.drools.model.PatternDSL.after) ClockType(org.drools.core.ClockType) ArrayList(java.util.ArrayList) Result(org.drools.modelcompiler.domain.Result) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) Assert.assertSame(org.junit.Assert.assertSame) Adult(org.drools.modelcompiler.domain.Adult) PatternDSL.alphaIndexedBy(org.drools.model.PatternDSL.alphaIndexedBy) PatternDSL.query(org.drools.model.PatternDSL.query) PatternDSL.reactiveFrom(org.drools.model.PatternDSL.reactiveFrom) KieServices(org.kie.api.KieServices) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Woman(org.drools.modelcompiler.domain.Woman) KieBase(org.kie.api.KieBase) Model(org.drools.model.Model) PatternDSL.and(org.drools.model.PatternDSL.and) ViewItem(org.drools.model.view.ViewItem) Pair(org.apache.commons.math3.util.Pair) Variable(org.drools.model.Variable) D(org.drools.modelcompiler.dsl.pattern.D) IOException(java.io.IOException) Test(org.junit.Test) PatternDSL.accumulate(org.drools.model.PatternDSL.accumulate) PatternDSL.not(org.drools.model.PatternDSL.not) PatternDSL.when(org.drools.model.PatternDSL.when) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) FactHandle(org.kie.api.runtime.rule.FactHandle) PatternDSL.accFunction(org.drools.model.PatternDSL.accFunction) TimeUnit(java.util.concurrent.TimeUnit) KieBaseBuilder(org.drools.modelcompiler.builder.KieBaseBuilder) ClockTypeOption(org.kie.api.runtime.conf.ClockTypeOption) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.drools.model.Rule) CollectSetAccumulateFunction(org.drools.core.base.accumulators.CollectSetAccumulateFunction) PatternDSL.betaIndexedBy(org.drools.model.PatternDSL.betaIndexedBy) Accumulate(org.drools.core.rule.Accumulate) DSL.supply(org.drools.model.DSL.supply) Assert.assertEquals(org.junit.Assert.assertEquals) ArrayList(java.util.ArrayList) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) KieBase(org.kie.api.KieBase) BaseModelTest.getObjectsIntoList(org.drools.modelcompiler.BaseModelTest.getObjectsIntoList) List(java.util.List) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ModelImpl(org.drools.model.impl.ModelImpl) Pattern(org.drools.core.rule.Pattern) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Model(org.drools.model.Model) Predicate1(org.drools.model.functions.Predicate1) Rule(org.drools.model.Rule) Person(org.drools.modelcompiler.domain.Person) Test(org.junit.Test)

Example 4 with Predicate1

use of org.drools.model.functions.Predicate1 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

ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Assertions (org.assertj.core.api.Assertions)3 ClassObjectType (org.drools.core.base.ClassObjectType)3 Pattern (org.drools.core.rule.Pattern)3 Index (org.drools.model.Index)3 PatternDSL (org.drools.model.PatternDSL)3 PatternDSL.alphaIndexedBy (org.drools.model.PatternDSL.alphaIndexedBy)3 PatternDSL.betaIndexedBy (org.drools.model.PatternDSL.betaIndexedBy)3 PatternDSL.pattern (org.drools.model.PatternDSL.pattern)3 PatternDSL.rule (org.drools.model.PatternDSL.rule)3 Predicate1 (org.drools.model.functions.Predicate1)3 IOException (java.io.IOException)2 Arrays (java.util.Arrays)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Pair (org.apache.commons.math3.util.Pair)2 ClockType (org.drools.core.ClockType)2 CollectSetAccumulateFunction (org.drools.core.base.accumulators.CollectSetAccumulateFunction)2