mutableBooleanType.setEnumeratedConstraint(enumeratedConstraint);
return mutableBooleanType;
}
public void testVerify() {
final MutableStringType stringType = TYPE_FACTORY.createStringType();
// normal case
MutableStringValue stringValue = VALUE_FACTORY.createStringValue();
stringValue.setValue("Foo");
Collection errors = stringType.verify(stringValue);
assertEquals(0, errors.size());
// null value
stringValue = VALUE_FACTORY.createStringValue();
errors = stringType.verify(stringValue);
assertEquals(1, errors.size());
VerificationError error =
(VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_NULL_VALUE,
error.getType());
assertEquals("", error.getLocation());
assertEquals(stringValue, error.getInvalidValue());
assertNull(error.getConstraint());
// invalid type
BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
errors = stringType.verify(booleanValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
error.getType());
assertEquals("", error.getLocation());
assertEquals(booleanValue, error.getInvalidValue());
assertNull(error.getConstraint());
// enumerated constraint
final MutableEnumeratedConstraint enumeratedConstraint =
CONSTRAINT_FACTORY.createEnumeratedConstraint();
final List enumeratedValues =
enumeratedConstraint.getMutableEnumeratedValues();
final MutableStringValue constraintValue =
VALUE_FACTORY.createStringValue();
constraintValue.setValue("one");
enumeratedValues.add(constraintValue.createImmutable());
constraintValue.setValue("two");
enumeratedValues.add(constraintValue.createImmutable());
stringType.setEnumeratedConstraint(enumeratedConstraint);
// check constraint with right value
stringValue.setValue("two");
errors = stringType.verify(stringValue);
assertEquals(0, errors.size());
// check constraint violation
stringValue.setValue("three");
errors = stringType.verify(stringValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("", error.getLocation());