Search in sources :

Example 1 with StudentHomePageData

use of teammates.ui.pagedata.StudentHomePageData in project teammates by TEAMMATES.

the class StudentHomePageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    String unregUserId = "unreg.user";
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String studentId = student1InCourse1.googleId;
    String adminUserId = "admin.user";
    String[] submissionParams = new String[] {};
    ______TS("unregistered student");
    gaeSimulation.loginUser(unregUserId);
    StudentHomePageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    AssertHelper.assertContainsRegex(getPageResultDestination(Const.ViewURIs.STUDENT_HOME, false, "unreg.user"), r.getDestinationWithParams());
    assertFalse(r.isError);
    AssertHelper.assertContainsRegex("Ooops! Your Google account is not known to TEAMMATES{*}use the new Gmail address.", r.getStatusMessage());
    StudentHomePageData data = (StudentHomePageData) r.data;
    assertEquals(0, data.getCourseTables().size());
    String expectedLogMessage = "TEAMMATESLOG|||studentHomePage|||studentHomePage" + "|||true|||Unregistered|||Unknown|||unreg.user|||Unknown" + "|||Servlet Action Failure :Student with Google ID " + "unreg.user does not exist|||/page/studentHomePage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("registered student with no courses");
    // Note: this can happen only if the course was deleted after the student joined it.
    // The 'welcome stranger' response is not really appropriate for this situation, but
    // we keep it because the situation is rare and not worth extra coding.
    // Create a student account without courses
    AccountAttributes studentWithoutCourses = AccountAttributes.builder().withGoogleId("googleId.without.courses").withName("Student Without Courses").withEmail("googleId.without.courses@email.tmt").withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes("googleId.without.courses").build();
    AccountsDb accountsDb = new AccountsDb();
    accountsDb.createAccount(studentWithoutCourses);
    assertNotNull(accountsDb.getAccount(studentWithoutCourses.googleId));
    gaeSimulation.loginUser(studentWithoutCourses.googleId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    AssertHelper.assertContainsRegex(getPageResultDestination(Const.ViewURIs.STUDENT_HOME, false, studentWithoutCourses.googleId), r.getDestinationWithParams());
    assertFalse(r.isError);
    AssertHelper.assertContainsRegex("Ooops! Your Google account is not known to TEAMMATES{*}use the new Gmail address.", r.getStatusMessage());
    data = (StudentHomePageData) r.data;
    assertEquals(0, data.getCourseTables().size());
    expectedLogMessage = "TEAMMATESLOG|||studentHomePage|||studentHomePage|||true" + "|||Unregistered|||Student Without Courses|||googleId.without.courses" + "|||googleId.without.courses@email.tmt|||Servlet Action Failure " + ":Student with Google ID googleId.without.courses does not exist" + "|||/page/studentHomePage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("typical user, masquerade mode");
    gaeSimulation.loginAsAdmin(adminUserId);
    studentId = typicalBundle.students.get("student2InCourse2").googleId;
    // Access page in masquerade mode
    a = getAction(addUserIdToParams(studentId, submissionParams));
    r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.STUDENT_HOME, false, studentId), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    data = (StudentHomePageData) r.data;
    assertEquals(2, data.getCourseTables().size());
    expectedLogMessage = "TEAMMATESLOG|||studentHomePage|||studentHomePage|||true" + "|||Student(M)|||Student in two courses|||student2InCourse1" + "|||student2InCourse1@gmail.tmt" + "|||studentHome Page Load<br>Total courses: 2" + "|||/page/studentHomePage";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, a.getLogMessage(), adminUserId);
    ______TS("New student with no existing course, course join affected by eventual consistency");
    submissionParams = new String[] { Const.ParamsNames.CHECK_PERSISTENCE_COURSE, "idOfTypicalCourse1" };
    studentId = "newStudent";
    gaeSimulation.loginUser(studentId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    data = (StudentHomePageData) r.data;
    assertEquals(1, data.getCourseTables().size());
    assertEquals("idOfTypicalCourse1", data.getCourseTables().get(0).getCourseId());
    ______TS("Registered student with existing courses, course join affected by eventual consistency");
    submissionParams = new String[] { Const.ParamsNames.CHECK_PERSISTENCE_COURSE, "idOfTypicalCourse2" };
    student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    studentId = student1InCourse1.googleId;
    gaeSimulation.loginUser(studentId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    data = (StudentHomePageData) r.data;
    assertEquals(2, data.getCourseTables().size());
    assertEquals("idOfTypicalCourse2", data.getCourseTables().get(1).getCourseId());
    ______TS("Just joined course, course join not affected by eventual consistency and appears in list");
    submissionParams = new String[] { Const.ParamsNames.CHECK_PERSISTENCE_COURSE, "idOfTypicalCourse1" };
    student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    studentId = student1InCourse1.googleId;
    gaeSimulation.loginUser(studentId);
    a = getAction(submissionParams);
    r = getShowPageResult(a);
    data = (StudentHomePageData) r.data;
    assertEquals(1, data.getCourseTables().size());
    // Delete additional sessions that were created
    CoursesLogic.inst().deleteCourseCascade("typicalCourse2");
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) AccountsDb(teammates.storage.api.AccountsDb) StudentHomePageAction(teammates.ui.controller.StudentHomePageAction) StudentHomePageData(teammates.ui.pagedata.StudentHomePageData) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) Test(org.testng.annotations.Test)

Example 2 with StudentHomePageData

use of teammates.ui.pagedata.StudentHomePageData in project teammates by TEAMMATES.

the class StudentHomePageDataTest method allTests.

@Test
public void allTests() {
    StudentHomePageData data = createData();
    testCourseTables(data.getCourseTables());
}
Also used : StudentHomePageData(teammates.ui.pagedata.StudentHomePageData) Test(org.testng.annotations.Test)

Example 3 with StudentHomePageData

use of teammates.ui.pagedata.StudentHomePageData in project teammates by TEAMMATES.

the class StudentHomePageAction method execute.

@Override
public ActionResult execute() {
    gateKeeper.verifyLoggedInUserPrivileges();
    String recentlyJoinedCourseId = getRequestParamValue(Const.ParamsNames.CHECK_PERSISTENCE_COURSE);
    List<CourseDetailsBundle> courses = new ArrayList<>();
    Map<FeedbackSessionAttributes, Boolean> sessionSubmissionStatusMap = new HashMap<>();
    try {
        courses = logic.getCourseDetailsListForStudent(account.googleId);
        sessionSubmissionStatusMap = generateFeedbackSessionSubmissionStatusMap(courses, account.googleId);
        CourseDetailsBundle.sortDetailedCoursesByCourseId(courses);
        statusToAdmin = "studentHome Page Load<br>" + "Total courses: " + courses.size();
        boolean isDataConsistent = isCourseIncluded(recentlyJoinedCourseId, courses);
        if (!isDataConsistent) {
            addPlaceholderCourse(courses, recentlyJoinedCourseId, sessionSubmissionStatusMap);
        }
        for (CourseDetailsBundle course : courses) {
            FeedbackSessionDetailsBundle.sortFeedbackSessionsByCreationTime(course.feedbackSessions);
        }
    } catch (EntityDoesNotExistException e) {
        if (recentlyJoinedCourseId == null) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_FIRST_TIME, StatusMessageColor.WARNING));
            statusToAdmin = Const.ACTION_RESULT_FAILURE + " :" + e.getMessage();
        } else {
            addPlaceholderCourse(courses, recentlyJoinedCourseId, sessionSubmissionStatusMap);
        }
    }
    StudentHomePageData data = new StudentHomePageData(account, sessionToken, courses, sessionSubmissionStatusMap);
    return createShowPageResult(Const.ViewURIs.STUDENT_HOME, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) HashMap(java.util.HashMap) StudentHomePageData(teammates.ui.pagedata.StudentHomePageData) ArrayList(java.util.ArrayList) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) StatusMessage(teammates.common.util.StatusMessage)

Example 4 with StudentHomePageData

use of teammates.ui.pagedata.StudentHomePageData in project teammates by TEAMMATES.

the class StudentHomePageDataTest method createData.

private StudentHomePageData createData() {
    // Courses
    CourseAttributes course1 = CourseAttributes.builder("course-id-1", "old-course", ZoneId.of("UTC")).build();
    CourseAttributes course2 = CourseAttributes.builder("course-id-2", "new-course", ZoneId.of("UTC")).build();
    // Feedback sessions
    submittedSession = createFeedbackSession("submitted session", -1, 1, 1);
    pendingSession = createFeedbackSession("pending session", -1, 1, 1);
    awaitingSession = createFeedbackSession("awaiting session", 1, 2, 1);
    publishedSession = createFeedbackSession("published session", -1, -1, -1);
    closedSession = createFeedbackSession("closed session", -2, -1, 1);
    submittedClosedSession = createFeedbackSession("submitted closed session", -2, -1, 1);
    // Submission status
    Map<FeedbackSessionAttributes, Boolean> sessionSubmissionStatusMap = new HashMap<>();
    sessionSubmissionStatusMap.put(submittedSession, true);
    sessionSubmissionStatusMap.put(pendingSession, false);
    sessionSubmissionStatusMap.put(awaitingSession, false);
    sessionSubmissionStatusMap.put(publishedSession, false);
    sessionSubmissionStatusMap.put(closedSession, false);
    sessionSubmissionStatusMap.put(submittedClosedSession, true);
    // Tooltip and button texts
    tooltipTextMap = new HashMap<>();
    buttonTextMap = new HashMap<>();
    tooltipTextMap.put(submittedSession, Const.Tooltips.FEEDBACK_SESSION_EDIT_SUBMITTED_RESPONSE);
    buttonTextMap.put(submittedSession, "Edit Submission");
    tooltipTextMap.put(pendingSession, Const.Tooltips.FEEDBACK_SESSION_SUBMIT);
    buttonTextMap.put(pendingSession, "Start Submission");
    tooltipTextMap.put(awaitingSession, Const.Tooltips.FEEDBACK_SESSION_AWAITING);
    buttonTextMap.put(awaitingSession, "Start Submission");
    tooltipTextMap.put(publishedSession, Const.Tooltips.FEEDBACK_SESSION_VIEW_SUBMITTED_RESPONSE);
    buttonTextMap.put(publishedSession, "View Submission");
    tooltipTextMap.put(closedSession, Const.Tooltips.FEEDBACK_SESSION_VIEW_SUBMITTED_RESPONSE);
    buttonTextMap.put(closedSession, "View Submission");
    tooltipTextMap.put(submittedClosedSession, Const.Tooltips.FEEDBACK_SESSION_VIEW_SUBMITTED_RESPONSE);
    buttonTextMap.put(submittedClosedSession, "View Submission");
    // Packing into bundles
    CourseDetailsBundle newCourseBundle = createCourseBundle(course1, submittedSession, pendingSession, awaitingSession);
    CourseDetailsBundle oldCourseBundle = createCourseBundle(course2, publishedSession, closedSession, submittedClosedSession);
    courses = new ArrayList<>();
    courses.add(newCourseBundle);
    courses.add(oldCourseBundle);
    return new StudentHomePageData(AccountAttributes.builder().build(), dummySessionToken, courses, sessionSubmissionStatusMap);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) CourseDetailsBundle(teammates.common.datatransfer.CourseDetailsBundle) HashMap(java.util.HashMap) StudentHomePageData(teammates.ui.pagedata.StudentHomePageData) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Aggregations

StudentHomePageData (teammates.ui.pagedata.StudentHomePageData)4 HashMap (java.util.HashMap)2 Test (org.testng.annotations.Test)2 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)2 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)2 ArrayList (java.util.ArrayList)1 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)1 StatusMessage (teammates.common.util.StatusMessage)1 AccountsDb (teammates.storage.api.AccountsDb)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1 StudentHomePageAction (teammates.ui.controller.StudentHomePageAction)1