@Override public String toString() { return getName(); }
/** * @see org.openmrs.OpenmrsObject#getId() */ @Override public Integer getId() { return getLocationTagId(); }
/** * @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); } }
/** * Required values constructor. This is the minimum number of values that must be non-null in * order to have a successful save to the database * * @param name the name of this encounter type * @param description a short description of why this encounter type exists */ public LocationTag(String name, String description) { setName(name); setDescription(description); }
/** * @see org.openmrs.api.LocationService#unretireLocationTag(org.openmrs.LocationTag) */ @Override public LocationTag unretireLocationTag(LocationTag tag) throws APIException { tag.setRetired(false); tag.setRetireReason(null); tag.setRetiredBy(null); tag.setDateRetired(null); return Context.getLocationService().saveLocationTag(tag); }
/** * @see LocationTagValidator#validate(Object, org.springframework.validation.Errors) */ @Test public void validate_shouldPassValidationIfFieldLengthsAreCorrect() { LocationTag locationTag = new LocationTag(); locationTag.setName("name"); locationTag.setDescription("description"); locationTag.setRetireReason("retireReason"); Errors errors = new BindException(locationTag, "locationTag"); new LocationTagValidator().validate(locationTag, errors); Assert.assertFalse(errors.hasErrors()); }
String origName = tag.getName(); String origDesc = tag.getDescription(); String newDesc = "new desc"; tag.setName(newName); tag.setDescription(newDesc); LocationTag newestTag = ls.getLocationTag(tag.getLocationTagId()); 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));
/** * Test to make sure that a simple save to a new location tag gets persisted to the database * * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldCreateLocationTagSuccessfully() { LocationTag tag = new LocationTag(); tag.setName("testing"); tag.setDescription("desc"); LocationService ls = Context.getLocationService(); ls.saveLocationTag(tag); LocationTag newSavedTag = ls.getLocationTag(tag.getLocationTagId()); assertNotNull("The saved tag should have an id now", tag.getLocationTagId()); assertNotNull("We should get back a tag", newSavedTag); assertTrue("The created tag needs to equal the pojo location", tag.equals(newSavedTag)); }
/** * @see LocationService#saveLocationTag(LocationTag) */ @Test(expected = APIException.class) public void saveLocationTag_shouldThrowExceptionIfTagNameIsNull() { LocationTag tag = new LocationTag(); tag.setName(null); tag.setDescription("desc"); Context.getLocationService().saveLocationTag(tag); }
/** * should set audit info if any item in the location tag is edited * * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldSetAuditInfoIfAnyItemInTheLocationTagIsEdited() { LocationService ls = Context.getLocationService(); LocationTag tag = ls.getLocationTag(1); Assert.assertNull(tag.getDateChanged()); Assert.assertNull(tag.getChangedBy()); tag.setName("testing"); tag.setDescription("desc"); LocationTag editedTag = Context.getLocationService().saveLocationTag(tag); Context.flushSession(); Assert.assertNotNull(editedTag.getDateChanged()); Assert.assertNotNull(editedTag.getChangedBy()); }
assertTrue(retiredTag.getRetired()); assertNotNull(retiredTag.getDateRetired()); assertEquals(Context.getAuthenticatedUser(), retiredTag.getRetiredBy()); assertEquals("Just Testing", retiredTag.getRetireReason());
if (tag.getLocationTagId() == null) { if (!StringUtils.hasLength(tag.getName())) { throw new APIException("Location.tag.name.required", (Object[]) null); LocationTag existing = Context.getLocationService().getLocationTagByName(tag.getName()); if (existing != null) { location.removeTag(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()); }
LocationTag tag = new LocationTag(); tag.setName("tag name"); ls.saveLocationTag(tag); assertTrue("Tag must be the previously added tag", newSavedLocation.getTags().iterator().next().equals(tag));
/** * @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()); }
/** * 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()); }
@Test public void shouldGetALocationTagByUuid() throws Exception { LocationTag locationTag = service.getLocationTag(1); MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + locationTag.getUuid()); SimpleObject result = deserialize(handle(req)); Assert.assertNotNull(result); Assert.assertEquals(locationTag.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(locationTag.getName(), PropertyUtils.getProperty(result, "name")); }
@Test public void shouldRetireLocationTag() throws Exception { LocationTag locationTag = service.getLocationTag(2); Assert.assertFalse(locationTag.isRetired()); MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + locationTag.getUuid()); req.addParameter("!purge", ""); req.addParameter("reason", "random reason"); handle(req); LocationTag retiredLocationTag = service.getLocationTag(2); Assert.assertTrue(retiredLocationTag.isRetired()); Assert.assertEquals("random reason", retiredLocationTag.getRetireReason()); }
/** * @see LocationService#saveLocationTag(LocationTag) */ @Test public void saveLocationTag_shouldReturnSavedObject() { LocationTag locationTag = new LocationTag("Some tag name", "Some description"); LocationTag savedLocationTag = Context.getLocationService().saveLocationTag(locationTag); Assert.assertEquals(locationTag, savedLocationTag); }