/**
   * Test that the {@link PersonJournalEntryController#get(UUID, UUID)} action returns the correct
   * validation errors when an invalid ID is sent.
   *
   * @throws ObjectNotFoundException Should not be thrown for this test.
   * @throws ValidationException Should not be thrown for this test.
   */
  @Test(expected = ObjectNotFoundException.class)
  public void testControllerGet() throws ObjectNotFoundException, ValidationException {
    final JournalEntryTO journalEntry = controller.get(PERSON_ID, JOURNAL_ENTRY_ID);

    assertNull("Returned JournalEntryTO from the controller should have been null.", journalEntry);
    assertEquals(
        "Detail list count did not match.", 2, journalEntry.getJournalEntryDetails().size());
  }
  /**
   * Test that the {@link PersonJournalEntryController#get(UUID, UUID)} action returns the correct
   * validation errors when an invalid ID is sent.
   *
   * @throws ObjectNotFoundException Should not be thrown for this test.
   * @throws ValidationException Should not be thrown for this test.
   */
  @Test(expected = ObjectNotFoundException.class)
  public void testControllerGetOfInvalidId() throws ObjectNotFoundException, ValidationException {
    assertNotNull(
        "Controller under test was not initialized by the container correctly.", controller);

    final JournalEntryTO obj = controller.get(PERSON_ID, UUID.randomUUID());

    assertNull("Returned JournalEntryTO from the controller should have been null.", obj);
  }
  /**
   * Test the {@link PersonJournalEntryController#create(UUID, JournalEntryTO)} action.
   *
   * @throws ObjectNotFoundException Should not be thrown for this test.
   * @throws ValidationException Should not be thrown for this test.
   */
  @Test()
  public void testControllerCreateMultiple() throws ValidationException, ObjectNotFoundException {
    // 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 ReferenceLiteTO<JournalStep> journalStep =
        new ReferenceLiteTO<JournalStep>(JOURNAL_STEP_ID, "");
    final Set<JournalEntryDetailTO> journalEntryDetails = Sets.newHashSet();
    final Set<ReferenceLiteTO<JournalStepDetail>> details = Sets.newHashSet();

    final JournalEntryDetailTO journalEntryDetail = new JournalEntryDetailTO();
    journalEntryDetail.setJournalStep(journalStep);
    details.add(new ReferenceLiteTO<JournalStepDetail>(JOURNAL_STEP_DETAIL_ID, ""));

    final JournalEntryDetailTO journalEntryDetail2 = new JournalEntryDetailTO();
    journalEntryDetail2.setJournalStep(journalStep);
    details.add(new ReferenceLiteTO<JournalStepDetail>(JOURNAL_STEP_DETAIL_ID2, ""));

    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("PersonIds did not match.", PERSON_ID, saved.getPersonId());
    assertFalse(
        "JournalEntryDetails should have had entries.", saved.getJournalEntryDetails().isEmpty());

    session.clear();

    final JournalEntryTO reloaded = controller.get(savedId, PERSON_ID);
    assertFalse(
        "JournalEntryDetails should have had entries.",
        reloaded.getJournalEntryDetails().isEmpty());
    assertEquals(
        "Details list did not have the expected item count.",
        2,
        reloaded.getJournalEntryDetails().size());
  }
  /**
   * Test the {@link PersonJournalEntryController#create(UUID, JournalEntryTO)} action using a null
   * JournalTrack.
   *
   * @throws ObjectNotFoundException Should not be thrown for this test.
   * @throws ValidationException Should not be thrown for this test.
   */
  @Test()
  public void testControllerCreateWithoutTrack()
      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.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("PersonIds did not match.", PERSON_ID, saved.getPersonId());

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

    final JournalEntryTO reloaded = controller.get(savedId, PERSON_ID);
    assertNotNull("Reloaded entry should not have been null.", reloaded);
    assertNull("Track should have been null.", reloaded.getJournalTrack());
  }
  /**
   * 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
    }
  }