Examples of PropertyConstraint


Examples of org.springframework.rules.constraint.property.PropertyConstraint

    and.add(constraint);
    if (logger.isDebugEnabled()) {
      logger.debug("Putting constraint for property '" + constraint.getPropertyName() + "', constraint -> ["
          + constraint + "]");
    }
        PropertyConstraint compoundConstraint = new CompoundPropertyConstraint(and);
    propertiesConstraints.put(constraint.getPropertyName(), compoundConstraint);
        orderedConstraints.add( compoundConstraint );
  }
View Full Code Here

Examples of org.springframework.rules.constraint.property.PropertyConstraint

    add(new CompoundPropertyConstraint(compoundPredicate));
  }

  public boolean test(Object bean) {
    for (Iterator i = orderedConstraints.iterator(); i.hasNext();) {
      PropertyConstraint propertyConstraint = (PropertyConstraint)i.next();
      if (!propertyConstraint.test(bean)) {
        return false;
      }
    }
    return true;
  }
View Full Code Here

Examples of org.springframework.rules.constraint.property.PropertyConstraint

    assertTrue(req.test(Arrays.asList(new Object[1])));
  }

  public void testRequiredIfOthersPresent() {
    Rules r = new Rules(Person.class);
    PropertyConstraint c = new RequiredIfOthersPresent("zip", "city,state");
    r.add(c);

    // Ensure that it properly reports all property dependencies
    assertTrue(c.isDependentOn("zip"));
    assertTrue(c.isDependentOn("city"));
    assertTrue(c.isDependentOn("state"));

    Person p = new Person();

    assertTrue(r.test(p)); // No city or state, so not required

    p.setCity("city");
    assertTrue(r.test(p)); // Need both city and state, so not required

    p.setState("state");
    assertFalse(r.test(p));

    p.setZip("zip");
    assertTrue(r.test(p));

    // Now test the OR version
    r = new Rules(Person.class);
    c = new RequiredIfOthersPresent("zip", "city,state", LogicalOperator.OR);
    r.add(c);

    assertTrue(c.isDependentOn("zip"));
    assertTrue(c.isDependentOn("city"));
    assertTrue(c.isDependentOn("state"));

    p = new Person();

    assertTrue(r.test(p)); // No city or state, so not required
View Full Code Here

Examples of org.springframework.rules.constraint.property.PropertyConstraint

  public void testBeanPropertyValueConstraint() {
    And p = constraints.conjunction();
    p.add(constraints.required());
    p.add(constraints.maxLength(9));
    PropertyConstraint e = new PropertyValueConstraint("test", p);
    assertTrue(e.test(new TestBean()));

    p = constraints.conjunction();
    e = new PropertyValueConstraint("test", p);
    p.add(constraints.required());
    p.add(constraints.maxLength(3));
    assertFalse(e.test(new TestBean()));
  }
View Full Code Here

Examples of org.springframework.rules.constraint.property.PropertyConstraint

    objectClass = object.getClass();
    Rules rules = null;
    if (object instanceof PropertyConstraintProvider) {
      PropertyConstraintProvider propertyConstraintProvider = (PropertyConstraintProvider) object;
      if (propertyName != null) {
        PropertyConstraint validationRule = propertyConstraintProvider.getPropertyConstraint(propertyName);
        checkRule(validationRule);
      }
      else {
        for (Iterator fieldNamesIter = formModel.getFieldNames().iterator(); fieldNamesIter.hasNext();) {
          PropertyConstraint validationRule = propertyConstraintProvider
              .getPropertyConstraint((String) fieldNamesIter.next());
          checkRule(validationRule);
        }
      }
    }
    else {
      if (getRulesSource() != null) {
        rules = getRulesSource().getRules(objectClass, getRulesContextId());
        if (rules != null) {
          for (Iterator i = rules.iterator(); i.hasNext();) {
            PropertyConstraint validationRule = (PropertyConstraint) i.next();
            if (propertyName == null) {
              if (formModel.hasValueModel(validationRule.getPropertyName())) {
                checkRule(validationRule);
              }
            }
            else if (validationRule.isDependentOn(propertyName)) {
              checkRule(validationRule);
            }
          }
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.