Search in sources :

Example 86 with CourseAttributes

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

the class InstructorCourseStudentListDownloadActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    String instructorId = typicalBundle.instructors.get("instructor1OfCourse1").googleId;
    CourseAttributes course = typicalBundle.courses.get("typicalCourse1");
    gaeSimulation.loginAsInstructor(instructorId);
    ______TS("Invalid params");
    String[] submissionParams = {};
    verifyAssumptionFailure(submissionParams);
    submissionParams = new String[] { Const.ParamsNames.COURSE_ID, course.getId() };
    ______TS("Typical case: student list downloaded successfully");
    InstructorCourseStudentListDownloadAction a = getAction(submissionParams);
    FileDownloadResult r = getFileDownloadResult(a);
    String expectedFileName = "idOfTypicalCourse1_studentList";
    assertEquals(expectedFileName, r.getFileName());
    // look at LogicTest.testGetCourseStudentListAsCsv. the logic api to generate Csv file content is tested in LogicTest
    String fileContent = r.getFileContent();
    String[] expected = { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID," + "\"" + course.getId() + "\"", "Course Name," + "\"" + course.getName() + "\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student1 In Course1</td></div>'\"\"\",\"Course1</td></div>'\"\"\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expected, System.lineSeparator()), fileContent);
    assertEquals("", r.getStatusMessage());
    ______TS("Typical case: student list downloaded successfully with student last name specified within braces");
    StudentAttributes student1InCourse1 = typicalBundle.students.get("student1InCourse1");
    student1InCourse1.name = "new name {new last name}";
    StudentsLogic.inst().updateStudentCascade(student1InCourse1.email, student1InCourse1);
    a = getAction(submissionParams);
    r = getFileDownloadResult(a);
    expectedFileName = "idOfTypicalCourse1_studentList";
    assertEquals(expectedFileName, r.getFileName());
    // look at LogicTest.testGetCourseStudentListAsCsv. the logic api to generate Csv file content is tested in LogicTest
    fileContent = r.getFileContent();
    expected = new String[] { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID," + "\"" + course.getId() + "\"", "Course Name," + "\"" + course.getName() + "\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"new name new last name\",\"new last name\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expected, System.lineSeparator()), fileContent);
    assertEquals("", r.getStatusMessage());
    removeAndRestoreTypicalDataBundle();
    ______TS("Typical case: student list downloaded successfully with special team name");
    student1InCourse1 = StudentsLogic.inst().getStudentForEmail("idOfTypicalCourse1", "student1InCourse1@gmail.tmt");
    student1InCourse1.team = "N/A";
    StudentsLogic.inst().updateStudentCascade("student1InCourse1@gmail.tmt", student1InCourse1);
    a = getAction(submissionParams);
    r = getFileDownloadResult(a);
    expectedFileName = "idOfTypicalCourse1_studentList";
    assertEquals(expectedFileName, r.getFileName());
    // look at LogicTest.testGetCourseStudentListAsCsv. the logic api to generate Csv file content is tested in LogicTest
    fileContent = r.getFileContent();
    expected = new String[] { // CHECKSTYLE.OFF:LineLength csv lines can exceed character limit
    "Course ID," + "\"" + course.getId() + "\"", "Course Name," + "\"" + course.getName() + "\"", "", "", "Section,Team,Full Name,Last Name,Status,Email", "\"Section 1\",\"N/A\",\"student1 In Course1</td></div>'\"\"\",\"Course1</td></div>'\"\"\",\"Joined\",\"student1InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student2 In Course1\",\"Course1\",\"Joined\",\"student2InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student3 In Course1\",\"Course1\",\"Joined\",\"student3InCourse1@gmail.tmt\"", "\"Section 1\",\"Team 1.1</td></div>'\"\"\",\"student4 In Course1\",\"Course1\",\"Joined\",\"student4InCourse1@gmail.tmt\"", "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"student5InCourse1@gmail.tmt\"", "" // CHECKSTYLE.ON:LineLength
    };
    assertEquals(StringUtils.join(expected, System.lineSeparator()), fileContent);
    assertEquals("", r.getStatusMessage());
}
Also used : InstructorCourseStudentListDownloadAction(teammates.ui.controller.InstructorCourseStudentListDownloadAction) FileDownloadResult(teammates.ui.controller.FileDownloadResult) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 87 with CourseAttributes

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

the class InstructorFeedbackEditCopyActionTest method testExecuteAndPostProcess.

@Override
@Test
public void testExecuteAndPostProcess() {
    InstructorAttributes instructor = dataBundle.instructors.get("teammates.test.instructor2");
    String instructorId = instructor.googleId;
    FeedbackSessionAttributes fs = dataBundle.feedbackSessions.get("openSession");
    CourseAttributes course = dataBundle.courses.get("course");
    gaeSimulation.loginAsInstructor(instructorId);
    String expectedString = "";
    ______TS("Failure case: No parameters");
    verifyAssumptionFailure();
    ______TS("Failure case: Courses not passed in, instructor home page");
    String[] params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    InstructorFeedbackEditCopyAction a = getAction(params);
    AjaxResult ajaxResult = getAjaxResult(a);
    InstructorFeedbackEditCopyData editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: Courses not passed in, instructor feedbacks page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: Courses not passed in, instructor feedback copy page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: Courses not passed in, instructor feedback edit page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, instructor.courseId, Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name" };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals(Const.StatusMessages.FEEDBACK_SESSION_COPY_NONESELECTED, editCopyData.errorMessage);
    ______TS("Failure case: copying non-existing fs");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "non.existing.fs", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name", Const.ParamsNames.COPIED_COURSES_ID, course.getId() };
    a = getAction(params);
    try {
        ajaxResult = getAjaxResult(a);
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException uae) {
        assertEquals("Trying to access system using a non-existent feedback session entity", uae.getMessage());
    }
    ______TS("Failure case: copying to non-existing course");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "valid name", Const.ParamsNames.COPIED_COURSES_ID, "non.existing.course" };
    a = getAction(params);
    try {
        ajaxResult = getAjaxResult(a);
        signalFailureToDetectException();
    } catch (UnauthorizedAccessException uae) {
        assertEquals("Trying to access system using a non-existent instructor entity", uae.getMessage());
    }
    ______TS("Failure case: course already has feedback session with same name, instructor home page");
    CourseAttributes course6 = dataBundle.courses.get("course6");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: course already has feedback session with same name, instructor feedbacks page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: course already has feedback session with same name, instructor feedback copy page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: course already has feedback session with same name, instructor feedback edit page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "A feedback session with the name \"First Session\" already exists in " + "the following course(s): FeedbackEditCopy.CS2104.";
    assertEquals(expectedString, editCopyData.errorMessage);
    ______TS("Failure case: empty name, instructor home page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Failure case: empty name, instructor feedbacks page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Failure case: empty name, instructor feedback copy page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Failure case: empty name, instructor feedback edit page");
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, "", Const.ParamsNames.COPIED_COURSES_ID, course.getId(), Const.ParamsNames.COPIED_COURSES_ID, course6.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    assertEquals("", editCopyData.redirectUrl);
    expectedString = "The field 'feedback session name' is empty. " + "The value of a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.";
    assertEquals(expectedString, editCopyData.errorMessage);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||true|||" + "Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||tmms.instr@gmail.tmt|||" + "Servlet Action Failure : The field 'feedback session name' is empty. The value of " + "a/an feedback session name should be no longer than 38 characters. " + "It should not be empty.|||/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
    ______TS("Successful case");
    CourseAttributes course7 = dataBundle.courses.get("course7");
    String copiedCourseName = "Session with valid name";
    params = new String[] { Const.ParamsNames.FEEDBACK_SESSION_NAME, "First Session", Const.ParamsNames.COURSE_ID, course.getId(), Const.ParamsNames.COPIED_FEEDBACK_SESSION_NAME, copiedCourseName, Const.ParamsNames.COPIED_COURSES_ID, course6.getId(), Const.ParamsNames.COPIED_COURSES_ID, course7.getId() };
    a = getAction(params);
    ajaxResult = getAjaxResult(a);
    editCopyData = (InstructorFeedbackEditCopyData) ajaxResult.data;
    expectedString = getPageResultDestination(Const.ActionURIs.INSTRUCTOR_FEEDBACK_SESSIONS_PAGE, false, instructor.googleId);
    assertEquals(expectedString, editCopyData.redirectUrl);
    expectedString = "TEAMMATESLOG|||instructorFeedbackEditCopy|||instructorFeedbackEditCopy|||" + "true|||Instructor|||Instructor 2|||FeedbackEditCopyinstructor2|||" + "tmms.instr@gmail.tmt|||Copying to multiple feedback sessions.<br>" + "New Feedback Session <span class=\"bold\">(Session with valid name)</span> " + "for Courses: <br>FeedbackEditCopy.CS2103R,FeedbackEditCopy.CS2102<br>" + "<span class=\"bold\">From:</span> 2012-04-01T21:59:00Z<span class=\"bold\"> " + "to</span> 2026-04-30T21:59:00Z<br><span class=\"bold\">Session visible from:</span> " + "2012-04-01T21:59:00Z<br><span class=\"bold\">Results visible from:</span> " + "2026-05-01T21:59:00Z<br><br><span class=\"bold\">Instructions:</span> " + "<Text: Instructions for first session><br>Copied from " + "<span class=\"bold\">(First Session)</span> " + "for Course <span class=\"bold\">[FeedbackEditCopy.CS2104]</span> created.<br>|||" + "/page/instructorFeedbackEditCopy";
    AssertHelper.assertLogMessageEquals(expectedString, a.getLogMessage());
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AjaxResult(teammates.ui.controller.AjaxResult) UnauthorizedAccessException(teammates.common.exception.UnauthorizedAccessException) InstructorFeedbackEditCopyData(teammates.ui.pagedata.InstructorFeedbackEditCopyData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorFeedbackEditCopyAction(teammates.ui.controller.InstructorFeedbackEditCopyAction) Test(org.testng.annotations.Test)

Example 88 with CourseAttributes

use of teammates.common.datatransfer.attributes.CourseAttributes 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 89 with CourseAttributes

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

the class BaseTestCaseWithDatastoreAccess method verifyEquals.

private void verifyEquals(EntityAttributes<?> expected, EntityAttributes<?> actual) {
    if (expected instanceof AccountAttributes) {
        AccountAttributes expectedAccount = ((AccountAttributes) expected).getCopy();
        AccountAttributes actualAccount = (AccountAttributes) actual;
        equalizeIrrelevantData(expectedAccount, actualAccount);
        assertEquals(JsonUtils.toJson(expectedAccount), JsonUtils.toJson(actualAccount));
    } else if (expected instanceof CourseAttributes) {
        CourseAttributes expectedCourse = (CourseAttributes) expected;
        CourseAttributes actualCourse = (CourseAttributes) actual;
        equalizeIrrelevantData(expectedCourse, actualCourse);
        assertEquals(JsonUtils.toJson(expectedCourse), JsonUtils.toJson(actualCourse));
    } else if (expected instanceof FeedbackQuestionAttributes) {
        FeedbackQuestionAttributes expectedFq = (FeedbackQuestionAttributes) expected;
        FeedbackQuestionAttributes actualFq = (FeedbackQuestionAttributes) actual;
        equalizeIrrelevantData(expectedFq, actualFq);
        assertEquals(JsonUtils.toJson(expectedFq), JsonUtils.toJson(actualFq));
    } else if (expected instanceof FeedbackResponseCommentAttributes) {
        FeedbackResponseCommentAttributes expectedFrc = (FeedbackResponseCommentAttributes) expected;
        FeedbackResponseCommentAttributes actualFrc = (FeedbackResponseCommentAttributes) actual;
        assertEquals(expectedFrc.courseId, actualFrc.courseId);
        assertEquals(expectedFrc.giverEmail, actualFrc.giverEmail);
        assertEquals(expectedFrc.feedbackSessionName, actualFrc.feedbackSessionName);
        assertEquals(expectedFrc.commentText, actualFrc.commentText);
    } else if (expected instanceof FeedbackResponseAttributes) {
        FeedbackResponseAttributes expectedFr = (FeedbackResponseAttributes) expected;
        FeedbackResponseAttributes actualFr = (FeedbackResponseAttributes) actual;
        equalizeIrrelevantData(expectedFr, actualFr);
        assertEquals(JsonUtils.toJson(expectedFr), JsonUtils.toJson(actualFr));
    } else if (expected instanceof FeedbackSessionAttributes) {
        FeedbackSessionAttributes expectedFs = ((FeedbackSessionAttributes) expected).getCopy();
        FeedbackSessionAttributes actualFs = (FeedbackSessionAttributes) actual;
        equalizeIrrelevantData(expectedFs, actualFs);
        assertEquals(JsonUtils.toJson(expectedFs), JsonUtils.toJson(actualFs));
    } else if (expected instanceof InstructorAttributes) {
        InstructorAttributes expectedInstructor = ((InstructorAttributes) expected).getCopy();
        InstructorAttributes actualInstructor = (InstructorAttributes) actual;
        equalizeIrrelevantData(expectedInstructor, actualInstructor);
        assertTrue(expectedInstructor.isEqualToAnotherInstructor(actualInstructor));
    } else if (expected instanceof StudentAttributes) {
        StudentAttributes expectedStudent = ((StudentAttributes) expected).getCopy();
        StudentAttributes actualStudent = (StudentAttributes) actual;
        equalizeIrrelevantData(expectedStudent, actualStudent);
        assertEquals(JsonUtils.toJson(expectedStudent), JsonUtils.toJson(actualStudent));
    } else {
        throw new RuntimeException("Unknown entity type!");
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 90 with CourseAttributes

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

the class BackDoorLogic method deleteCourses.

private void deleteCourses(Collection<CourseAttributes> courses) {
    List<String> courseIds = new ArrayList<>();
    for (CourseAttributes course : courses) {
        courseIds.add(course.getId());
    }
    if (!courseIds.isEmpty()) {
        coursesDb.deleteEntities(courses);
        instructorsDb.deleteInstructorsForCourses(courseIds);
        studentsDb.deleteStudentsForCourses(courseIds);
        fbDb.deleteFeedbackSessionsForCourses(courseIds);
        fqDb.deleteFeedbackQuestionsForCourses(courseIds);
        frDb.deleteFeedbackResponsesForCourses(courseIds);
        fcDb.deleteFeedbackResponseCommentsForCourses(courseIds);
    }
}
Also used : ArrayList(java.util.ArrayList) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes)

Aggregations

CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)106 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 Test (org.testng.annotations.Test)40 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)33 ArrayList (java.util.ArrayList)31 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)19 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)16 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)15 EmailWrapper (teammates.common.util.EmailWrapper)15 HashMap (java.util.HashMap)12 InvalidParametersException (teammates.common.exception.InvalidParametersException)10 EmailGenerator (teammates.logic.api.EmailGenerator)10 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)6 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)5 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)4 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)4 InstructorCoursesPageData (teammates.ui.pagedata.InstructorCoursesPageData)4 InstructorFeedbackSessionsPageData (teammates.ui.pagedata.InstructorFeedbackSessionsPageData)4