Search in sources :

Example 26 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class InstructorCourseStudentDetailsEditPageActionTest method testAccessControl.

@Override
@Test
protected void testAccessControl() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    verifyOnlyInstructorsOfTheSameCourseCanAccess(submissionParams);
    verifyUnaccessibleWithoutModifyStudentPrivilege(submissionParams);
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 27 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class InstructorCourseStudentDetailsEditPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid parameters");
    // no parameters
    verifyAssumptionFailure();
    // null student email
    String[] invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    verifyAssumptionFailure(invalidParams);
    // null course id
    invalidParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    verifyAssumptionFailure(invalidParams);
    ______TS("Typical case, edit student detail page");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    InstructorCourseStudentDetailsEditPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, false, "idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());
    InstructorCourseStudentDetailsEditPageData pageData = (InstructorCourseStudentDetailsEditPageData) r.data;
    assertEquals(instructorId, pageData.account.googleId);
    assertEquals(student1InCourse1.name, pageData.getStudentInfoTable().getName());
    assertEquals(student1InCourse1.email, pageData.getStudentInfoTable().getEmail());
    assertEquals(student1InCourse1.section, pageData.getStudentInfoTable().getSection());
    assertEquals(student1InCourse1.team, pageData.getStudentInfoTable().getTeam());
    assertEquals(student1InCourse1.comments, pageData.getStudentInfoTable().getComments());
    assertEquals(student1InCourse1.course, pageData.getStudentInfoTable().getCourse());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEdit|||instructorCourseStudentDetailsEdit" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1" + "|||instr1@course1.tmt|||instructorCourseStudentEdit Page Load<br>Editing Student " + "<span class=\"bold\">student1InCourse1@gmail.tmt's</span> details in Course " + "<span class=\"bold\">[idOfTypicalCourse1]</span>" + "|||/page/instructorCourseStudentDetailsEdit";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorCourseStudentDetailsEditPageData(teammates.ui.pagedata.InstructorCourseStudentDetailsEditPageData) InstructorCourseStudentDetailsEditPageAction(teammates.ui.controller.InstructorCourseStudentDetailsEditPageAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 28 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class InstructorCourseStudentDetailsEditSaveActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String newStudentEmail = "newemail@gmail.tmt";
    String newStudentTeam = "new student's team";
    String newStudentComments = "this is new comment after editing";
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid parameters");
    // no parameters
    verifyAssumptionFailure();
    // null student email
    String[] invalidParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    verifyAssumptionFailure(invalidParams);
    // null course id
    invalidParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    verifyAssumptionFailure(invalidParams);
    ______TS("Typical case, successful edit and save student detail");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, newStudentEmail, Const.ParamsNames.COMMENTS, newStudentComments, Const.ParamsNames.TEAM_NAME, newStudentTeam, Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK, "true" };
    InstructorCourseStudentDetailsEditSaveAction a = getAction(submissionParams);
    RedirectResult r = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, false, "idOfInstructor1OfCourse1", "idOfTypicalCourse1"), r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(Const.StatusMessages.STUDENT_EDITED_AND_EMAIL_SENT, r.getStatusMessage());
    verifyNumberOfEmailsSent(a, 1);
    EmailWrapper email = getEmailsSent(a).get(0);
    String courseName = coursesLogic.getCourse(instructor1OfCourse1.courseId).getName();
    assertEquals(String.format(EmailType.STUDENT_EMAIL_CHANGED.getSubject(), courseName, instructor1OfCourse1.courseId), email.getSubject());
    assertEquals(newStudentEmail, email.getRecipient());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Student <span class=\"bold\">" + student1InCourse1.email + "'s</span> details in Course <span class=\"bold\">[idOfTypicalCourse1]</span> edited.<br>" + "New Email: " + newStudentEmail + "<br>New Team: " + newStudentTeam + "<br>Comments: " + newStudentComments + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Typical case, successful edit and save student detail with spaces to be trimmed");
    // after trim, this is equal to newStudentEmail
    String newStudentEmailToBeTrimmed = "  newemail@gmail.tmt   ";
    String newStudentTeamToBeTrimmed = "  New team   ";
    String newStudentCommentsToBeTrimmed = "  this is new comment after editing   ";
    String[] submissionParamsToBeTrimmed = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, newStudentEmail, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, newStudentEmailToBeTrimmed, Const.ParamsNames.COMMENTS, newStudentCommentsToBeTrimmed, Const.ParamsNames.TEAM_NAME, newStudentTeamToBeTrimmed, Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK, "true" };
    InstructorCourseStudentDetailsEditSaveAction aToBeTrimmed = getAction(submissionParamsToBeTrimmed);
    RedirectResult rToBeTrimmed = getRedirectResult(aToBeTrimmed);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, false, "idOfInstructor1OfCourse1", "idOfTypicalCourse1"), rToBeTrimmed.getDestinationWithParams());
    assertFalse(rToBeTrimmed.isError);
    assertEquals(Const.StatusMessages.STUDENT_EDITED, rToBeTrimmed.getStatusMessage());
    verifyNoEmailsSent(aToBeTrimmed);
    String expectedLogMessageToBeTrimmed = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Student <span class=\"bold\">" + newStudentEmail + "'s</span> details in Course <span class=\"bold\">[idOfTypicalCourse1]</span> edited.<br>" + "New Email: " + newStudentEmailToBeTrimmed.trim() + "<br>New Team: " + newStudentTeamToBeTrimmed.trim() + "<br>Comments: " + newStudentCommentsToBeTrimmed.trim() + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessageToBeTrimmed, aToBeTrimmed.getLogMessage());
    ______TS("Error case, invalid email parameter (email has too many characters)");
    String invalidStudentEmail = StringHelperExtension.generateStringOfLength(255 - "@gmail.tmt".length()) + "@gmail.tmt";
    assertEquals(FieldValidator.EMAIL_MAX_LENGTH + 1, invalidStudentEmail.length());
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, // Use the new email as the previous email have been changed
    Const.ParamsNames.STUDENT_EMAIL, // Use the new email as the previous email have been changed
    newStudentEmail, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, invalidStudentEmail, Const.ParamsNames.COMMENTS, student1InCourse1.comments, Const.ParamsNames.TEAM_NAME, student1InCourse1.team };
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    ShowPageResult result = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, true, "idOfInstructor1OfCourse1"), result.getDestinationWithParams());
    assertTrue(result.isError);
    assertEquals(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, invalidStudentEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.EMAIL_MAX_LENGTH), result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Servlet Action Failure : " + getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, invalidStudentEmail, FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_TOO_LONG, FieldValidator.EMAIL_MAX_LENGTH) + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Error case, invalid email parameter (email already taken by others)");
    StudentAttributes student2InCourse1 = typicalBundle.students.get("student2InCourse1");
    String takenStudentEmail = student2InCourse1.email;
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, // Use the new email as the previous email have been changed
    Const.ParamsNames.STUDENT_EMAIL, // Use the new email as the previous email have been changed
    newStudentEmail, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, takenStudentEmail, Const.ParamsNames.COMMENTS, student1InCourse1.comments, Const.ParamsNames.TEAM_NAME, student1InCourse1.team };
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    result = getShowPageResult(a);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, true, "idOfInstructor1OfCourse1"), result.getDestinationWithParams());
    assertTrue(result.isError);
    assertEquals(String.format(Const.StatusMessages.STUDENT_EMAIL_TAKEN_MESSAGE, student2InCourse1.name, takenStudentEmail), result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Servlet Action Failure : " + String.format(Const.StatusMessages.STUDENT_EMAIL_TAKEN_MESSAGE, student2InCourse1.name, takenStudentEmail) + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    // deleting edited student
    AccountsLogic.inst().deleteAccountCascade(student2InCourse1.googleId);
    AccountsLogic.inst().deleteAccountCascade(student1InCourse1.googleId);
    ______TS("Error case, student does not exist");
    String nonExistentEmailForStudent = "notinuseemail@gmail.tmt";
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, nonExistentEmailForStudent, Const.ParamsNames.STUDENT_NAME, student1InCourse1.name, Const.ParamsNames.NEW_STUDENT_EMAIL, student1InCourse1.email, Const.ParamsNames.COMMENTS, student1InCourse1.comments, Const.ParamsNames.TEAM_NAME, student1InCourse1.team };
    gaeSimulation.loginAsInstructor(instructorId);
    a = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(a);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE, true, instructorId, instructor1OfCourse1.courseId), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_EDIT, redirectResult.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseStudentDetailsEditSave|||instructorCourseStudentDetailsEditSave" + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Student <span class=\"bold\">" + nonExistentEmailForStudent + "</span> in " + "Course <span class=\"bold\">[" + instructor1OfCourse1.courseId + "]</span> not found." + "|||/page/instructorCourseStudentDetailsEditSave";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());
    ______TS("Unsuccessful case: test null student email parameter");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    try {
        a = getAction(submissionParams);
        r = getRedirectResult(a);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.STUDENT_EMAIL), e.getMessage());
    }
    ______TS("Unsuccessful case: test null course id parameter");
    submissionParams = new String[] { Const.ParamsNames.STUDENT_EMAIL, newStudentEmail };
    try {
        a = getAction(submissionParams);
        r = getRedirectResult(a);
        signalFailureToDetectException("Did not detect that parameters are null.");
    } catch (NullPostParameterException e) {
        assertEquals(String.format(Const.StatusCodes.NULL_POST_PARAMETER, Const.ParamsNames.COURSE_ID), e.getMessage());
    }
}
Also used : ShowPageResult(teammates.ui.controller.ShowPageResult) NullPostParameterException(teammates.common.exception.NullPostParameterException) RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseStudentDetailsEditSaveAction(teammates.ui.controller.InstructorCourseStudentDetailsEditSaveAction) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 29 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class InstructorCourseStudentDetailsEditSaveActionTest method testAccessControl.

@Override
@Test
protected void testAccessControl() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student3InCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    verifyOnlyInstructorsOfTheSameCourseCanAccess(submissionParams);
    verifyUnaccessibleWithoutModifyStudentPrivilege(submissionParams);
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 30 with StudentAttributes

use of teammates.common.datatransfer.attributes.StudentAttributes in project teammates by TEAMMATES.

the class InstructorCourseStudentDetailsPageActionTest method testAccessControl.

@Override
@Test
protected void testAccessControl() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.STUDENT_EMAIL, student1InCourse1.email };
    verifyOnlyInstructorsOfTheSameCourseCanAccess(submissionParams);
    verifyUnaccessibleWithoutViewStudentInSectionsPrivilege(submissionParams);
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)241 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)85 Test (org.testng.annotations.Test)80 ArrayList (java.util.ArrayList)55 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)33 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)33 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)30 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)27 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)22 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)17 ShowPageResult (teammates.ui.controller.ShowPageResult)15 HashMap (java.util.HashMap)14 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)14 InvalidParametersException (teammates.common.exception.InvalidParametersException)14 EmailWrapper (teammates.common.util.EmailWrapper)13 RedirectResult (teammates.ui.controller.RedirectResult)12 List (java.util.List)11 StatusMessage (teammates.common.util.StatusMessage)10 HashSet (java.util.HashSet)9 StudentEnrollDetails (teammates.common.datatransfer.StudentEnrollDetails)9