Package org.springframework.rules.constraint.property

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


    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

TOP

Related Classes of org.springframework.rules.constraint.property.RequiredIfOthersPresent

Copyright © 2018 www.massapicom. 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.