Search in sources :

Example 1 with StudentFeedbackResultsPageAction

use of teammates.ui.controller.StudentFeedbackResultsPageAction in project teammates by TEAMMATES.

the class StudentFeedbackResultsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    FeedbackSessionAttributes session1InCourse1 = typicalBundle.feedbackSessions.get("session1InCourse1");
    FeedbackSessionAttributes emptySession = typicalBundle.feedbackSessions.get("empty.session");
    FeedbackSessionAttributes closedSession = typicalBundle.feedbackSessions.get("closedSession");
    FeedbackSessionAttributes gracePeriodSession = typicalBundle.feedbackSessions.get("gracePeriodSession");
    session1InCourse1.setResultsVisibleFromTime(session1InCourse1.getStartTime());
    FeedbackSessionsLogic.inst().updateFeedbackSession(session1InCourse1);
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    gaeSimulation.loginAsStudent(student1InCourse1.googleId);
    ______TS("invalid params");
    String[] submissionParams = new String[] {};
    verifyRedirectTo(Const.ActionURIs.STUDENT_HOME_PAGE, submissionParams);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId() };
    verifyRedirectTo(Const.ActionURIs.STUDENT_HOME_PAGE, submissionParams);
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName() };
    verifyRedirectTo(Const.ActionURIs.STUDENT_HOME_PAGE, submissionParams);
    ______TS("results not viewable when not published");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName() };
    FeedbackSessionsLogic.inst().unpublishFeedbackSession(session1InCourse1);
    StudentFeedbackResultsPageAction pageAction = getAction(submissionParams);
    try {
        getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("This feedback session is not yet visible.", exception.getMessage());
    }
    ______TS("cannot access a private session");
    FeedbackSessionsLogic.inst().publishFeedbackSession(session1InCourse1);
    session1InCourse1.setFeedbackSessionType(FeedbackSessionType.PRIVATE);
    FeedbackSessionsLogic.inst().updateFeedbackSession(session1InCourse1);
    pageAction = getAction(submissionParams);
    try {
        getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("Feedback session [First feedback session] is not accessible to student " + "[" + student1InCourse1.email + "]", exception.getMessage());
    }
    session1InCourse1.setFeedbackSessionType(FeedbackSessionType.STANDARD);
    FeedbackSessionsLogic.inst().updateFeedbackSession(session1InCourse1);
    ______TS("access a empty session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, emptySession.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, emptySession.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    assertEquals(Const.ViewURIs.STUDENT_FEEDBACK_RESULTS, pageResult.destination);
    assertFalse(pageResult.isError);
    assertEquals("You have not received any new feedback but you may review your own submissions below.", pageResult.getStatusMessage());
    ______TS("access a gracePeriodSession session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, gracePeriodSession.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, gracePeriodSession.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    try {
        pageResult = getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("This feedback session is not yet visible.", exception.getMessage());
    }
    ______TS("access a closed session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, closedSession.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, closedSession.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    try {
        pageResult = getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("This feedback session is not yet visible.", exception.getMessage());
    }
    ______TS("access a non-existent session");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, "non-existent session" };
    pageAction = getAction(submissionParams);
    try {
        pageResult = getShowPageResult(pageAction);
    } catch (UnauthorizedAccessException exception) {
        assertEquals("Trying to access system using a non-existent feedback session entity", exception.getMessage());
    }
    ______TS("typical case");
    removeAndRestoreTypicalDataBundle();
    session1InCourse1 = FeedbackSessionsLogic.inst().getFeedbackSession(session1InCourse1.getFeedbackSessionName(), session1InCourse1.getCourseId());
    FeedbackSessionsLogic.inst().publishFeedbackSession(session1InCourse1);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, session1InCourse1.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session1InCourse1.getFeedbackSessionName() };
    pageAction = getAction(submissionParams);
    pageResult = getShowPageResult(pageAction);
    assertEquals(Const.ViewURIs.STUDENT_FEEDBACK_RESULTS, pageResult.destination);
    assertFalse(pageResult.isError);
    assertEquals("You have received feedback from others. Please see below.", pageResult.getStatusMessage());
    StudentFeedbackResultsPageData pageData = (StudentFeedbackResultsPageData) pageResult.data;
    // databundle time changed here because publishing sets resultsVisibleTime to now.
    typicalBundle.feedbackSessions.get("session1InCourse1").setResultsVisibleFromTime(Instant.now());
    /*
         * The above test can fail if the time elapsed between pageData... and dataBundle...
         * changes the time recorded by dataBundle up to the precision of seconds.
         * To solve that, verify that the time elapsed is less than one second (or else the test
         * fails after all) and if it does, change the value in the dataBundle to match.
         */
    Instant pageDataResultsVisibleFromTime = pageData.getBundle().feedbackSession.getResultsVisibleFromTime();
    Instant dataBundleResultsVisibleFromTime = typicalBundle.feedbackSessions.get("session1InCourse1").getResultsVisibleFromTime();
    Duration difference = Duration.between(pageDataResultsVisibleFromTime, dataBundleResultsVisibleFromTime);
    long toleranceTimeInMs = 1000;
    if (difference.compareTo(Duration.ofMillis(toleranceTimeInMs)) < 0) {
        // change to the value that will never make the test fail
        typicalBundle.feedbackSessions.get("session1InCourse1").setResultsVisibleFromTime(pageData.getBundle().feedbackSession.getResultsVisibleFromTime());
    }
    List<FeedbackSessionAttributes> expectedInfoList = new ArrayList<>();
    List<FeedbackSessionAttributes> actualInfoList = new ArrayList<>();
    expectedInfoList.add(typicalBundle.feedbackSessions.get("session1InCourse1"));
    actualInfoList.add(pageData.getBundle().feedbackSession);
    AssertHelper.assertSameContentIgnoreOrder(expectedInfoList, actualInfoList);
    assertEquals(student1InCourse1.googleId, pageData.account.googleId);
    assertEquals(student1InCourse1.getIdentificationString(), pageData.student.getIdentificationString());
}
Also used : Instant(java.time.Instant) ArrayList(java.util.ArrayList) Duration(java.time.Duration) StudentFeedbackResultsPageData(teammates.ui.pagedata.StudentFeedbackResultsPageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) ShowPageResult(teammates.ui.controller.ShowPageResult) StudentFeedbackResultsPageAction(teammates.ui.controller.StudentFeedbackResultsPageAction) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) Test(org.testng.annotations.Test)

Aggregations

Duration (java.time.Duration)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1 StudentFeedbackResultsPageAction (teammates.ui.controller.StudentFeedbackResultsPageAction)1 StudentFeedbackResultsPageData (teammates.ui.pagedata.StudentFeedbackResultsPageData)1