Search in sources :

Example 6 with LocationAttributeType

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

the class LocationAttributeTypeValidatorTest method validate_shouldPassValidationIfFieldLengthsAreCorrect.

/**
 * @see LocationAttributeTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfFieldLengthsAreCorrect() {
    LocationAttributeType type = new LocationAttributeType();
    type.setName("name");
    type.setDatatypeClassname("org.openmrs.customdatatype.datatype.FreeTextDatatype");
    type.setDescription("description");
    type.setRetireReason("retireReason");
    Errors errors = new BindException(type, "type");
    new LocationAttributeTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 7 with LocationAttributeType

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

the class LocationServiceTest method unretireLocationAttributeType_shouldUnretireARetiredLocationAttributeType.

/**
 * @see LocationService#unretireLocationAttributeType(LocationAttributeType)
 */
@Test
public void unretireLocationAttributeType_shouldUnretireARetiredLocationAttributeType() {
    executeDataSet(LOC_ATTRIBUTE_DATA_XML);
    LocationService service = Context.getLocationService();
    LocationAttributeType lat = service.getLocationAttributeType(2);
    Assert.assertTrue(lat.getRetired());
    Assert.assertNotNull(lat.getDateRetired());
    Assert.assertNotNull(lat.getRetiredBy());
    Assert.assertNotNull(lat.getRetireReason());
    service.unretireLocationAttributeType(lat);
    Assert.assertFalse(lat.getRetired());
    Assert.assertNull(lat.getDateRetired());
    Assert.assertNull(lat.getRetiredBy());
    Assert.assertNull(lat.getRetireReason());
}
Also used : LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with LocationAttributeType

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

the class LocationServiceTest method saveLocationAttributeType_shouldEditAnExistingLocationAttributeType.

/**
 * @see LocationService#saveLocationAttributeType(LocationAttributeType)
 */
@Test
public void saveLocationAttributeType_shouldEditAnExistingLocationAttributeType() {
    executeDataSet(LOC_ATTRIBUTE_DATA_XML);
    LocationService service = Context.getLocationService();
    Assert.assertEquals(2, service.getAllLocationAttributeTypes().size());
    LocationAttributeType lat = service.getLocationAttributeType(1);
    lat.setName("A new name");
    service.saveLocationAttributeType(lat);
    Assert.assertEquals(2, service.getAllLocationAttributeTypes().size());
    Assert.assertEquals("A new name", service.getLocationAttributeType(1).getName());
}
Also used : LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with LocationAttributeType

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

the class LocationServiceTest method getLocationAttributeTypeByName_shouldReturnTheLocationAttributeTypeWithTheSpecifiedName.

/**
 * @see LocationService#getLocationAttributeTypeByName(String)
 */
@Test
public void getLocationAttributeTypeByName_shouldReturnTheLocationAttributeTypeWithTheSpecifiedName() {
    executeDataSet(LOC_ATTRIBUTE_DATA_XML);
    LocationAttributeType locationAttributeType = Context.getLocationService().getLocationAttributeTypeByName("Audit Date");
    Assert.assertNotNull(locationAttributeType);
    Assert.assertEquals("Audit Date", locationAttributeType.getName());
}
Also used : LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with LocationAttributeType

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

the class LocationServiceTest method saveLocationAttributeType_shouldCreateANewLocationAttributeType.

/**
 * @see LocationService#saveLocationAttributeType(LocationAttributeType)
 */
@Test
public void saveLocationAttributeType_shouldCreateANewLocationAttributeType() {
    executeDataSet(LOC_ATTRIBUTE_DATA_XML);
    Assert.assertEquals(2, Context.getLocationService().getAllLocationAttributeTypes().size());
    LocationAttributeType lat = new LocationAttributeType();
    lat.setName("Another one");
    lat.setDatatypeClassname(FreeTextDatatype.class.getName());
    Context.getLocationService().saveLocationAttributeType(lat);
    Assert.assertNotNull(lat.getId());
    Assert.assertEquals(3, Context.getLocationService().getAllLocationAttributeTypes().size());
}
Also used : FreeTextDatatype(org.openmrs.customdatatype.datatype.FreeTextDatatype) LocationAttributeType(org.openmrs.LocationAttributeType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

LocationAttributeType (org.openmrs.LocationAttributeType)16 Test (org.junit.Test)13 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)13 BindException (org.springframework.validation.BindException)6 Errors (org.springframework.validation.Errors)6 HashMap (java.util.HashMap)2 Location (org.openmrs.Location)2 LocationAttribute (org.openmrs.LocationAttribute)2 LocationService (org.openmrs.api.LocationService)1 FreeTextDatatype (org.openmrs.customdatatype.datatype.FreeTextDatatype)1