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