Search in sources :

Example 1 with StringRestriction

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

the class ExprConstraintDescrVisitorTest method testVisitVariableRestriction.

@Test
public void testVisitVariableRestriction() throws Exception {
    PackageDescr packageDescr = getPackageDescr(getClass().getResourceAsStream("ExprConstraintDescr3.drl"));
    assertNotNull(packageDescr);
    packageDescrVisitor.visitPackageDescr(packageDescr);
    Collection<StringRestriction> allRestrictions = verifierData.getAll(VerifierComponentType.RESTRICTION);
    assertEquals(1, allRestrictions.size());
    assertContainsFields(1);
    assertContainsField("age");
    assertContainsVariable("Test 1", "var");
    assertContainsVariableRestriction(Operator.BuiltInOperator.EQUAL.getOperator(), "var");
}
Also used : StringRestriction(org.drools.verifier.components.StringRestriction) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 2 with StringRestriction

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

the class ExprConstraintDescrVisitorTest method testVisitPerson.

@Test
public void testVisitPerson() throws Exception {
    PackageDescr packageDescr = getPackageDescr(getClass().getResourceAsStream("ExprConstraintDescr1.drl"));
    assertNotNull(packageDescr);
    packageDescrVisitor.visitPackageDescr(packageDescr);
    Collection<StringRestriction> allRestrictions = verifierData.getAll(VerifierComponentType.RESTRICTION);
    Collection<Field> allFields = verifierData.getAll(VerifierComponentType.FIELD);
    assertEquals(3, allRestrictions.size());
    assertEquals(3, allFields.size());
    for (Field field : allFields) {
        assertNotNull(field.getFieldType());
    }
    assertContainsField("name");
    assertContainsField("lastName");
    assertContainsField("age");
    assertContainsStringRestriction(Operator.BuiltInOperator.EQUAL.getOperator(), "toni");
    assertContainsStringRestriction(Operator.BuiltInOperator.NOT_EQUAL.getOperator(), "Lake");
    assertContainsNumberRestriction(Operator.BuiltInOperator.GREATER.getOperator(), 20);
    assertContainsEval("eval( true )");
}
Also used : Field(org.drools.verifier.components.Field) StringRestriction(org.drools.verifier.components.StringRestriction) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 3 with StringRestriction

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

the class ExprConstraintDescrVisitorTest method testVisitAnd.

@Test
public void testVisitAnd() throws Exception {
    PackageDescr packageDescr = getPackageDescr(getClass().getResourceAsStream("ExprConstraintDescr2.drl"));
    assertNotNull(packageDescr);
    packageDescrVisitor.visitPackageDescr(packageDescr);
    Collection<StringRestriction> allRestrictions = verifierData.getAll(VerifierComponentType.RESTRICTION);
    assertEquals(2, allRestrictions.size());
    assertContainsFields(1);
    assertContainsField("age");
    assertContainsNumberRestriction(Operator.BuiltInOperator.GREATER.getOperator(), 0);
    assertContainsNumberRestriction(Operator.BuiltInOperator.LESS.getOperator(), 100);
}
Also used : StringRestriction(org.drools.verifier.components.StringRestriction) PackageDescr(org.drools.drl.ast.descr.PackageDescr) Test(org.junit.Test)

Example 4 with StringRestriction

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

the class ExprConstraintDescrVisitorTest method assertContainsStringRestriction.

private void assertContainsStringRestriction(Operator operator, String value) {
    Collection<Restriction> allRestrictions = verifierData.getAll(VerifierComponentType.RESTRICTION);
    for (Restriction restriction : allRestrictions) {
        if (restriction instanceof StringRestriction) {
            StringRestriction stringLiteral = (StringRestriction) restriction;
            if (value.equals(stringLiteral.getValueAsString()) && operator.equals(stringLiteral.getOperator())) {
                return;
            }
        }
    }
    fail(String.format("Could not find StringRestriction: Operator : %s Value: %s", operator, value));
}
Also used : Restriction(org.drools.verifier.components.Restriction) NumberRestriction(org.drools.verifier.components.NumberRestriction) StringRestriction(org.drools.verifier.components.StringRestriction) VariableRestriction(org.drools.verifier.components.VariableRestriction) StringRestriction(org.drools.verifier.components.StringRestriction)

Aggregations

StringRestriction (org.drools.verifier.components.StringRestriction)4 PackageDescr (org.drools.drl.ast.descr.PackageDescr)3 Test (org.junit.Test)3 Field (org.drools.verifier.components.Field)1 NumberRestriction (org.drools.verifier.components.NumberRestriction)1 Restriction (org.drools.verifier.components.Restriction)1 VariableRestriction (org.drools.verifier.components.VariableRestriction)1