/**
   * Tests <code>{@link CopilotProjectDAOImpl#retrieve(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  public void testRetrieve1() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    CopilotProject result = instance.retrieve(copilotProject1.getId());

    assertCopilotProject(copilotProject1, result);

    result = instance.retrieve(copilotProject2.getId());

    assertCopilotProject(copilotProject2, result);
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#delete(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testDelete2() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setCopilotProjectId(copilotProject.getId());
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);
    hibernateTemplate.save(copilotProject);

    instance.delete(copilotProject.getId());

    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProjectInfo").size());
  }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#update(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testUpdate() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);
    hibernateTemplate.save(copilotProject);

    copilotProject.setCompletionDate(new Date());
    copilotProject.setCustomerFeedback("test customer feedback");
    copilotProject.setCustomerRating(0.9F);
    copilotProject.setPmFeedback("test pm feedback");
    copilotProject.setPmRating(0.9F);

    CopilotProjectInfoType copilotProjectInfoType = TestHelper.createCopilotProjectInfoType();
    hibernateTemplate.save(copilotProjectInfoType);

    CopilotProjectInfo copilotProjectInfo = TestHelper.createCopilotProjectInfo();
    copilotProjectInfo.setInfoType(copilotProjectInfoType);
    copilotProject.getProjectInfos().add(copilotProjectInfo);

    instance.update(copilotProject);

    List<CopilotProject> result =
        (List<CopilotProject>)
            hibernateTemplate.find("from CopilotProject where id = ?", copilotProject.getId());

    assertCopilotProject(copilotProject, result.get(0));
  }
  /**
   * Asserts that the passed {@link CopilotProject} instances are exactly the same.
   *
   * @param copilotProject project to compare
   * @param result project to compare
   */
  private void assertCopilotProject(CopilotProject copilotProject, CopilotProject result) {
    Assert.assertEquals("Invalid CopilotProject id", copilotProject.getId(), result.getId());
    Assert.assertEquals(
        "Invalid CopilotProject status", copilotProject.getStatus(), result.getStatus());

    Assert.assertEquals("Invalid CopilotProject name", copilotProject.getName(), result.getName());
    Assert.assertEquals(
        "Invalid CopilotProject completion date",
        copilotProject.getCompletionDate(),
        result.getCompletionDate());
    Assert.assertEquals(
        "Invalid CopilotProject copilot type",
        copilotProject.getCopilotType(),
        result.getCopilotType());
    Assert.assertEquals(
        "Invalid CopilotProject customer feedback",
        copilotProject.getCustomerFeedback(),
        result.getCustomerFeedback());
    Assert.assertEquals(
        "Invalid CopilotProject customer rating",
        copilotProject.getCustomerRating(),
        result.getCustomerRating());
    Assert.assertEquals(
        "Invalid CopilotProject pm feedback",
        copilotProject.getPmFeedback(),
        result.getPmFeedback());
    Assert.assertEquals(
        "Invalid CopilotProject pm rating", copilotProject.getPmRating(), result.getPmRating());
    Assert.assertEquals(
        "Invalid CopilotProject tcDirectProjectId",
        copilotProject.getTcDirectProjectId(),
        result.getTcDirectProjectId());

    Assert.assertEquals(
        "Invalid CopilotProject create user",
        copilotProject.getCreateUser(),
        result.getCreateUser());
    Assert.assertEquals(
        "Invalid CopilotProject modify user",
        copilotProject.getModifyUser(),
        result.getModifyUser());
  }
  /**
   * Tests <code>{@link CopilotProjectDAOImpl#delete(long)}</code> method.
   *
   * @throws CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testDelete1() throws CopilotDAOException {

    CopilotProfile copilotProfile1 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject1 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile1, copilotProject1);
    hibernateTemplate.save(copilotProject1);

    CopilotProfile copilotProfile2 = TestHelper.createCopilotProfile();
    CopilotProject copilotProject2 = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(
        hibernateTemplate, copilotProfile2, copilotProject2);
    hibernateTemplate.save(copilotProject2);

    instance.delete(copilotProject1.getId());

    List<CopilotProject> result =
        hibernateTemplate.find("from CopilotProject where id = ?", copilotProject1.getId());

    Assert.assertEquals(
        "One entity in database should still exist.",
        1,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals("Entity was not deleted.", 0, result.size());

    instance.delete(copilotProject2.getId());

    result = hibernateTemplate.find("from CopilotProject where id = ?", copilotProject2.getId());

    Assert.assertEquals(
        "None entity in database should exist.",
        0,
        hibernateTemplate.find("from CopilotProject").size());
    Assert.assertEquals("Entity was not deleted.", 0, result.size());
  }
  /**
   * Tests <code>{@link
   * CopilotProjectDAOImpl#create(com.topcoder.direct.services.copilot.model.IdentifiableEntity)}
   * </code> method.
   *
   * @throws com.topcoder.direct.services.copilot.dao.CopilotDAOException if any error occurs
   */
  @Test
  @SuppressWarnings("unchecked")
  public void testCreate1() throws CopilotDAOException {

    CopilotProfile copilotProfile = TestHelper.createCopilotProfile();
    CopilotProject copilotProject = TestHelper.createCopilotProject();

    TestHelper.persistCopilotProjectDependencies(hibernateTemplate, copilotProfile, copilotProject);

    instance.create(copilotProject);

    List<CopilotProject> result =
        (List<CopilotProject>)
            hibernateTemplate.find("from CopilotProject where id = ?", copilotProject.getId());

    assertCopilotProject(copilotProject, result.get(0));
  }