use of teammates.ui.controller.InstructorCourseJoinAction in project teammates by TEAMMATES.
the class InstructorCourseJoinActionTest method testExecuteAndPostProcess.
@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
InstructorsDb instrDb = new InstructorsDb();
// Reassign to let "key" variable in "instructor" not to be null
instructor = instrDb.getInstructorForGoogleId(instructor.courseId, instructor.googleId);
String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
gaeSimulation.loginAsInstructor(instructor.googleId);
______TS("Invalid key, redirect for confirmation again");
String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
InstructorCourseJoinAction confirmAction = getAction(submissionParams);
ShowPageResult pageResult = getShowPageResult(confirmAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "idOfInstructor1OfCourse1", invalidEncryptedKey), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
String expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + invalidEncryptedKey;
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
______TS("Already registered instructor, redirect straight to authentication page");
submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
confirmAction = getAction(submissionParams);
RedirectResult redirectResult = getRedirectResult(confirmAction);
assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN_AUTHENTICATED, StringHelper.encrypt(instructor.key), false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
assertFalse(redirectResult.isError);
assertEquals("", redirectResult.getStatusMessage());
expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(instructor.key);
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
______TS("Typical case: unregistered instructor, redirect to confirmation page");
instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAT.instr@email.com").build();
InstructorsLogic.inst().createInstructor(instructor);
instructor.googleId = "ICJAT.instr";
AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
AccountsLogic.inst().createAccount(newInstructorAccount);
InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
gaeSimulation.loginUser(instructor.googleId);
submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
confirmAction = getAction(submissionParams);
pageResult = getShowPageResult(confirmAction);
assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "ICJAT.instr", StringHelper.encrypt(newInstructor.key)), pageResult.getDestinationWithParams());
assertFalse(pageResult.isError);
assertEquals("", pageResult.getStatusMessage());
expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(newInstructor.key);
AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
}
Aggregations