if (existing != null) { location.removeTag(tag); location.addTag(existing); } else { throw new APIException("Location.cannot.add.transient.tags", (Object[]) null);
/** * @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); }
/** * 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()); }
/** * @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); }
/** * @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()); }
location.addTag(tag); ls.saveLocation(location);