Search in sources :

Example 1 with InstructorFeedbackPublishAction

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

the class InstructorFeedbackPublishActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    gaeSimulation.loginAsInstructor(typicalBundle.instructors.get("instructor1OfCourse1").googleId);
    FeedbackSessionAttributes session = typicalBundle.feedbackSessions.get("session2InCourse1");
    String[] paramsNormal = { Const.ParamsNames.COURSE_ID, session.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsWithNullCourseId = { Const.ParamsNames.FEEDBACK_SESSION_NAME, session.getFeedbackSessionName() };
    String[] paramsWithNullFeedbackSessionName = { Const.ParamsNames.COURSE_ID, session.getCourseId() };
    ______TS("Typical successful case: session publishable");
    makeFeedbackSessionUnpublished(session);
    InstructorFeedbackPublishAction publishAction = getAction(paramsNormal);
    RedirectResult result = getRedirectResult(publishAction);
    String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_PUBLISHED, result.getStatusMessage());
    assertFalse(result.isError);
    verifySpecifiedTasksAdded(publishAction, Const.TaskQueue.FEEDBACK_SESSION_PUBLISHED_EMAIL_QUEUE_NAME, 1);
    TaskWrapper taskAdded = publishAction.getTaskQueuer().getTasksAdded().get(0);
    Map<String, String[]> paramMap = taskAdded.getParamMap();
    assertEquals(session.getCourseId(), paramMap.get(ParamsNames.EMAIL_COURSE)[0]);
    assertEquals(session.getSessionName(), paramMap.get(ParamsNames.EMAIL_FEEDBACK)[0]);
    ______TS("Unsuccessful case 1: params with null course id");
    String errorMessage = "";
    publishAction = getAction(paramsWithNullCourseId);
    try {
        publishAction.executeAndPostProcess();
        signalFailureToDetectException("NullPostParameterException expected");
    } catch (NullPostParameterException e) {
        errorMessage = e.getMessage();
    }
    assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), errorMessage);
    ______TS("Unsuccessful case 2: params with null feedback session name");
    errorMessage = "";
    publishAction = getAction(paramsWithNullFeedbackSessionName);
    try {
        publishAction.executeAndPostProcess();
        signalFailureToDetectException("NullPostParameterException expected");
    } catch (NullPostParameterException e) {
        errorMessage = e.getMessage();
    }
    assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.FEEDBACK_SESSION_NAME), errorMessage);
    ______TS("Unsuccessful case 3: trying to publish a session not currently unpublished");
    makeFeedbackSessionPublished(session);
    publishAction = getAction(paramsNormal);
    result = getRedirectResult(publishAction);
    expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, true, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, result.getDestinationWithParams());
    assertEquals("Error publishing feedback session: Session has already been published.", result.getStatusMessage());
    assertTrue(result.isError);
    verifyNoTasksAdded(publishAction);
    makeFeedbackSessionUnpublished(session);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) TaskWrapper(teammates.common.util.TaskWrapper) NullPostParameterException(teammates.common.exception.NullPostParameterException) InstructorFeedbackPublishAction(teammates.ui.controller.InstructorFeedbackPublishAction) RedirectResult(teammates.ui.controller.RedirectResult) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)1 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)1 NullPostParameterException (teammates.common.exception.NullPostParameterException)1 TaskWrapper (teammates.common.util.TaskWrapper)1 InstructorFeedbackPublishAction (teammates.ui.controller.InstructorFeedbackPublishAction)1 RedirectResult (teammates.ui.controller.RedirectResult)1