Search in sources :

Example 6 with ImplementationId

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");
        }
    }
}
Also used : ImplementationId(org.openmrs.ImplementationId) APIException(org.openmrs.api.APIException)

Example 7 with ImplementationId

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"));
}
Also used : ImplementationId(org.openmrs.ImplementationId) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with ImplementationId

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"));
}
Also used : ImplementationId(org.openmrs.ImplementationId) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with ImplementationId

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());
}
Also used : ImplementationId(org.openmrs.ImplementationId) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with ImplementationId

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());
}
Also used : ImplementationId(org.openmrs.ImplementationId) Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

ImplementationId (org.openmrs.ImplementationId)15 Test (org.junit.Test)14 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)14 BindException (org.springframework.validation.BindException)7 Errors (org.springframework.validation.Errors)7 Ignore (org.junit.Ignore)3 GlobalProperty (org.openmrs.GlobalProperty)1 APIException (org.openmrs.api.APIException)1