/** * 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 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); }
String newDesc = "new desc"; tag.setName(newName); tag.setDescription(newDesc);
/** * @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()); }
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")); } }
/** * 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()); }