Search in sources :

Example 56 with InstructorAttributes

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

the class FeedbackSessionStatsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String[] submissionParams;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("typical: instructor accesses feedback stats of his/her course");
    FeedbackSessionAttributes accessableFeedbackSession = typicalBundle.feedbackSessions.get("session1InCourse1");
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, accessableFeedbackSession.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    FeedbackSessionStatsPageAction a = getAction(addUserIdToParams(instructorId, submissionParams));
    AjaxResult r = getAjaxResult(a);
    FeedbackSessionStatsPageData data = (FeedbackSessionStatsPageData) r.data;
    assertEquals(getPageResultDestination("", false, "idOfInstructor1OfCourse1"), r.getDestinationWithParams());
    assertEquals(10, data.sessionDetails.stats.expectedTotal);
    assertEquals(4, data.sessionDetails.stats.submittedTotal);
    assertEquals("", r.getStatusMessage());
    ______TS("fail: instructor accesses stats of non-existent feedback session");
    String nonexistentFeedbackSession = "nonexistentFeedbackSession";
    submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, nonexistentFeedbackSession, Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    boolean hasThrownUnauthorizedAccessException = false;
    String exceptionMessage = "";
    a = getAction(addUserIdToParams(instructorId, submissionParams));
    try {
        r = getAjaxResult(a);
    } catch (UnauthorizedAccessException e) {
        hasThrownUnauthorizedAccessException = true;
        exceptionMessage = e.getMessage();
    }
    assertTrue(hasThrownUnauthorizedAccessException);
    assertEquals("Trying to access system using a non-existent feedback session entity", exceptionMessage);
    assertEquals("", r.getStatusMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AjaxResult(teammates.ui.controller.AjaxResult) FeedbackSessionStatsPageAction(teammates.ui.controller.FeedbackSessionStatsPageAction) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) FeedbackSessionStatsPageData(teammates.ui.pagedata.FeedbackSessionStatsPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 57 with InstructorAttributes

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

the class FeedbackSessionStatsPageActionTest method testAccessControl.

@Override
@Test
protected void testAccessControl() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    FeedbackSessionAttributes accessibleFeedbackSession = typicalBundle.feedbackSessions.get("session1InCourse1");
    String[] submissionParams = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, accessibleFeedbackSession.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    verifyOnlyInstructorsOfTheSameCourseCanAccess(submissionParams);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 58 with InstructorAttributes

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

the class InstructorCourseDeleteActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical case, 2 courses, redirect to homepage");
    CoursesLogic.inst().createCourseAndInstructor(instructorId, "icdct.tpa.id1", "New course", "UTC");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_HOME_PAGE };
    assertTrue(CoursesLogic.inst().isCoursePresent("icdct.tpa.id1"));
    InstructorCourseDeleteAction deleteAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course idOfTypicalCourse1 has been deleted.", redirectResult.getStatusMessage());
    List<CourseAttributes> courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(1, courseList.size());
    assertEquals("icdct.tpa.id1", courseList.get(0).getId());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||" + "Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||" + "instr1@course1.tmt|||Course deleted: idOfTypicalCourse1|||" + "/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, deleteAction.getLogMessage());
    ______TS("Masquerade mode, delete last course, redirect to Courses page");
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "icdct.tpa.id1", Const.ParamsNames.NEXT_URL, Const.ActionURIs.INSTRUCTOR_COURSES_PAGE };
    deleteAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course icdct.tpa.id1 has been deleted.", redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(0, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course deleted: icdct.tpa.id1|||/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, deleteAction.getLogMessage(), adminUserId);
    ______TS("Masquerade mode, delete last course, no next URL, redirect to Courses page");
    CoursesLogic.inst().createCourseAndInstructor(instructorId, "icdct.tpa.id2", "New course", "UTC");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, "icdct.tpa.id2" };
    deleteAction = getAction(addUserIdToParams(instructorId, submissionParams));
    redirectResult = getRedirectResult(deleteAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSES_PAGE, false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("The course icdct.tpa.id2 has been deleted.", redirectResult.getStatusMessage());
    courseList = CoursesLogic.inst().getCoursesForInstructor(instructorId);
    assertEquals(0, courseList.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDelete|||instructorCourseDelete|||true|||Instructor(M)|||" + "Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||instr1@course1.tmt|||" + "Course deleted: icdct.tpa.id2|||/page/instructorCourseDelete";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, deleteAction.getLogMessage(), adminUserId);
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) InstructorCourseDeleteAction(teammates.ui.controller.InstructorCourseDeleteAction) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 59 with InstructorAttributes

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

the class InstructorCourseDetailsPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1OfCourse1.googleId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical Case, Course with at least one student");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId };
    InstructorCourseDetailsPageAction pageAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_DETAILS, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    InstructorCourseDetailsPageData pageData = (InstructorCourseDetailsPageData) pageResult.data;
    assertEquals(5, pageData.getInstructors().size());
    assertEquals("idOfTypicalCourse1", pageData.getCourseDetails().course.getId());
    assertEquals("Typical Course 1 with 2 Evals", pageData.getCourseDetails().course.getName());
    assertEquals(2, pageData.getCourseDetails().stats.teamsTotal);
    assertEquals(5, pageData.getCourseDetails().stats.studentsTotal);
    assertEquals(0, pageData.getCourseDetails().stats.unregisteredTotal);
    assertEquals(0, pageData.getCourseDetails().feedbackSessions.size());
    String expectedLogMessage = "TEAMMATESLOG|||instructorCourseDetailsPage|||instructorCourseDetailsPage|||true" + "|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1" + "|||instr1@course1.tmt|||instructorCourseDetails Page Load<br>Viewing Course " + "Details for Course <span class=\"bold\">[idOfTypicalCourse1]</span>" + "|||/page/instructorCourseDetailsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, pageAction.getLogMessage());
    ______TS("Masquerade mode, Course with no student");
    String adminUserId = "admin.user";
    gaeSimulation.loginAsAdmin(adminUserId);
    InstructorAttributes instructor4 = typicalBundle.instructors.get("instructor4");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor4.courseId };
    pageAction = getAction(addUserIdToParams(instructor4.googleId, submissionParams));
    pageResult = getShowPageResult(pageAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_DETAILS, false, "idOfInstructor4"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals(String.format(Const.StatusMessages.INSTRUCTOR_COURSE_EMPTY, pageResult.data.getInstructorCourseEnrollLink(instructor4.courseId)), pageResult.getStatusMessage());
    pageData = (InstructorCourseDetailsPageData) pageResult.data;
    assertEquals(1, pageData.getInstructors().size());
    assertEquals("idOfCourseNoEvals", pageData.getCourseDetails().course.getId());
    assertEquals("Typical Course 3 with 0 Evals", pageData.getCourseDetails().course.getName());
    assertEquals(0, pageData.getCourseDetails().stats.teamsTotal);
    assertEquals(0, pageData.getCourseDetails().stats.studentsTotal);
    assertEquals(0, pageData.getCourseDetails().stats.unregisteredTotal);
    assertEquals(0, pageData.getCourseDetails().feedbackSessions.size());
    expectedLogMessage = "TEAMMATESLOG|||instructorCourseDetailsPage|||instructorCourseDetailsPage|||true|||" + "Instructor(M)|||Instructor 4 of CourseNoEvals|||idOfInstructor4|||" + "instr4@coursenoevals.tmt|||instructorCourseDetails Page Load<br>Viewing Course " + "Details for Course <span class=\"bold\">[idOfCourseNoEvals]</span>|||" + "/page/instructorCourseDetailsPage";
    AssertHelper.assertLogMessageEqualsInMasqueradeMode(expectedLogMessage, pageAction.getLogMessage(), adminUserId);
    ______TS("HTML Table needed");
    instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    gaeSimulation.loginAsInstructor(instructor1OfCourse1.googleId);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, instructor1OfCourse1.courseId, Const.ParamsNames.CSV_TO_HTML_TABLE_NEEDED, "true" };
    pageAction = getAction(submissionParams);
    AjaxResult ajaxResult = this.getAjaxResult(pageAction);
    assertEquals(getPageResultDestination("", false, "idOfInstructor1OfCourse1"), ajaxResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", ajaxResult.getStatusMessage());
    pageData = (InstructorCourseDetailsPageData) ajaxResult.data;
    assertEquals("<table class=\"table table-bordered table-striped table-condensed\">" + "<tr>" + "<td>Course ID</td>" + "<td>idOfTypicalCourse1</td>" + "</tr>" + "<tr>" + "<td>Course Name</td>" + "<td>Typical Course 1 with 2 Evals</td>" + "</tr>" + "<tr>" + "<td>Section</td>" + "<td>Team</td>" + "<td>Full Name</td>" + "<td>Last Name</td>" + "<td>Status</td>" + "<td>Email</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1&lt;&#x2f;td&gt;&lt;&#x2f;div&gt;&#39;&quot;</td>" + "<td>student1 In Course1&lt;&#x2f;td&gt;&lt;&#x2f;div&gt;&#39;&quot;</td>" + "<td>Course1&lt;&#x2f;td&gt;&lt;&#x2f;div&gt;&#39;&quot;</td>" + "<td>Joined</td>" + "<td>student1InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1&lt;&#x2f;td&gt;&lt;&#x2f;div&gt;&#39;&quot;</td>" + "<td>student2 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student2InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1&lt;&#x2f;td&gt;&lt;&#x2f;div&gt;&#39;&quot;</td>" + "<td>student3 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student3InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 1</td>" + "<td>Team 1.1&lt;&#x2f;td&gt;&lt;&#x2f;div&gt;&#39;&quot;</td>" + "<td>student4 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student4InCourse1@gmail.tmt</td>" + "</tr>" + "<tr>" + "<td>Section 2</td>" + "<td>Team 1.2</td>" + "<td>student5 In Course1</td>" + "<td>Course1</td>" + "<td>Joined</td>" + "<td>student5InCourse1@gmail.tmt</td>" + "</tr>" + "</table>", pageData.getStudentListHtmlTableAsString());
}
Also used : AjaxResult(teammates.ui.controller.AjaxResult) ShowPageResult(teammates.ui.controller.ShowPageResult) InstructorCourseDetailsPageAction(teammates.ui.controller.InstructorCourseDetailsPageAction) InstructorCourseDetailsPageData(teammates.ui.pagedata.InstructorCourseDetailsPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 60 with InstructorAttributes

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

the class InstructorCourseEditPageActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Not enough parameters");
    verifyAssumptionFailure();
    ______TS("Typical case: open the course edit page");
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId };
    InstructorCourseEditPageAction editAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(editAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    InstructorCourseEditPageData data = (InstructorCourseEditPageData) pageResult.data;
    assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
    verifySameInstructorList(InstructorsLogic.inst().getInstructorsForCourse(courseId), data.getInstructorPanelList());
    String expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
    AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
    ______TS("Typical case: open the course edit page with instructor's email");
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, courseId, Const.ParamsNames.INSTRUCTOR_EMAIL, "instr1@course1.tmt", Const.ParamsNames.COURSE_EDIT_MAIN_INDEX, "1" };
    editAction = getAction(submissionParams);
    pageResult = getShowPageResult(editAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor1OfCourse1"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    data = (InstructorCourseEditPageData) pageResult.data;
    assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
    assertEquals(1, data.getInstructorPanelList().size());
    expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
    AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
    ______TS("Masquerade mode");
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor4");
    instructorId = instructor.googleId;
    courseId = instructor.courseId;
    gaeSimulation.loginAsAdmin("admin.user");
    submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId };
    editAction = getAction(submissionParams);
    pageResult = getShowPageResult(editAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_EDIT, false, "idOfInstructor4"), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    data = (InstructorCourseEditPageData) pageResult.data;
    assertEquals(CoursesLogic.inst().getCourse(courseId).toString(), data.getCourse().toString());
    verifySameInstructorList(InstructorsLogic.inst().getInstructorsForCourse(courseId), data.getInstructorPanelList());
    expectedLogSegment = "instructorCourseEdit Page Load<br>" + "Editing information for Course <span class=\"bold\">[" + courseId + "]</span>";
    AssertHelper.assertContains(expectedLogSegment, editAction.getLogMessage());
    ______TS("Failure case: edit a non-existing course");
    CoursesLogic.inst().deleteCourseCascade(courseId);
    submissionParams = new String[] { Const.ParamsNames.USER_ID, instructorId, Const.ParamsNames.COURSE_ID, courseId };
    try {
        editAction = getAction(submissionParams);
        pageResult = getShowPageResult(editAction);
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException e) {
        assertEquals("Trying to access system using a non-existent instructor entity", e.getMessage());
    }
}
Also used : InstructorCourseEditPageAction(teammates.ui.controller.InstructorCourseEditPageAction) ShowPageResult(teammates.ui.controller.ShowPageResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) InstructorCourseEditPageData(teammates.ui.pagedata.InstructorCourseEditPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)325 Test (org.testng.annotations.Test)127 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)84 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)77 ArrayList (java.util.ArrayList)58 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)47 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)46 RedirectResult (teammates.ui.controller.RedirectResult)46 StatusMessage (teammates.common.util.StatusMessage)34 ShowPageResult (teammates.ui.controller.ShowPageResult)31 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)30 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)29 HashMap (java.util.HashMap)25 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)24 InvalidParametersException (teammates.common.exception.InvalidParametersException)24 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)20 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)18 EmailWrapper (teammates.common.util.EmailWrapper)15 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)14 DataBundle (teammates.common.datatransfer.DataBundle)13