Search in sources :

Example 41 with ShowPageResult

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

the class InstructorHomePageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    String[] submissionParams = new String[] { Const.ParamsNames.CHECK_PERSISTENCE_COURSE, "something" };
    ______TS("persistence issue");
    gaeSimulation.loginUser("unreg_user");
    InstructorHomePageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertFalse(a.account.isInstructor);
    assertEquals(Const.StatusMessages.INSTRUCTOR_PERSISTENCE_ISSUE, r.getStatusMessage());
    ______TS("instructor with no courses, right after registration (ie no persistence issue)");
    gaeSimulation.loginAsInstructor(typicalBundle.accounts.get("instructorWithoutCourses").googleId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    AssertHelper.assertContainsRegex(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, "instructorWithoutCourses"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.HINT_FOR_NEW_INSTRUCTOR, r.getStatusMessage());
    InstructorHomePageData data = (InstructorHomePageData) r.data;
    assertEquals(0, data.getCourseTables().size());
    String expectedLogMessage = "TEAMMATESLOG|||instructorHomePage|||instructorHomePage" + "|||true|||Instructor|||Instructor Without Courses" + "|||instructorWithoutCourses|||iwc@yahoo.tmt" + "|||instructorHome Page Load<br>Total Courses: 0" + "|||/page/instructorHomePage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    submissionParams = new String[] {};
    ______TS("instructor with multiple courses, sort by course id, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, Const.SORT_BY_COURSE_ID };
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    // access page in masquerade mode
    String instructorWithMultipleCourses = typicalBundle.accounts.get("instructor3").googleId;
    // create another course for sorting
    Logic logic = new Logic();
    // should be 1st if sort by course id
    String newCourseIdForSorting = "idOfTypicalCourse";
    // should be 3rd if sort by course name
    String newCourseNameForSorting = "Typical Course 3";
    logic.createCourseAndInstructor(instructorWithMultipleCourses, newCourseIdForSorting, newCourseNameForSorting, "UTC");
    a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, instructorWithMultipleCourses), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (InstructorHomePageData) r.data;
    assertEquals(3, data.getCourseTables().size());
    String expectedCourse1IdAfterSortByCourseId = "idOfTypicalCourse";
    String expectedCourse2IdAfterSortByCourseId = "idOfTypicalCourse1";
    String expectedCourse3IdAfterSortByCourseId = "idOfTypicalCourse2";
    String actualCourse1AfterSortByCourseId = data.getCourseTables().get(0).getCourseId();
    String actualCourse2AfterSortByCourseId = data.getCourseTables().get(1).getCourseId();
    String actualCourse3AfterSortByCourseId = data.getCourseTables().get(2).getCourseId();
    assertEquals(expectedCourse1IdAfterSortByCourseId, actualCourse1AfterSortByCourseId);
    assertEquals(expectedCourse2IdAfterSortByCourseId, actualCourse2AfterSortByCourseId);
    assertEquals(expectedCourse3IdAfterSortByCourseId, actualCourse3AfterSortByCourseId);
    assertEquals(Const.SORT_BY_COURSE_ID, data.getSortCriteria());
    expectedLogMessage = "TEAMMATESLOG|||instructorHomePage|||instructorHomePage|||true" + "|||Instructor(M)|||Instructor 3 of Course 1 and 2" + "|||idOfInstructor3|||instr3@course1n2.tmt" + "|||instructorHome Page Load<br>Total Courses: 3" + "|||/page/instructorHomePage";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, a.getLogMessage(), adminUserId);
    ______TS("instructor with multiple courses, sort by course name, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, Const.SORT_BY_COURSE_NAME };
    a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, instructorWithMultipleCourses), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (InstructorHomePageData) r.data;
    assertEquals(3, data.getCourseTables().size());
    String expectedCourse1IdAfterSortByCourseName = "idOfTypicalCourse1";
    String expectedCourse2IdAfterSortByCourseName = "idOfTypicalCourse2";
    String expectedCourse3IdAfterSortByCourseName = "idOfTypicalCourse";
    String actualCourse1AfterSortByCourseName = data.getCourseTables().get(0).getCourseId();
    String actualCourse2AfterSortByCourseName = data.getCourseTables().get(1).getCourseId();
    String actualCourse3AfterSortByCourseName = data.getCourseTables().get(2).getCourseId();
    assertEquals(expectedCourse1IdAfterSortByCourseName, actualCourse1AfterSortByCourseName);
    assertEquals(expectedCourse2IdAfterSortByCourseName, actualCourse2AfterSortByCourseName);
    assertEquals(expectedCourse3IdAfterSortByCourseName, actualCourse3AfterSortByCourseName);
    assertEquals(Const.SORT_BY_COURSE_NAME, data.getSortCriteria());
    ______TS("instructor with multiple courses, sort by course name, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, "haha" };
    try {
        a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
        r = getShowPageResult(a);
        signalFailureToDetectException("The Assertion error is not thrown as expected");
    } catch (AssertionError e) {
        assertNotNull(e);
    }
    ______TS("instructor with multiple courses, sort by creation date, masquerade mode");
    submissionParams = new String[] { Const.ParamsNames.COURSE_SORTING_CRITERIA, Const.SORT_BY_COURSE_CREATION_DATE };
    a = getAction(addUserIdToParams(instructorWithMultipleCourses, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_HOME, false, instructorWithMultipleCourses), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (InstructorHomePageData) r.data;
    assertEquals(3, data.getCourseTables().size());
    String expectedCourse1IdAfterSortByCourseCreationDate = "idOfTypicalCourse";
    String expectedCourse2IdAfterSortByCourseCreationDate = "idOfTypicalCourse2";
    String expectedCourse3IdAfterSortByCourseCreationDate = "idOfTypicalCourse1";
    String actualCourse1AfterSortByCourseCreationDate = data.getCourseTables().get(0).getCourseId();
    String actualCourse2AfterSortByCourseCreationDate = data.getCourseTables().get(1).getCourseId();
    String actualCourse3AfterSortByCourseCreationDate = data.getCourseTables().get(2).getCourseId();
    assertEquals(expectedCourse1IdAfterSortByCourseCreationDate, actualCourse1AfterSortByCourseCreationDate);
    assertEquals(expectedCourse2IdAfterSortByCourseCreationDate, actualCourse2AfterSortByCourseCreationDate);
    assertEquals(expectedCourse3IdAfterSortByCourseCreationDate, actualCourse3AfterSortByCourseCreationDate);
    assertEquals(Const.SORT_BY_COURSE_CREATION_DATE, data.getSortCriteria());
    // delete the new course
    CoursesLogic.inst().deleteCourseCascade(newCourseIdForSorting);
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorHomePageData(teammates.ui.pagedata.InstructorHomePageData) CoursesLogic(teammates.logic.core.CoursesLogic) Logic(teammates.logic.api.Logic) InstructorHomePageAction(teammates.ui.controller.InstructorHomePageAction) Test(org.testng.annotations.Test)

Example 42 with ShowPageResult

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

the class InstructorStudentRecordsAjaxPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor3OfCourse1");
    StudentAttributes student = typicalBundle.students.get("student2InCourse1");
    String instructorId = instructor.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Typical case: specific session name");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.STUDENT_EMAIL, student.email, Const.ParamsNames.FEEDBACK_SESSION_NAME, "First feedback session" };
    InstructorStudentRecordsAjaxPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS_AJAX, false, "idOfInstructor3"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    InstructorStudentRecordsAjaxPageData data = (InstructorStudentRecordsAjaxPageData) r.data;
    assertEquals(1, data.getResultsTables().size());
}
Also used : InstructorStudentRecordsAjaxPageData(teammates.ui.pagedata.InstructorStudentRecordsAjaxPageData) ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorStudentRecordsAjaxPageAction(teammates.ui.controller.InstructorStudentRecordsAjaxPageAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 43 with ShowPageResult

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

the class InstructorCourseAddActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String adminUserId = "admin.user";
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    verifyAssumptionFailure(Const.ParamsNames.COURSE_NAME, "ticac tac name");
    ______TS("Error: Invalid parameter for Course ID");
    String invalidCourseId = "ticac,tpa1,id";
    InstructorCourseAddAction addAction = getAction(Const.ParamsNames.COURSE_ID, invalidCourseId, Const.ParamsNames.COURSE_NAME, "ticac tpa1 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
    ShowPageResult pageResult = getShowPageResult(addAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSES, true, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertTrue(pageResult.isError);
    assertEquals(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, invalidCourseId, FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), pageResult.getStatusMessage());
    InstructorCoursesPageData pageData = (InstructorCoursesPageData) pageResult.data;
    assertEquals(1, pageData.getActiveCourses().getRows().size() + pageData.getArchivedCourses().getRows().size());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, invalidCourseId, FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH) + "|||/page/instructorCourseAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
    ______TS("Typical case, 1 existing course");
    addAction = getAction(Const.ParamsNames.COURSE_ID, "ticac.tpa1.id", Const.ParamsNames.COURSE_NAME, "ticac tpa1 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
    RedirectResult redirectResult = getRedirectResult(addAction);
    List<CourseAttributes> courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(2, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course added : ticac.tpa1.id<br>Total courses: 2|||/page/instructorCourseAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
    String expected = Const.StatusMessages.COURSE_ADDED.replace("${courseEnrollLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_ENROLL_PAGE, "ticac.tpa1.id", "idOfInstructor1OfCourse1")).replace("${courseEditLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, "ticac.tpa1.id", "idOfInstructor1OfCourse1"));
    assertEquals(expected, redirectResult.getStatusMessage());
    ______TS("Error: Try to add the same course again");
    addAction = getAction(Const.ParamsNames.COURSE_ID, "ticac.tpa1.id", Const.ParamsNames.COURSE_NAME, "ticac tpa1 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
    pageResult = getShowPageResult(addAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSES, true, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertTrue(pageResult.isError);
    assertEquals(Const.StatusMessages.COURSE_EXISTS, pageResult.getStatusMessage());
    pageData = (InstructorCoursesPageData) pageResult.data;
    assertEquals(2, pageData.getActiveCourses().getRows().size() + pageData.getArchivedCourses().getRows().size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "A course by the same ID already exists in the system, possibly created by another " + "user. Please choose a different course ID|||/page/instructorCourseAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
    ______TS("Masquerade mode, 0 courses");
    CoursesLogic.inst().deleteCourseCascade(instructor1OfCourse1.courseId);
    CoursesLogic.inst().deleteCourseCascade("ticac.tpa1.id");
    gaeSimulation.loginAsAdmin(adminUserId);
    addAction = getAction(Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, "ticac.tpa2.id", Const.ParamsNames.COURSE_NAME, "ticac tpa2 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
    redirectResult = getRedirectResult(addAction);
    String expectedDestination = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1");
    assertEquals(expectedDestination, redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    String expectedStatus = "The course has been added. Click <a href=\"/page/instructorCourseEnrollPage?" + "courseid=ticac.tpa2.id&user=idOfInstructor1OfCourse1\">here</a> to add students " + "to the course or click <a href=\"/page/instructorCourseEditPage?" + "courseid=ticac.tpa2.id&user=idOfInstructor1OfCourse1\">here</a> to add other " + "instructors.<br>If you don't see the course in the list below, please refresh " + "the page after a few moments.";
    assertEquals(expectedStatus, redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(1, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course added : ticac.tpa2.id<br>Total courses: 1|||/page/instructorCourseAdd";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, addAction.getLogMessage(), adminUserId);
    // delete the new course
    CoursesLogic.inst().deleteCourseCascade("ticac.tpa2.id");
    ______TS("Test archived Courses");
    InstructorAttributes instructorOfArchivedCourse = typicalBundle.instructors.get("instructorOfArchivedCourse");
    instructorId = instructorOfArchivedCourse.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    addAction = getAction(Const.ParamsNames.COURSE_ID, "ticac.tpa2.id", Const.ParamsNames.COURSE_NAME, "ticac tpa2 name", Const.ParamsNames.COURSE_TIME_ZONE, "UTC");
    redirectResult = getRedirectResult(addAction);
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(2, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd|||true|||Instructor|||" + "InstructorOfArchiveCourse name|||idOfInstructorOfArchivedCourse|||" + "instructorOfArchiveCourse@archiveCourse.tmt|||Course added : ticac.tpa2.id<br>" + "Total courses: 2|||/page/instructorCourseAdd";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, addAction.getLogMessage());
    expected = Const.StatusMessages.COURSE_ADDED.replace("${courseEnrollLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_ENROLL_PAGE, "ticac.tpa2.id", "idOfInstructorOfArchivedCourse")).replace("${courseEditLink}", getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE, "ticac.tpa2.id", "idOfInstructorOfArchivedCourse"));
    assertEquals(expected, redirectResult.getStatusMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorCoursesPageData(teammates.ui.pagedata.InstructorCoursesPageData) RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseAddAction(teammates.ui.controller.InstructorCourseAddAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 44 with ShowPageResult

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

the class AdminAccountDetailsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    ______TS("case: view instructor account details");
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.INSTRUCTOR_ID, instructor1OfCourse1.googleId };
    final String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    AdminAccountDetailsPageAction action = getAction(submissionParams);
    ShowPageResult result = getShowPageResult(action);
    assertEquals("", result.getStatusMessage());
    assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_ACCOUNT_DETAILS, false, adminUserId), result.getDestinationWithParams());
    assertFalse(result.isError);
    AdminAccountDetailsPageData data = (AdminAccountDetailsPageData) result.data;
    assertEquals(instructor1OfCourse1.googleId, data.getAccountInformation().googleId);
}
Also used : AdminAccountDetailsPageData(teammates.ui.pagedata.AdminAccountDetailsPageData) ShowPageResult(teammates.ui.controller.ShowPageResult) AdminAccountDetailsPageAction(teammates.ui.controller.AdminAccountDetailsPageAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 45 with ShowPageResult

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

the class AdminActivityLogPageActionTest method verifyContinueSearch.

private void verifyContinueSearch(String[] params, int[][] expected, int totalLogs, int filteredLogs, Instant earliestDateInUtc) {
    AdminActivityLogPageAction action = getAction(params);
    ShowPageResult result = getShowPageResult(action);
    AdminActivityLogPageData pageData = (AdminActivityLogPageData) result.data;
    verifyStatusMessage(result.getStatusMessage(), totalLogs, filteredLogs, earliestDateInUtc);
    verifyLogs(expected, getLogsFromLogTemplateRows(pageData.getLogs()));
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AdminActivityLogPageAction(teammates.ui.controller.AdminActivityLogPageAction) AdminActivityLogPageData(teammates.ui.pagedata.AdminActivityLogPageData)

Aggregations

ShowPageResult (teammates.ui.controller.ShowPageResult)51 Test (org.testng.annotations.Test)42 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)31 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)15 RedirectResult (teammates.ui.controller.RedirectResult)10 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)8 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)8 EntityNotFoundException (teammates.common.exception.EntityNotFoundException)5 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)4 NullPostParameterException (teammates.common.exception.NullPostParameterException)4 ArrayList (java.util.ArrayList)3 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)3 AdminActivityLogPageAction (teammates.ui.controller.AdminActivityLogPageAction)3 AdminEmailLogPageAction (teammates.ui.controller.AdminEmailLogPageAction)3 AjaxResult (teammates.ui.controller.AjaxResult)3 InstructorCourseEnrollPageAction (teammates.ui.controller.InstructorCourseEnrollPageAction)3 InstructorCourseEnrollPageData (teammates.ui.pagedata.InstructorCourseEnrollPageData)3 Instant (java.time.Instant)2 AdminEmailAttributes (teammates.common.datatransfer.attributes.AdminEmailAttributes)2 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)2