/** * Test that the {@link PersonProgramStatusController#create(UUID, PersonProgramStatusTO)} action * prohibits duplicates correctly. * * @throws ValidationException If validation error occurred. * @throws ObjectNotFoundException If object could not be found. */ @Test(expected = ValidationException.class) public void testControllerCreateDuplicateProhibition() throws ValidationException, ObjectNotFoundException { final Date now = new Date(); final PersonProgramStatusTO obj = createProgramStatus(); obj.setEffectiveDate(now); final PersonProgramStatusTO saved = controller.create(PERSON_ID, obj); final UUID savedId = saved.getId(); assertEquals("Saved instance values did not match.", now, saved.getEffectiveDate()); assertEquals( "Saved instance sets did not match.", PROGRAM_STATUS_CHANGE_REASON_ID, saved.getProgramStatusChangeReasonId()); final PersonProgramStatusTO obj2 = createProgramStatus(); final PersonProgramStatusTO saved2 = controller.create(PERSON_ID, obj2); assertNotNull("Saved instance should not have been null.", saved2); final PersonProgramStatusTO autoExpired = controller.get(savedId, PERSON_ID); assertNotNull("Saved instance identifier should not have been null.", autoExpired); assertNotNull( "Original instance should have been auto-expired when new one added.", autoExpired.getExpirationDate()); saved2.setExpirationDate(null); controller.save(saved2.getId(), PERSON_ID, saved2); }
/** * Test the {@link PersonProgramStatusController#create(UUID, PersonProgramStatusTO)} and {@link * PersonProgramStatusController#delete(UUID, UUID)} actions. * * @throws ValidationException If validation error occurred. * @throws ObjectNotFoundException If object could not be found. */ @Test(expected = ObjectNotFoundException.class) public void testControllerDelete() throws ValidationException, ObjectNotFoundException { final Date now = new Date(); final PersonProgramStatusTO obj = createProgramStatus(); obj.setEffectiveDate(now); final PersonProgramStatusTO saved = controller.create(PERSON_ID, obj); assertNotNull("Saved instance should not have been null.", saved); final UUID savedId = saved.getId(); assertNotNull("Saved instance identifier should not have been null.", savedId); assertEquals("Saved instance values did not match.", now, saved.getEffectiveDate()); assertEquals( "Saved instance sets did not match.", PROGRAM_STATUS_CHANGE_REASON_ID, saved.getProgramStatusChangeReasonId()); final ServiceResponse response = controller.delete(savedId, PERSON_ID); assertNotNull("Deletion response should not have been null.", response); assertTrue("Deletion response did not return success.", response.isSuccess()); final PersonProgramStatusTO afterDeletion = controller.get(savedId, PERSON_ID); // ObjectNotFoundException expected at this point assertNull( "Instance should not be able to get loaded after it has been deleted.", afterDeletion); }
@Test(expected = ValidationException.class) public void testControllerCreateWithInvalidDataGetId() throws ValidationException, ObjectNotFoundException { final PersonProgramStatusTO obj = new PersonProgramStatusTO(); obj.setId(UUID.randomUUID()); obj.setEffectiveDate(null); controller.create(UUID.randomUUID(), obj); fail("Create with invalid Person UUID should have thrown exception."); }