Search in sources :

Example 1 with LiteralRestriction

use of org.drools.verifier.components.LiteralRestriction in project drools by kiegroup.

the class FieldConstraintDescrVisitor method visit.

/**
 * End
 *
 * @param descr
 */
private void visit(LiteralRestrictionDescr descr) {
    LiteralRestriction restriction = LiteralRestriction.createRestriction(pattern, descr.getText());
    restriction.setPatternIsNot(pattern.isPatternNot());
    restriction.setFieldPath(field.getPath());
    restriction.setOperator(Operator.determineOperator(descr.getEvaluator(), descr.isNegated()));
    restriction.setOrderNumber(orderNumber);
    restriction.setParentPath(pattern.getPath());
    restriction.setParentType(pattern.getVerifierComponentType());
    // Set field value, if it is unset.
    field.setFieldType(restriction.getValueType());
    data.add(restriction);
    solvers.addPatternComponent(restriction);
}
Also used : LiteralRestriction(org.drools.verifier.components.LiteralRestriction)

Example 2 with LiteralRestriction

use of org.drools.verifier.components.LiteralRestriction in project drools by kiegroup.

the class IncompatibilityRestrictionsTest method testLiteralRestrictionsIncompatibilityGreater.

@Test
public void testLiteralRestrictionsIncompatibilityGreater() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
    Collection<Object> data = new ArrayList<Object>();
    Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
    Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
    /*
         * Working pair
         */
    LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern1, "10");
    r1.setOperator(Operator.BuiltInOperator.GREATER.getOperator());
    r1.setFieldPath("0");
    r1.setOrderNumber(0);
    LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern1, "1");
    r2.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
    r2.setFieldPath("0");
    r2.setOrderNumber(1);
    /*
         * Pair that doesn't work.
         */
    LiteralRestriction r3 = LiteralRestriction.createRestriction(pattern2, "1");
    r3.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
    r3.setFieldPath("1");
    r3.setOrderNumber(0);
    LiteralRestriction r4 = LiteralRestriction.createRestriction(pattern2, "10");
    r4.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
    r4.setFieldPath("1");
    r4.setOrderNumber(1);
    data.add(r1);
    data.add(r2);
    data.add(r3);
    data.add(r4);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incompatible LiteralRestrictions with ranges in pattern possibility, impossible equality greater"));
    Map<Cause, Set<Cause>> map = createIncompatibilityMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
    assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
    if (!map.isEmpty()) {
        fail("More incompatibilities than was expected.");
    }
}
Also used : LiteralRestriction(org.drools.verifier.components.LiteralRestriction) Pattern(org.drools.verifier.components.Pattern) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Set(java.util.Set) Cause(org.drools.verifier.report.components.Cause) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 3 with LiteralRestriction

use of org.drools.verifier.components.LiteralRestriction in project drools by kiegroup.

the class IncompatibilityRestrictionsTest method testLiteralRestrictionsIncompatibilityImpossibleRange.

@Test
public void testLiteralRestrictionsIncompatibilityImpossibleRange() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
    Collection<Object> data = new ArrayList<Object>();
    Pattern pattern1 = VerifierComponentMockFactory.createPattern1();
    Pattern pattern2 = VerifierComponentMockFactory.createPattern2();
    /*
         * Working pair
         */
    LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern1, "10");
    r1.setOperator(Operator.BuiltInOperator.GREATER.getOperator());
    r1.setFieldPath("0");
    r1.setOrderNumber(0);
    LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern1, "10");
    r2.setOperator(Operator.BuiltInOperator.LESS.getOperator());
    r2.setFieldPath("0");
    r2.setOrderNumber(1);
    /*
         * Pair that doesn't work.
         */
    LiteralRestriction r3 = LiteralRestriction.createRestriction(pattern2, "1");
    r3.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
    r3.setFieldPath("1");
    r3.setOrderNumber(0);
    LiteralRestriction r4 = LiteralRestriction.createRestriction(pattern2, "");
    r4.setOperator(Operator.BuiltInOperator.EQUAL.getOperator());
    r4.setFieldPath("1");
    r4.setOrderNumber(1);
    data.add(r1);
    data.add(r2);
    data.add(r3);
    data.add(r4);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Incompatible LiteralRestrictions with ranges in pattern possibility, impossible range"));
    Map<Cause, Set<Cause>> map = createIncompatibilityMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
    assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
    if (!map.isEmpty()) {
        fail("More incompatibilities than was expected.");
    }
}
Also used : LiteralRestriction(org.drools.verifier.components.LiteralRestriction) Pattern(org.drools.verifier.components.Pattern) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Set(java.util.Set) Cause(org.drools.verifier.report.components.Cause) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 4 with LiteralRestriction

use of org.drools.verifier.components.LiteralRestriction in project drools by kiegroup.

the class MissingEqualityTest method testMissingEqualityInLiteralRestrictions.

@Test
public void testMissingEqualityInLiteralRestrictions() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("MissingEquality.drl"));
    VerifierReport result = VerifierReportFactory.newVerifierReport();
    Collection<? extends Object> testData = getTestData(this.getClass().getResourceAsStream("MissingEqualityTest.drl"), result.getVerifierData());
    session.setGlobal("result", result);
    for (Object o : testData) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Missing restriction in LiteralRestrictions"));
    Iterator<VerifierMessageBase> iter = result.getBySeverity(Severity.WARNING).iterator();
    Collection<String> ruleNames = new ArrayList<String>();
    while (iter.hasNext()) {
        Object o = (Object) iter.next();
        if (o instanceof VerifierMessage) {
            Cause cause = ((VerifierMessage) o).getFaulty();
            String name = ((LiteralRestriction) cause).getRuleName();
            ruleNames.add(name);
        }
    }
    assertTrue(ruleNames.remove("Missing equality 1"));
    assertTrue(ruleNames.remove("Missing equality 2"));
    if (!ruleNames.isEmpty()) {
        for (String string : ruleNames) {
            fail("Rule " + string + " caused an error.");
        }
    }
}
Also used : LiteralRestriction(org.drools.verifier.components.LiteralRestriction) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) VerifierMessage(org.drools.verifier.report.components.VerifierMessage) VerifierMessageBase(org.drools.verifier.report.components.VerifierMessageBase) VerifierReport(org.drools.verifier.data.VerifierReport) Cause(org.drools.verifier.report.components.Cause) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 5 with LiteralRestriction

use of org.drools.verifier.components.LiteralRestriction in project drools by kiegroup.

the class OppositeRestrictionsTest method testLiteralRestrictionOppositeWithRangesGreaterOrEqualAndLess.

@Test
public void testLiteralRestrictionOppositeWithRangesGreaterOrEqualAndLess() throws Exception {
    KieSession session = getStatelessKieSession(this.getClass().getResourceAsStream("Restrictions.drl"));
    Collection<Object> data = new ArrayList<Object>();
    Pattern pattern = VerifierComponentMockFactory.createPattern1();
    LiteralRestriction r1 = LiteralRestriction.createRestriction(pattern, "1");
    r1.setFieldPath("0");
    r1.setOperator(Operator.BuiltInOperator.GREATER_OR_EQUAL.getOperator());
    r1.setOrderNumber(0);
    LiteralRestriction r2 = LiteralRestriction.createRestriction(pattern, "1");
    r2.setFieldPath("0");
    r2.setOperator(Operator.BuiltInOperator.LESS.getOperator());
    r2.setOrderNumber(1);
    data.add(r1);
    data.add(r2);
    for (Object o : data) {
        session.insert(o);
    }
    session.fireAllRules(new RuleNameMatchesAgendaFilter("Opposite LiteralRestrictions with ranges, greater or equal - less"));
    Map<Cause, Set<Cause>> map = createOppositesMap(VerifierComponentType.RESTRICTION, (Iterator<Object>) session.getObjects().iterator());
    assertTrue((TestBaseOld.causeMapContains(map, r1, r2) ^ TestBaseOld.causeMapContains(map, r2, r1)));
    if (!map.isEmpty()) {
        fail("More opposites than was expected.");
    }
}
Also used : LiteralRestriction(org.drools.verifier.components.LiteralRestriction) Pattern(org.drools.verifier.components.Pattern) RuleNameMatchesAgendaFilter(org.drools.core.base.RuleNameMatchesAgendaFilter) Set(java.util.Set) Cause(org.drools.verifier.report.components.Cause) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Aggregations

LiteralRestriction (org.drools.verifier.components.LiteralRestriction)18 Test (org.junit.Test)16 Set (java.util.Set)15 Pattern (org.drools.verifier.components.Pattern)15 RuleNameMatchesAgendaFilter (org.drools.core.base.RuleNameMatchesAgendaFilter)8 Cause (org.drools.verifier.report.components.Cause)8 KieSession (org.kie.api.runtime.KieSession)8 ArrayList (java.util.ArrayList)7 VerifierReport (org.drools.verifier.data.VerifierReport)1 VerifierMessage (org.drools.verifier.report.components.VerifierMessage)1 VerifierMessageBase (org.drools.verifier.report.components.VerifierMessageBase)1