/**
   * 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);
  }
コード例 #2
0
  /**
   * Test the {@link PersonJournalEntryController#create(UUID, JournalEntryTO)} and {@link
   * PersonJournalEntryController#delete(UUID, UUID)} actions.
   *
   * @throws ObjectNotFoundException Should not be thrown for this test.
   * @throws ValidationException Should not be thrown for this test.
   */
  @Test()
  public void testControllerCreateAndDelete() throws ObjectNotFoundException, ValidationException {
    // Now create JournalEntry for testing
    final JournalEntryTO obj = new JournalEntryTO();
    obj.setPersonId(PERSON_ID);
    obj.setEntryDate(new Date());
    obj.setJournalSource(
        new ReferenceLiteTO<JournalSource>(
            UUID.fromString("b2d07973-5056-a51a-8073-1d3641ce507f"), ""));
    obj.setJournalTrack(
        new ReferenceLiteTO<JournalTrack>(
            UUID.fromString("b2d07a7d-5056-a51a-80a8-96ae5188a188"), ""));
    obj.setConfidentialityLevel(new ConfidentialityLevelLiteTO(CONFIDENTIALITY_LEVEL_ID, ""));
    obj.setObjectStatus(ObjectStatus.ACTIVE);

    final Set<JournalEntryDetailTO> journalEntryDetails = Sets.newHashSet();
    final JournalEntryDetailTO journalEntryDetail = new JournalEntryDetailTO();
    journalEntryDetail.setJournalStep(new ReferenceLiteTO<JournalStep>(JOURNAL_STEP_ID, ""));
    final Set<ReferenceLiteTO<JournalStepDetail>> details = Sets.newHashSet();
    details.add(new ReferenceLiteTO<JournalStepDetail>(JOURNAL_STEP_DETAIL_ID, ""));
    journalEntryDetail.setJournalStepDetails(details);
    journalEntryDetails.add(journalEntryDetail);
    obj.setJournalEntryDetails(journalEntryDetails);

    final JournalEntryTO saved = controller.create(PERSON_ID, obj);
    final Session session = sessionFactory.getCurrentSession();
    session.flush();

    final UUID savedId = saved.getId();
    assertNotNull("Saved instance identifier should not have been null.", savedId);
    assertEquals("Person identifiers don't match.", PERSON_ID, saved.getPersonId());
    assertFalse(
        "JournalEntryDetails should not have been empty.",
        saved.getJournalEntryDetails().isEmpty());

    session.flush();
    session.clear();

    final JournalEntryTO reloaded = controller.get(savedId, PERSON_ID);
    assertFalse(
        "JournalEntryDetails should not have been empty.",
        reloaded.getJournalEntryDetails().isEmpty());

    // Try save (update)
    final JournalEntryDetailTO journalEntryDetail2 = new JournalEntryDetailTO();
    journalEntryDetail2.setJournalStep(new ReferenceLiteTO<JournalStep>(JOURNAL_STEP_ID, ""));
    final Set<ReferenceLiteTO<JournalStepDetail>> details2 = Sets.newHashSet();
    details2.add(new ReferenceLiteTO<JournalStepDetail>(JOURNAL_STEP_DETAIL_ID, ""));
    journalEntryDetail2.setJournalStepDetails(details2);
    journalEntryDetails.add(journalEntryDetail2);
    reloaded.getJournalEntryDetails().add(journalEntryDetail2);

    final JournalEntryTO updated = controller.save(savedId, PERSON_ID, reloaded);
    session.flush();

    assertEquals("Saved instance identifiers do not match.", savedId, updated.getId());
    assertEquals("PersonIds did not match.", PERSON_ID, updated.getPersonId());
    assertFalse(
        "JournalEntryDetails should have had entries.", updated.getJournalEntryDetails().isEmpty());

    session.flush();
    session.clear();

    final JournalEntryTO reloadedAgain = controller.get(savedId, PERSON_ID);
    assertEquals(
        "JournalEntryDetails did not have the expected number of entries.",
        2,
        reloadedAgain.getJournalEntryDetails().size());

    // finally delete
    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());

    try {
      // ObjectNotFoundException expected at this point
      final JournalEntryTO afterDeletion = controller.get(savedId, PERSON_ID);
      assertNull(
          "Instance should not be able to get loaded after it has been deleted.", afterDeletion);
    } catch (final ObjectNotFoundException exc) { // NOPMD by jon.adams
      // expected
    }
  }