public void testEditReportingPeriodReviewCommentWithId() {
    Integer reportingPeriodId = 5;
    String newComment = "new Comment";
    String userId = "userId";
    Integer commentId = 2;

    AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
    ReportingPeriodReviewComment comment =
        Fixtures.createReportingPeriodReviewComment(1, "comment 1");
    ArrayList<ReportingPeriodReviewComment> commentsList =
        new ArrayList<ReportingPeriodReviewComment>();
    commentsList.add(comment);
    comment = Fixtures.createReportingPeriodReviewComment(2, "comment 2");
    commentsList.add(comment);
    rp.setReviewComments(commentsList);
    EasyMock.expect(rpDao.getById(reportingPeriodId)).andReturn(rp);
    rpDao.modifyOrSaveReviewStatusAndComments(rp);
    replayMocks();
    impl.editReportingPeriodReviewComment(reportingPeriodId, newComment, userId, commentId);
    verifyMocks();

    assertEquals(
        "Edit comment isnt working correctly",
        "new Comment",
        rp.getReviewCommentsInternal().get(1).getUserComment());
  }
  public void testAddReportingPeriodReviewCommentWithId() {
    Integer reportingPeriodId = 5;
    String comment = "mycomment";
    String userId = "userId";

    AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
    rp.setReviewComments(new ArrayList<ReportingPeriodReviewComment>());
    EasyMock.expect(rpDao.getById(reportingPeriodId)).andReturn(rp);
    rpDao.modifyOrSaveReviewStatusAndComments(rp);
    replayMocks();
    impl.addReportingPeriodReviewComment(reportingPeriodId, comment, userId);
    verifyMocks();
  }
  public void testEnactReportingPeriodWorkflow() {
    long processId = 5;
    StudyParticipantAssignment assignment = Fixtures.createAssignment();
    AdverseEventReportingPeriod reportingPeriod = Fixtures.createReportingPeriod();
    reportingPeriod.setId(44);
    WorkflowConfig workflowConfig = Fixtures.createWorkflowConfig("test");
    StudySite site = assignment.getStudySite();
    StudySiteWorkflowConfig ssWfCfg =
        new StudySiteWorkflowConfig("reportingPeriod", site, workflowConfig);
    site.addStudySiteWorkflowConfig(ssWfCfg);
    reportingPeriod.setAssignment(assignment);

    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(WorkflowService.VAR_STUDY_ID, site.getStudy().getId());
    variables.put(WorkflowService.VAR_WF_TYPE, AdverseEventReportingPeriod.class.getName());
    variables.put(WorkflowService.VAR_WF_STUDY_NAME, reportingPeriod.getStudy().getDisplayName());
    variables.put(
        WorkflowService.VAR_WF_SUBJECT_NAME, reportingPeriod.getParticipant().getFullName());
    variables.put(WorkflowService.VAR_WF_COURSE_NAME, reportingPeriod.getName());
    variables.put(WorkflowService.VAR_REPORTING_PERIOD_ID, reportingPeriod.getId());

    EasyMock.expect(wfService.createProcessInstance("test", variables)).andReturn(processInstance);
    EasyMock.expect(processInstance.getId()).andReturn(processId).anyTimes();
    rpDao.modifyOrSaveReviewStatusAndComments(reportingPeriod);
    replayMocks();
    impl.enactReportingPeriodWorkflow(reportingPeriod);
    verifyMocks();
  }
 public void testDeleteReportingPeriodReviewComment() {
   AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
   ArrayList<ReportingPeriodReviewComment> commentsList =
       new ArrayList<ReportingPeriodReviewComment>();
   commentsList.add(Fixtures.createReportingPeriodReviewComment(1, "comment 1"));
   commentsList.add(Fixtures.createReportingPeriodReviewComment(2, "comment 2"));
   commentsList.add(Fixtures.createReportingPeriodReviewComment(3, "comment 3"));
   rp.setReviewComments(commentsList);
   rp.setId(1);
   EasyMock.expect(rpDao.getById(1)).andReturn(rp);
   rpDao.modifyOrSaveReviewStatusAndComments(rp);
   replayMocks();
   impl.deleteReportingPeriodReviewComment(1, 2);
   verifyMocks();
   assertEquals(
       "Comment not deleted from comments list", 2, rp.getReviewCommentsInternal().size());
 }
  public void testFindAdverseEventReportingPeriods() {
    String userId = "tester";
    AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
    ExpeditedAdverseEventReport aeReport = Fixtures.createSavableExpeditedReport();
    Report report = Fixtures.createReport("test report");
    report.setStatus(ReportStatus.INPROCESS);
    report.setReviewStatus(ReviewStatus.DRAFT_INCOMPLETE);
    report.setWorkflowId(1);
    rp.addAeReport(aeReport);
    aeReport.addReport(report);

    List<AdverseEventReportingPeriod> reportingPeriods =
        new ArrayList<AdverseEventReportingPeriod>();
    reportingPeriods.add(rp);

    rp.setReviewStatus(ReviewStatus.DRAFT_INCOMPLETE);
    rp.setWorkflowId(1);

    AdverseEventReportingPeriodDTO rpDto = new AdverseEventReportingPeriodDTO();
    ExpeditedAdverseEventReportDTO rDto = new ExpeditedAdverseEventReportDTO();
    ReportDTO reportDto = new ReportDTO();
    rDto.addReportDTO(reportDto);
    List<String> possibleActions = new ArrayList<String>();
    possibleActions.add("abc");
    reportDto.setPossibleActions(possibleActions);
    EasyMock.expect(
            rpDao.findAdverseEventReportingPeriods(
                (AdverseEventReportingPeriodForReviewQuery) EasyMock.anyObject()))
        .andReturn(reportingPeriods);

    EasyMock.expect(factory.createAdverseEventEvalutionPeriodDTO(rp, userId, true))
        .andReturn(rpDto);
    EasyMock.expect(factory.createAdverseEventReportDTO(aeReport, userId)).andReturn(rDto);
    List rrList = new ArrayList<ReconciliationReport>();
    EasyMock.expect(
            reconciliationReportDao.search((ReconciliationReportQuery) EasyMock.anyObject()))
        .andReturn(rrList)
        .anyTimes();
    replayMocks();

    Participant participant = Fixtures.createParticipant("Joel", "biju");
    Study study = Fixtures.createStudy("Hello");
    Organization org = Fixtures.createOrganization("test org");
    ReviewStatus reviewStatus = null;
    ReportStatus reportStatus = null;

    List<AdverseEventReportingPeriodDTO> dtos =
        impl.findAdverseEventReportingPeriods(
            participant, study, org, reviewStatus, reportStatus, userId, true);

    verifyMocks();

    assertEquals(1, dtos.size());
    assertEquals(1, dtos.get(0).getAeReports().size());
  }
 public void testFetchReviewCommentsForReportingPeriod() {
   AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
   List<ReportingPeriodReviewComment> reviewComments =
       new ArrayList<ReportingPeriodReviewComment>();
   rp.setReviewComments(reviewComments);
   Integer rpId = 5;
   EasyMock.expect(rpDao.getById(rpId)).andReturn(rp);
   replayMocks();
   List<? extends ReviewComment> comments = impl.fetchReviewCommentsForReportingPeriod(rpId);
   verifyMocks();
   assertEquals(reviewComments.size(), comments.size());
 }
  public void testAdvanceReportingPeriodWorkflow() {
    Integer id = 5;
    Integer wfId = 5;
    String loginId = "SYSTEM_ADMIN";
    String transitionToTake = "abcd";
    List<String> transitions = new ArrayList<String>();
    ReviewStatus rs = ReviewStatus.DRAFT_INCOMPLETE;
    AdverseEventReportingPeriod rp = Fixtures.createReportingPeriod();
    rp.setReviewComments(new ArrayList<ReportingPeriodReviewComment>());
    EasyMock.expect(wfService.advanceWorkflow(wfId, transitionToTake)).andReturn(rs);
    EasyMock.expect(wfService.nextTransitionNames(wfId, loginId)).andReturn(transitions);
    EasyMock.expect(rpDao.getById(id)).andReturn(rp);
    rpDao.modifyOrSaveReviewStatusAndComments(rp);
    replayMocks();
    List<String> transitionNames =
        impl.advanceReportingPeriodWorkflow(wfId, transitionToTake, id, loginId);

    verifyMocks();
    assertEquals(
        "A review comment for the action of advancing workflow was not added",
        1,
        rp.getReviewComments().size());
  }