/** no story */
  public void testAddExistedStory_1() {
    long sprintId = mCS.getSprintsId().get(0);
    String releaseId = "-1";
    String[] selects = {};

    // ================ set request info ========================
    String projectName = mProject.getName();
    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("selects", selects);
    addRequestParameter("sprintID", String.valueOf(sprintId));
    addRequestParameter("releaseID", releaseId);

    // ================ set session info ========================
    request.getSession().setAttribute("UserSession", mConfig.getUserSession());

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    // assert response text
    String expectedResponseText = "";
    String actualResponseText = response.getWriterBuffer().toString();
    assertEquals(expectedResponseText, actualResponseText);
  }
  /** 專案擁有一個Sprint但該專案沒有成員 */
  public void testShowInformationAction_2() {
    int sprintCount = 1;
    CreateSprint createSprint = new CreateSprint(sprintCount, mCP);
    createSprint.exe();

    // ================ set request info ========================
    String expectedSprintID = "1";
    String projectName = mProject.getName();
    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("sprintID", expectedSprintID);

    // ================ set session info ========================
    request.getSession().setAttribute("UserSession", mConfig.getUserSession());

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    /*
     * in struts-config.xml
     * <forward name="success" path="sprintInformation.show"/>
     * 因此根據sprintInformation.show必須到tiles-defs.xml找到要轉發的頁面
     * in tiles-defs.xml
     * <definition name="sprintInformation.show" path="/Pages/ShowSprintInformation.jsp"></definition>
     */
    verifyForward("success");
    verifyForwardPath("/Pages/ShowSprintInformation.jsp");

    String actualSprintID = String.valueOf(request.getAttribute("SprintID"));
    String actualStoryPoint = String.valueOf(request.getAttribute("StoryPoint"));
    ISprintPlanDesc actualSprintPlan = (ISprintPlanDesc) request.getAttribute("SprintPlan");
    String actualActors = String.valueOf(request.getAttribute("Actors"));
    String actualSprintPeriod = String.valueOf(request.getAttribute("SprintPeriod"));
    @SuppressWarnings("unchecked")
    ArrayList<StoryObject> actualIIssueList =
        (ArrayList<StoryObject>) request.getAttribute("Stories");

    TestTool testTool = new TestTool();
    Date today = createSprint.mToday;
    Date startDate = testTool.getSprintStartDate(CreateSprint.SPRINT_INTERVAL, today);
    Date endDate = testTool.getSprintEndDate(CreateSprint.SPRINT_INTERVAL, today);
    String expectedSprintPeriod =
        testTool.transformDate(startDate) + " to " + testTool.transformDate(endDate);

    assertEquals(expectedSprintID, actualSprintID); // 	verify sprint ID
    assertEquals("0.0", actualStoryPoint); // 	verify story points
    assertNotNull(actualSprintPlan); // 	verify sprint plan object
    assertEquals(
        createSprint.TEST_SPRINT_GOAL + expectedSprintID,
        actualSprintPlan.getGoal()); // 	verify sprint goal
    assertEquals("[]", actualActors); // 	verify 參與此專案的人(因為尚未加入團隊成員因此為空的)
    assertEquals(expectedSprintPeriod, actualSprintPeriod); // 	verify Sprint週期
    //	verify story information
    assertNotNull(actualIIssueList);
    assertEquals(0, actualIIssueList.size());
    assertEquals("0.0", actualStoryPoint); // 	verify story points
  }
 @Test
 public void testGetRetrospectivesBySprintId() {
   long sprintId = 2;
   ArrayList<RetrospectiveObject> retrospectives =
       RetrospectiveDAO.getInstance().getRetrospectivesBySprintId(sprintId);
   assertEquals(0, retrospectives.size());
   RetrospectiveObject retrospective1 = new RetrospectiveObject(mProject.getId());
   retrospective1.setSprintId(sprintId).save();
   RetrospectiveObject retrospective2 = new RetrospectiveObject(mProject.getId());
   retrospective2.setSprintId(sprintId).save();
   RetrospectiveObject retrospective3 = new RetrospectiveObject(mProject.getId());
   retrospective3.setSprintId(sprintId).save();
   retrospectives = RetrospectiveDAO.getInstance().getRetrospectivesBySprintId(sprintId);
   assertEquals(3, retrospectives.size());
   assertEquals(retrospectives.get(0).getId(), retrospective1.getId());
   assertEquals(retrospectives.get(1).getId(), retrospective2.getId());
   assertEquals(retrospectives.get(2).getId(), retrospective3.getId());
 }
 public long addRelease(ReleaseInfo releaseInfo) {
   ReleaseObject release = new ReleaseObject(mProject.getId());
   release
       .setName(releaseInfo.name)
       .setDescription(releaseInfo.description)
       .setStartDate(releaseInfo.startDate)
       .setDueDate(releaseInfo.dueDate)
       .save();
   return release.getId();
 }
  @Test
  public void testCreate() throws SQLException {
    // Test data
    String name = "TEST_RETROSPECTIVE_NAME";
    String description = "TEST_RETROSPECTIVE_DESCRIPTION";
    String type = RetrospectiveObject.TYPE_GOOD;
    String status = RetrospectiveObject.STATUS_NEW;
    long sprintId = 1;

    // Create Retrospective
    RetrospectiveObject retrospective = new RetrospectiveObject(mProject.getId());
    retrospective
        .setName(name)
        .setDescription(description)
        .setType(type)
        .setStatus(status)
        .setSprintId(sprintId);

    // Test create method
    long retrospectiveId = RetrospectiveDAO.getInstance().create(retrospective);
    assertTrue(retrospectiveId > 0);

    // Get Data From DB
    IQueryValueSet valueSet = new MySQLQuerySet();
    valueSet.addTableName(RetrospectiveEnum.TABLE_NAME);
    valueSet.addEqualCondition(RetrospectiveEnum.ID, retrospectiveId);

    String query = valueSet.getSelectQuery();
    ResultSet result = mControl.executeQuery(query);

    RetrospectiveObject retrospectiveFromDB = null;

    if (result.next()) {
      retrospectiveFromDB = RetrospectiveDAO.convert(result);
    }
    closeResultSet(result);

    // Verify Data
    assertEquals(name, retrospectiveFromDB.getName());
    assertEquals(description, retrospectiveFromDB.getDescription());
    assertEquals(type, retrospectiveFromDB.getType());
    assertEquals(status, retrospectiveFromDB.getStatus());
    assertEquals(sprintId, retrospectiveFromDB.getSprintId());
  }
  /** 專案沒有一個 Sprint */
  public void testShowInformationAction_1() {
    // ================ set request info ========================
    String sprintId = "1";
    String projectName = mProject.getName();

    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("sprintID", sprintId);

    // ================ set session info ========================
    request.getSession().setAttribute("UserSession", mConfig.getUserSession());

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    verifyForward("error");
    verifyForwardPath("/Error.jsp");
  }
  /** 登入的使用者沒有AccessSprintBacklog的權限 */
  public void testShowInformationAction_4() {
    int sprintCount = 1;
    CreateSprint createSprint = new CreateSprint(sprintCount, mCP);
    createSprint.exe();

    int accountCount = 1;
    CreateAccount createAccount = new CreateAccount(accountCount);
    createAccount.exe();
    AddUserToRole addUserToRole = new AddUserToRole(mCP, createAccount);
    addUserToRole.exe_Guest();

    // ================ set request info ========================
    String expectedSprintID = "1";
    String projectName = mProject.getName();
    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("sprintID", expectedSprintID);

    // ================ set session info ========================
    AccountObject account = createAccount.getAccountList().get(0);
    UserSession newUser = new UserSession(new AccountMapper().getAccount(account.getUsername()));
    request.getSession().setAttribute("UserSession", newUser);

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    /*
     * in struts-config.xml
     * <forward name="GuestOnly" path="Guest.Summary" />
     * 因此根據Guest.Summary必須到tiles-defs.xml找到要轉發的頁面
     * in tiles-defs.xml
     * <definition name="Guest.Summary" extends="base.layout">
     * <definition name="base.layout" path="/Layout/Layout.jsp">
     */
    verifyForward("GuestOnly");
    verifyForwardPath("/Layout/Layout.jsp");
  }
  private long createRetrospective() {
    // Test data
    String name = "TEST_RETROSPECTIVE_NAME";
    String description = "TEST_RETROSPECTIVE_DESCRIPTION";
    String type = RetrospectiveObject.TYPE_GOOD;
    String status = RetrospectiveObject.STATUS_NEW;
    long sprintId = 1;

    // Create Retrospective
    RetrospectiveObject retrospective = new RetrospectiveObject(mProject.getId());
    retrospective
        .setName(name)
        .setDescription(description)
        .setType(type)
        .setStatus(status)
        .setSprintId(sprintId);

    // Test create method
    long retrospectiveId = RetrospectiveDAO.getInstance().create(retrospective);
    assertTrue(retrospectiveId > 0);

    return retrospectiveId;
  }
  /** two stories */
  public void testAddExistedStory_2() {
    int storyCount = 2;
    CreateProductBacklog CPB = new CreateProductBacklog(storyCount, mCP);
    CPB.exe();

    long sprintId = mCS.getSprintsId().get(0);
    String releaseID = "-1";
    String[] selects = {"1", "2"};

    // ================ set request info ========================
    String projectName = mProject.getName();
    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("selects", selects);
    addRequestParameter("sprintID", String.valueOf(sprintId));
    addRequestParameter("releaseID", releaseID);

    // ================ set session info ========================
    request.getSession().setAttribute("UserSession", mConfig.getUserSession());

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    // assert response text
    String actualResponseText = response.getWriterBuffer().toString();
    StringBuilder expectedResponseText = new StringBuilder();
    expectedResponseText.append("");
    assertEquals(expectedResponseText.toString(), actualResponseText);

    // 驗證是否確實有被加入sprint中
    String showSprintBacklog_ActionPath = "/showSprintBacklog2";
    setRequestPathInfo(showSprintBacklog_ActionPath);

    clearRequestParameters();
    response.reset();

    // ================ set request info ========================
    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("sprintID", String.valueOf(sprintId));

    // ================ set session info ========================
    request.getSession().setAttribute("UserSession", mConfig.getUserSession());

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    // assert response text
    String expectedStoryEstimation = "2";
    String expectedSprintGoal = "TEST_SPRINTGOAL_1";
    String expectedSprintHoursToCommit = "10";
    for (int i = 0; i < mCS.getSprintCount() - 1; i++) {
      expectedResponseText
          .append("{\"success\":true,\"Total\":2,")
          .append("\"Sprint\":{")
          .append("\"Id\":")
          .append(sprintId)
          .append(",")
          .append("\"Name\":\"Sprint #")
          .append(sprintId)
          .append("\",")
          .append("\"CurrentPoint\":")
          .append(Integer.parseInt(expectedStoryEstimation) * 2)
          .append(",")
          .append("\"LimitedPoint\":")
          .append(Integer.parseInt(expectedSprintHoursToCommit))
          .append(",")
          .append("\"TaskPoint\":0,")
          .append("\"ReleaseID\":\"Release #None\",")
          .append("\"SprintGoal\":\"")
          .append(expectedSprintGoal)
          .append("\"},")
          .append("\"Stories\":[");

      for (StoryObject story : CPB.getStories()) {
        expectedResponseText
            .append("{\"Id\":")
            .append(story.getId())
            .append(",")
            .append("\"Link\":\"")
            .append("\",")
            .append("\"Name\":\"")
            .append(story.getName())
            .append("\",")
            .append("\"Value\":")
            .append(story.getValue())
            .append(",")
            .append("\"Importance\":")
            .append(story.getImportance())
            .append(",")
            .append("\"Estimate\":")
            .append(story.getEstimate())
            .append(",")
            .append("\"Status\":\"new\",")
            .append("\"Notes\":\"")
            .append(story.getNotes())
            .append("\",")
            .append("\"Tag\":\"\",")
            .append("\"HowToDemo\":\"")
            .append(story.getHowToDemo())
            .append("\",")
            .append("\"Release\":\"\",")
            .append("\"Sprint\":")
            .append(sprintId)
            .append(",")
            .append("\"Attach\":false,")
            .append("\"AttachFileList\":[]},");
      }
      expectedResponseText.deleteCharAt(expectedResponseText.length() - 1);
      expectedResponseText.append("]}");
    }
    actualResponseText = response.getWriterBuffer().toString();
    assertEquals(expectedResponseText.toString(), actualResponseText);
  }
Beispiel #10
0
 public ArrayList<ReleaseObject> getReleases() {
   return mProject.getReleases();
 }
  /**
   * 專案擁有一個Sprint且專案擁有一位成員
   *
   * @throws Exception
   */
  public void testShowInformationAction_3() throws Exception {
    int sprintCount = 1;
    CreateSprint createSprint = new CreateSprint(sprintCount, mCP);
    createSprint.exe();

    int storyCount = 1;
    int expectStoryEstimation = 5;
    AddStoryToSprint addStoryToSprint =
        new AddStoryToSprint(
            storyCount,
            expectStoryEstimation,
            createSprint,
            mCP,
            CreateProductBacklog.COLUMN_TYPE_EST);
    addStoryToSprint.exe();

    int accountCount = 1;
    CreateAccount createAccount = new CreateAccount(accountCount);
    createAccount.exe();
    AddUserToRole addUserToRole = new AddUserToRole(mCP, createAccount);
    addUserToRole.exe_ST();

    // ================ set request info ========================
    String expectedSprintID = "1";
    String projectName = mProject.getName();
    request.setHeader("Referer", "?PID=" + projectName);
    addRequestParameter("sprintID", expectedSprintID);

    // ================ set session info ========================
    request.getSession().setAttribute("UserSession", mConfig.getUserSession());

    // ================ 執行 action ======================
    actionPerform();

    // ================ assert ========================
    verifyNoActionErrors();
    verifyNoActionMessages();
    /*
     * in struts-config.xml
     * <forward name="success" path="sprintInformation.show"/>
     * 因此根據sprintInformation.show必須到tiles-defs.xml找到要轉發的頁面
     * in tiles-defs.xml
     * <definition name="sprintInformation.show" path="/Pages/ShowSprintInformation.jsp"></definition>
     */
    verifyForward("success");
    verifyForwardPath("/Pages/ShowSprintInformation.jsp");

    String actualSprintID = String.valueOf(request.getAttribute("SprintID"));
    String actualStoryPoint = String.valueOf(request.getAttribute("StoryPoint"));
    ISprintPlanDesc actualSprintPlan = (ISprintPlanDesc) request.getAttribute("SprintPlan");
    String actualSprintPeriod = String.valueOf(request.getAttribute("SprintPeriod"));
    @SuppressWarnings("unchecked")
    ArrayList<StoryObject> actualStories = (ArrayList<StoryObject>) request.getAttribute("Stories");
    @SuppressWarnings("unchecked")
    ArrayList<String> actualActors = (ArrayList<String>) request.getAttribute("Actors");

    TestTool testTool = new TestTool();
    Date today = createSprint.mToday;
    Date startDate = testTool.getSprintStartDate(CreateSprint.SPRINT_INTERVAL, today);
    Date endDate = testTool.getSprintEndDate(CreateSprint.SPRINT_INTERVAL, today);
    String expectedSprintPeriod =
        testTool.transformDate(startDate) + " to " + testTool.transformDate(endDate);

    /**
     * 1. verify sprint ID 2. verify story information 3. verify sprint plan information 5. verify
     * Sprint週期 6. verify 參與此專案的人
     */
    //	verify sprint ID
    assertEquals(expectedSprintID, actualSprintID);

    //	verify story information
    assertNotNull(actualStories);
    assertEquals("TEST_STORY_1", actualStories.get(0).getName());
    assertEquals("5.0", actualStoryPoint);

    //	verify sprint plan information
    assertNotNull(actualSprintPlan);
    assertEquals(createSprint.TEST_SPRINT_GOAL + expectedSprintID, actualSprintPlan.getGoal());

    //	verify Sprint週期
    assertEquals(expectedSprintPeriod, actualSprintPeriod);

    //	verify 參與此專案的人
    String expectAccountID = createAccount.getAccount_ID(1);
    boolean isExistedAccount = false;
    for (String accountID : actualActors) {
      if (accountID.equals(expectAccountID)) {
        isExistedAccount = true;
        break;
      }
    }
    assertTrue(isExistedAccount);
  }