use of teammates.ui.controller.InstructorFeedbackUnpublishAction in project teammates by TEAMMATES.
the class InstructorFeedbackUnpublishActionTest 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 unpublishable");
makeFeedbackSessionPublished(session);
InstructorFeedbackUnpublishAction unpublishAction = getAction(paramsNormal);
RedirectResult result = getRedirectResult(unpublishAction);
String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, "idOfInstructor1OfCourse1");
assertEquals(expectedDestination, result.getDestinationWithParams());
assertEquals(Const.StatusMessages.FEEDBACK_SESSION_UNPUBLISHED, result.getStatusMessage());
assertFalse(result.isError);
verifySpecifiedTasksAdded(unpublishAction, Const.TaskQueue.FEEDBACK_SESSION_UNPUBLISHED_EMAIL_QUEUE_NAME, 1);
TaskWrapper taskAdded = unpublishAction.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 = "";
unpublishAction = getAction(paramsWithNullCourseId);
try {
unpublishAction.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 = "";
unpublishAction = getAction(paramsWithNullFeedbackSessionName);
try {
unpublishAction.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 unpublish a session not currently published");
makeFeedbackSessionUnpublished(session);
unpublishAction = getAction(paramsNormal);
result = getRedirectResult(unpublishAction);
expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, true, "idOfInstructor1OfCourse1");
assertEquals(expectedDestination, result.getDestinationWithParams());
assertEquals("Error unpublishing feedback session: Session has already been unpublished.", result.getStatusMessage());
assertTrue(result.isError);
verifyNoTasksAdded(unpublishAction);
makeFeedbackSessionPublished(session);
}
Aggregations