use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists.
/**
* You should be able to add a transient tag with an existing tag name.
*
* @see LocationService#saveLocation(Location)
*/
@Test
public void saveLocation_shouldOverwriteTransientTagIfTagWithSameNameExists() {
LocationService ls = Context.getLocationService();
// First, create a new Location
Location location = new Location();
location.setName("name");
location.setDescription("is a location");
// Add a transient tag with an existing name
location.addTag(new LocationTag("General Hospital", null));
ls.saveLocation(location);
Location newSavedLocation = ls.getLocation(location.getLocationId());
// Saved parent location should have exactly 1 tag
assertEquals(1, newSavedLocation.getTags().size());
// Tag must be overwritten with tag with locationTagId == 1
assertNotNull("Location tag should have an ID now", newSavedLocation.getTags().iterator().next().getLocationTagId());
assertEquals(1, newSavedLocation.getTags().iterator().next().getLocationTagId().intValue());
}
use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound.
/**
* @see LocationService#saveLocation(Location)
*/
@Test(expected = APIException.class)
public void saveLocation_shouldThrowAPIExceptionIfTransientTagIsNotFound() {
LocationTag tagWithoutName = new LocationTag("some random tag name", "a nonexistant tag");
Location location = new Location();
location.setName("Some name");
location.setDescription("Some description");
location.addTag(tagWithoutName);
Context.getLocationService().saveLocation(location);
}
use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method retireLocationTag_shouldRetireLocationTagSuccessfully.
/**
* @see LocationService#retireLocationTag(LocationTag,String)
*/
@Test
public void retireLocationTag_shouldRetireLocationTagSuccessfully() {
LocationService ls = Context.getLocationService();
// Get all tags.
List<LocationTag> tagsBeforeRetired = ls.getAllLocationTags(true);
List<LocationTag> tagsNotRetiredBefore = ls.getAllLocationTags(false);
// Get a non-retired tag
LocationTag tag = ls.getLocationTag(1);
LocationTag retiredTag = ls.retireLocationTag(tag, "Just Testing");
// make sure its still the same object
assertEquals(retiredTag, tag);
// Get all tags again.
List<LocationTag> tagsAfterRetired = ls.getAllLocationTags(true);
List<LocationTag> tagsNotRetiredAfter = ls.getAllLocationTags(false);
// Make sure that all the values were filled in
assertTrue(retiredTag.getRetired());
assertNotNull(retiredTag.getDateRetired());
assertEquals(Context.getAuthenticatedUser(), retiredTag.getRetiredBy());
assertEquals("Just Testing", retiredTag.getRetireReason());
// Both tag lists that include retired should be equal.
assertEquals(tagsBeforeRetired, tagsAfterRetired);
// Both tag lists that do not include retired should not be the same.
assertNotSame(tagsNotRetiredBefore, tagsNotRetiredAfter);
}
use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocationTag_shouldThrowAPIExceptionIfTagHasNoName.
/**
* @see LocationService#saveLocationTag(LocationTag)
*/
@Test(expected = APIException.class)
public void saveLocationTag_shouldThrowAPIExceptionIfTagHasNoName() {
LocationTag tagWithoutName = new LocationTag();
Location location = new Location();
location.setName("Some name");
location.setDescription("Some description");
location.addTag(tagWithoutName);
Context.getLocationService().saveLocation(location);
}
use of org.openmrs.LocationTag in project openmrs-core by openmrs.
the class LocationServiceTest method saveLocationTag_shouldUpdateLocationTagSuccessfully.
/**
* Test a simple update to a location tag that is already in the database.
*
* @see LocationService#saveLocationTag(LocationTag)
*/
@Test
public void saveLocationTag_shouldUpdateLocationTagSuccessfully() {
LocationService ls = Context.getLocationService();
// get the location tag from the database
LocationTag tag = ls.getLocationTag(1);
// save the current values for comparison later
String origName = tag.getName();
String origDesc = tag.getDescription();
// add values that are different than the ones in the initialData.xml file
String newName = "new name";
String newDesc = "new desc";
tag.setName(newName);
tag.setDescription(newDesc);
// save to the db
ls.saveLocationTag(tag);
// fetch that encounter from the db
LocationTag newestTag = ls.getLocationTag(tag.getLocationTagId());
assertFalse("The name should be different", origName.equals(newName));
assertTrue("The name should NOT be different", newestTag.getName().equals(newName));
assertFalse("The name should be different", origDesc.equals(newDesc));
assertTrue("The name should NOT be different", newestTag.getDescription().equals(newDesc));
}
Aggregations