本文整理汇总了Java中org.kuali.rice.krad.datadictionary.validation.processor.MustOccurConstraintProcessor类的典型用法代码示例。如果您正苦于以下问题:Java MustOccurConstraintProcessor类的具体用法?Java MustOccurConstraintProcessor怎么用?Java MustOccurConstraintProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MustOccurConstraintProcessor类属于org.kuali.rice.krad.datadictionary.validation.processor包,在下文中一共展示了MustOccurConstraintProcessor类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNoStateNoZipUSAddress
import org.kuali.rice.krad.datadictionary.validation.processor.MustOccurConstraintProcessor; //导入依赖的package包/类
@Test
/**
* test that the error produced for an invalid US address has the expected attributes
*
* <p>Address has a must occur constraint where either the postal code must be entered or _both_ the city and state</p>
*
* @see DictionaryValidationServiceImpl#validate(Object, String, String, boolean)
* @see ConstraintValidationResult
* @see org.kuali.rice.krad.datadictionary.validation.constraint.MustOccurConstraint
*/
public void testNoStateNoZipUSAddress() {
DictionaryValidationResult dictionaryValidationResult = service.validate(noZipNoCityUSAddress,
"org.kuali.rice.krad.datadictionary.validation.Address", addressEntry, true);
Assert.assertEquals(0, dictionaryValidationResult.getNumberOfWarnings());
Assert.assertEquals(1, dictionaryValidationResult.getNumberOfErrors());
if (dictionaryValidationResult.getNumberOfErrors() > 0) {
for (Iterator<ConstraintValidationResult> iterator = dictionaryValidationResult.iterator();
iterator.hasNext(); ) {
ConstraintValidationResult constraintValidationResult = iterator.next();
if (constraintValidationResult.getStatus().getLevel() >= ErrorLevel.WARN.getLevel()) {
// The top level error should be an occurs error
Assert.assertEquals(ErrorLevel.ERROR, constraintValidationResult.getStatus());
Assert.assertEquals("error.occurs", constraintValidationResult.getErrorKey());
// It should have two children
List<ConstraintValidationResult> children = constraintValidationResult.getChildren();
Assert.assertNotNull(children);
Assert.assertEquals(2, children.size());
// The first child should have it's own child
ConstraintValidationResult child1 = children.get(0);
ConstraintValidationResult child2 = children.get(1);
Assert.assertEquals("error.requiresField", child1.getErrorKey());
Assert.assertArrayEquals(new String[]{"postalCode"}, child1.getErrorParameters());
List<ConstraintValidationResult> grandchildren = child2.getChildren();
Assert.assertNotNull(grandchildren);
Assert.assertEquals(2, grandchildren.size());
ConstraintValidationResult grandchild1 = grandchildren.get(0);
Assert.assertEquals(ErrorLevel.ERROR, grandchild1.getStatus());
Assert.assertEquals("error.requiresField", grandchild1.getErrorKey());
Assert.assertArrayEquals(new String[]{"city"}, grandchild1.getErrorParameters());
ConstraintValidationResult grandchild2 = grandchildren.get(1);
Assert.assertEquals(ErrorLevel.OK, grandchild2.getStatus());
Assert.assertEquals(new MustOccurConstraintProcessor().getName(), grandchild2.getConstraintName());
}
}
}
}