Search in sources :

Example 11 with ImplementationId

use of org.openmrs.ImplementationId in project openmrs-core by openmrs.

the class AdministrationServiceTest method setImplementationId_shouldThrowAPIExceptionIfGivenACaretInTheImplementationIdCode.

/**
 * This uses a try/catch so that we can make sure no blank id is saved to the database.
 *
 * @see AdministrationService#setImplementationId(ImplementationId)
 */
@Test
public void setImplementationId_shouldThrowAPIExceptionIfGivenACaretInTheImplementationIdCode() {
    // save an impl id with an invalid hl7 code
    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");
    try {
        adminService.setImplementationId(invalidId);
        fail("An exception should be thrown on an invalid impl id save");
    } catch (APIException e) {
    // expected exception
    }
    ImplementationId afterInvalid = adminService.getImplementationId();
    assertNull("There shouldn't be an impl id defined after setting an invalid impl id", afterInvalid);
}
Also used : ImplementationId(org.openmrs.ImplementationId) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 12 with ImplementationId

use of org.openmrs.ImplementationId in project openmrs-core by openmrs.

the class AdministrationServiceTest method setImplementationId_shouldSetUuidOnImplementationIdGlobalProperty.

/**
 * @see AdministrationService#setImplementationId(ImplementationId)
 */
@Test
@Ignore
public void setImplementationId_shouldSetUuidOnImplementationIdGlobalProperty() {
    ImplementationId validId = new ImplementationId();
    validId.setImplementationId("JUNIT-TEST");
    validId.setName("JUNIT-TEST implementation id");
    validId.setPassphrase("This is the junit test passphrase");
    validId.setDescription("This is the junit impl id used for testing of the openmrs API only.");
    adminService.setImplementationId(validId);
    GlobalProperty gp = adminService.getGlobalPropertyObject(OpenmrsConstants.GLOBAL_PROPERTY_IMPLEMENTATION_ID);
    Assert.assertNotNull(gp.getUuid());
}
Also used : ImplementationId(org.openmrs.ImplementationId) GlobalProperty(org.openmrs.GlobalProperty) Ignore(org.junit.Ignore) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 13 with ImplementationId

use of org.openmrs.ImplementationId in project openmrs-core by openmrs.

the class ImplementationIdValidatorTest method validate_shouldFailValidationIfImplementationIdIsNull.

/**
 * @see ImplementationIdValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfImplementationIdIsNull() {
    ImplementationId implementationId = new ImplementationId();
    implementationId.setPassphrase("PASSPHRASE");
    implementationId.setDescription("Description");
    Errors errors = new BindException(implementationId, "implementationId");
    new ImplementationIdValidator().validate(implementationId, errors);
    Assert.assertTrue(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 14 with ImplementationId

use of org.openmrs.ImplementationId in project openmrs-core by openmrs.

the class ImplementationIdValidatorTest method validate_shouldPassValidationIfDescriptionIsNull.

/**
 * @see ImplementationIdValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfDescriptionIsNull() {
    ImplementationId implementationId = new ImplementationId();
    implementationId.setImplementationId("IMPL_ID");
    implementationId.setPassphrase("PASSPHRASE");
    Errors errors = new BindException(implementationId, "implementationId");
    new ImplementationIdValidator().validate(implementationId, errors);
    Assert.assertFalse(errors.hasFieldErrors("description"));
    Assert.assertFalse(errors.hasFieldErrors("implementationId"));
    Assert.assertFalse(errors.hasFieldErrors("passphrase"));
}
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 15 with ImplementationId

use of org.openmrs.ImplementationId in project openmrs-core by openmrs.

the class ImplementationIdValidatorTest method validate_shouldFailIfGivenEmptyImplementationIdObject.

/**
 * @see ImplementationIdValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailIfGivenEmptyImplementationIdObject() {
    // save a blank impl id. exception thrown
    ImplementationId implementationId = new ImplementationId();
    Errors errors = new BindException(implementationId, "implementationId");
    new ImplementationIdValidator().validate(implementationId, errors);
    Assert.assertTrue(errors.hasFieldErrors("passphrase"));
    Assert.assertTrue(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)

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