use of org.openmrs.ImplementationId in project openmrs-core by openmrs.
the class ImplementationIdValidator method validate.
/*
* @should should fail validation if implementation id is null
* @should should fail validation if description is null
* @should should fail validation if pass phrase is null
* @should should fail if given empty implementationId object
* @should should fail if given a pipe in the implementationId code
*
*/
@Override
public void validate(Object obj, Errors errors) throws APIException {
ImplementationId implId = (ImplementationId) obj;
char[] illegalChars = { '^', '|' };
if (implId == null) {
throw new APIException("ImplementationId.null", (Object[]) null);
} else {
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "ImplementationId.name.empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "implementationId", "ImplementationId.implementationId.empty");
ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passphrase", "ImplementationId.passphrase.empty");
if (implId.getImplementationId() != null && StringUtils.containsAny(implId.getImplementationId(), illegalChars)) {
errors.rejectValue("implementationId", "ImplementationId.implementationId.invalidCharacter");
}
}
}
use of org.openmrs.ImplementationId in project openmrs-core by openmrs.
the class ImplementationIdValidatorTest method validate_shouldFailValidationIfPassPhraseIsNull.
/**
* @see ImplementationIdValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfPassPhraseIsNull() {
ImplementationId implementationId = new ImplementationId();
implementationId.setImplementationId("IMPL_ID");
implementationId.setDescription("Description");
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);
Assert.assertTrue(errors.hasFieldErrors("passphrase"));
Assert.assertFalse(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("description"));
}
use of org.openmrs.ImplementationId in project openmrs-core by openmrs.
the class ImplementationIdValidatorTest method validate_shouldFailValidationIfNameIsNull.
/**
* @see ImplementationIdValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailValidationIfNameIsNull() {
ImplementationId implementationId = new ImplementationId();
implementationId.setImplementationId("IMPL_ID");
implementationId.setPassphrase("PASSPHRASE");
implementationId.setDescription("Description");
Errors errors = new BindException(implementationId, "implementationId");
new ImplementationIdValidator().validate(implementationId, errors);
Assert.assertTrue(errors.hasFieldErrors("name"));
Assert.assertFalse(errors.hasFieldErrors("implementationId"));
Assert.assertFalse(errors.hasFieldErrors("passphrase"));
Assert.assertFalse(errors.hasFieldErrors("description"));
}
use of org.openmrs.ImplementationId in project openmrs-core by openmrs.
the class ImplementationIdValidatorTest method validate_shouldFailIfGivenAPipeInTheImplementationIdCode.
/**
* @see ImplementationIdValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfGivenAPipeInTheImplementationIdCode() {
// save an impl id with an invalid hl7 code
ImplementationId invalidId2 = new ImplementationId();
invalidId2.setImplementationId("pipe|pipe");
invalidId2.setName("an invalid impl id for a unit test");
invalidId2.setPassphrase("some valid passphrase");
invalidId2.setDescription("Some valid description");
Errors errors = new BindException(invalidId2, "implementationId");
new ImplementationIdValidator().validate(invalidId2, errors);
Assert.assertTrue(errors.hasFieldErrors("implementationId"));
Assert.assertEquals("ImplementationId.implementationId.invalidCharacter", errors.getFieldError("implementationId").getCode());
}
use of org.openmrs.ImplementationId in project openmrs-core by openmrs.
the class ImplementationIdValidatorTest method validate_shouldFailIfGivenACaretInTheImplementationIdCode.
/**
* @see ImplementationIdValidator#validate(Object,Errors)
*/
@Test
public void validate_shouldFailIfGivenACaretInTheImplementationIdCode() {
ImplementationId invalidId = new ImplementationId();
invalidId.setImplementationId("caret^caret");
invalidId.setName("an invalid impl id for a unit test");
invalidId.setPassphrase("some valid passphrase");
invalidId.setDescription("Some valid description");
Errors errors = new BindException(invalidId, "implementationId");
new ImplementationIdValidator().validate(invalidId, errors);
Assert.assertTrue(errors.hasFieldErrors("implementationId"));
Assert.assertEquals("ImplementationId.implementationId.invalidCharacter", errors.getFieldError("implementationId").getCode());
}
Aggregations