/**
  * Test the method getDefaultTemplateName(int) for failure.
  *
  * <p>It tests when it failed to execute the statement and expects PersistenceException
  *
  * @throws Exception to JUnit
  */
 public void testGetDefaultTemplateName_Failure3() throws Exception {
   persistence =
       new DBPhaseTemplatePersistence(FailureTestHelper.getDBConnectionFactory(), "root");
   try {
     persistence.getDefaultTemplateName(1);
     fail("should get PersistenceException");
   } catch (PersistenceException e) {
     // success
   }
 }
 /**
  * Test the method removeTemplate(String) for failure.
  *
  * <p>It tests when it failed to connect to the database and expects PersistenceException.
  *
  * @throws Exception to JUnit
  */
 public void testRemoveTemplate_Failure2() throws Exception {
   persistence =
       new DBPhaseTemplatePersistence(FailureTestHelper.getDBConnectionFactory(), "root");
   try {
     persistence.removeTemplate("New_Design");
     fail("should get PersistenceException");
   } catch (PersistenceException e) {
     // success
   }
 }
 /**
  * Test the method getTemplateCategory(String) for failure.
  *
  * <p>It tests when it failed to connect to the database and expects PersistenceException.
  *
  * @throws Exception to JUnit
  */
 public void testGetTemplateCategory_Failure4() throws Exception {
   persistence =
       new DBPhaseTemplatePersistence(
           FailureTestHelper.getDBConnectionFactory(), "wrongConnection");
   try {
     persistence.getTemplateCategory("New_Design");
     fail("should get PersistenceException");
   } catch (PersistenceException e) {
     // success
   }
 }
  /**
   * Test the method <code>getAllTemplateNames(int)</code>for failure.
   *
   * <p>It tests when it failed to execute the statement and expects PersistenceException.
   *
   * @throws Exception to JUnit
   */
  public void testGetAllTemplateNamesInt_Failure2() throws Exception {
    persistence =
        new DBPhaseTemplatePersistence(FailureTestHelper.getDBConnectionFactory(), "root");

    try {
      persistence.getAllTemplateNames(2);
      fail("PersistenceException expected.");
    } catch (PersistenceException ex) {
      // success
    }
  }
  /**
   * Test the method <code>generatePhases(String, Project)</code>for failure.
   *
   * <p>It tests when it failed to execute the statement and expects PersistenceException.
   *
   * @throws Exception to JUnit
   */
  public void testGeneratePhases_Failure6() throws Exception {
    persistence =
        new DBPhaseTemplatePersistence(FailureTestHelper.getDBConnectionFactory(), "root");

    try {
      persistence.generatePhases("New_Design", project);
      fail("PersistenceException expected.");
    } catch (PersistenceException ex) {
      // success
    }
  }
  /**
   * Set up environment.
   *
   * @throws Exception to JUnit
   */
  protected void setUp() throws Exception {
    FailureTestHelper.initializeDB();
    Helper.loadConfig(CONFIG_FILE);
    Helper.loadConfig(BAD_CONFIG_FILE);
    persistence =
        new DBPhaseTemplatePersistence(FailureTestHelper.getDBConnectionFactory(), "test");

    // create needed objects
    startDate = Calendar.getInstance().getTime();
    workdays = new DefaultWorkdays();
    project = new Project(startDate, workdays);
  }
  /**
   * Test the method <code>getAllTemplateNames()</code>for failure.
   *
   * <p>It tests when it failed to connect to the database and expects PersistenceRuntimeException.
   *
   * @throws Exception to JUnit
   */
  public void testGetAllTemplateNames_Failure1() throws Exception {
    persistence =
        new DBPhaseTemplatePersistence(
            FailureTestHelper.getDBConnectionFactory(), "wrongConnection");

    try {
      persistence.getAllTemplateNames();
      fail("PersistenceRuntimeException expected.");
    } catch (PersistenceRuntimeException ex) {
      // success
    }
  }