/** * @see org.openmrs.api.LocationService#retireLocationTag(LocationTag, String) */ @Override public LocationTag retireLocationTag(LocationTag tag, String reason) throws APIException { if (tag.getRetired()) { return tag; } else { if (reason == null) { throw new APIException("Location.retired.reason.required", (Object[]) null); } tag.setRetired(true); tag.setRetireReason(reason); tag.setRetiredBy(Context.getAuthenticatedUser()); tag.setDateRetired(new Date()); return Context.getLocationService().saveLocationTag(tag); } }
/** * @see LocationService#unretireLocationTag(LocationTag) */ @Test public void unretireLocationTag_shouldUnretireRetiredLocationTag() { LocationService ls = Context.getLocationService(); LocationTag tag = ls.getLocationTagByName("Test Retired Tag"); Assert.assertTrue(tag.getRetired()); LocationTag newTag = ls.unretireLocationTag(tag); Assert.assertEquals(tag, newTag); Assert.assertFalse(tag.getRetired()); Assert.assertNull(tag.getRetiredBy()); Assert.assertNull(tag.getRetireReason()); }
assertTrue(retiredTag.getRetired()); assertNotNull(retiredTag.getDateRetired()); assertEquals(Context.getAuthenticatedUser(), retiredTag.getRetiredBy());
/** * @see LocationService#retireLocationTag(LocationTag,String) */ @Test public void retireLocationTag_shouldRetireLocationTagWithGivenReason() { LocationService ls = Context.getLocationService(); LocationTag tag = ls.getLocationTag(1); Assert.assertFalse(tag.getRetired()); String reason = "because i can"; LocationTag newTag = ls.retireLocationTag(tag, reason); Assert.assertEquals(tag, newTag); Assert.assertTrue(tag.getRetired()); Assert.assertEquals(reason, tag.getRetireReason()); }
/** * @see LocationService#retireLocation(Location location, String reason) */ @Test public void retireLocation_shouldNotRetireIndependentField() { LocationService locationService = Context.getLocationService(); Location location = new Location(1); location.setName("location to retire"); LocationTag tag = new LocationTag(1); location.addTag(tag); locationService.retireLocation(location, "test retire reason"); Assert.assertFalse(tag.getRetired()); }