/** * @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); }
/** * @see org.openmrs.module.webservices.rest.web.resource.impl.BaseDelegatingResource#newDelegate() */ @Override public LocationTag newDelegate() { return new LocationTag(); }
/** * @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); }
/** * 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#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); }
/** * @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()); }
/** * @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()); }
LocationTag tag = new LocationTag(); tag.setName("tag name"); ls.saveLocationTag(tag);
/** * 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 LocationTagValidator#validate(Object,Errors) */ @Test public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() { LocationTag locationTag = new LocationTag(); locationTag .setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); locationTag .setDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); locationTag .setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text"); Errors errors = new BindException(locationTag, "location"); new LocationTagValidator().validate(locationTag, errors); Assert.assertTrue(errors.hasFieldErrors("name")); Assert.assertTrue(errors.hasFieldErrors("description")); Assert.assertTrue(errors.hasFieldErrors("retireReason")); } }