Esempio n. 1
0
  public void testGetCourseSummaryWithoutStats() throws Exception {

    ______TS("typical case");

    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    CourseSummaryBundle courseSummary = coursesLogic.getCourseSummaryWithoutStats(course.id);
    assertEquals(course.id, courseSummary.course.id);
    assertEquals(course.name, courseSummary.course.name);
    assertEquals(false, courseSummary.course.isArchived);

    assertEquals(0, courseSummary.evaluations.size());
    assertEquals(0, courseSummary.sections.size());

    ______TS("course without students");

    StudentProfileAttributes spa = new StudentProfileAttributes();
    spa.googleId = "instructor1";

    AccountsLogic.inst()
        .createAccount(
            new AccountAttributes(
                "instructor1",
                "Instructor 1",
                true,
                "*****@*****.**",
                "TEAMMATES Test Institute 1",
                spa));
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1");
    courseSummary = coursesLogic.getCourseSummaryWithoutStats("course1");
    assertEquals("course1", courseSummary.course.id);
    assertEquals("course 1", courseSummary.course.name);

    assertEquals(0, courseSummary.evaluations.size());
    assertEquals(0, courseSummary.sections.size());

    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");

    ______TS("non-existent");

    try {
      coursesLogic.getCourseSummaryWithoutStats("non-existent-course");
      signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
      AssertHelper.assertContains("The course does not exist:", e.getMessage());
    }

    ______TS("null parameter");

    try {
      coursesLogic.getCourseSummaryWithoutStats(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Esempio n. 2
0
  public void testGetTeamsForCourse() throws Exception {

    ______TS("typical case");

    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    List<TeamDetailsBundle> teams = coursesLogic.getTeamsForCourse(course.id);

    assertEquals(2, teams.size());
    assertEquals("Team 1.1", teams.get(0).name);
    assertEquals("Team 1.2", teams.get(1).name);

    ______TS("course without students");

    StudentProfileAttributes spa = new StudentProfileAttributes();
    spa.googleId = "instructor1";

    AccountsLogic.inst()
        .createAccount(
            new AccountAttributes(
                "instructor1",
                "Instructor 1",
                true,
                "*****@*****.**",
                "TEAMMATES Test Institute 1",
                spa));
    coursesLogic.createCourseAndInstructor("instructor1", "course1", "course 1");
    teams = coursesLogic.getTeamsForCourse("course1");

    assertEquals(0, teams.size());

    coursesLogic.deleteCourseCascade("course1");
    accountsDb.deleteAccount("instructor1");

    ______TS("non-existent");

    try {
      coursesLogic.getTeamsForCourse("non-existent-course");
      signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
      AssertHelper.assertContains("does not exist", e.getMessage());
    }

    ______TS("null parameter");

    try {
      coursesLogic.getTeamsForCourse(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
  @Test
  public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = dataBundle.instructors.get("instructor3OfCourse1");
    StudentAttributes student = dataBundle.students.get("student2InCourse1");
    String instructorId = instructor.googleId;

    gaeSimulation.loginAsInstructor(instructorId);

    ______TS("Invalid parameters");

    // no params
    verifyAssumptionFailure();

    // null courseId
    String[] invalidParams = new String[] {Const.ParamsNames.STUDENT_EMAIL, student.email};

    verifyAssumptionFailure(invalidParams);

    // null student email
    invalidParams = new String[] {Const.ParamsNames.COURSE_ID, instructor.courseId};

    verifyAssumptionFailure(invalidParams);

    // student not in course
    String studentEmailOfStudent1InCourse2 = dataBundle.students.get("student1InCourse2").email;
    invalidParams =
        new String[] {
          Const.ParamsNames.COURSE_ID,
          instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL,
          studentEmailOfStudent1InCourse2
        };

    RedirectResult redirect = getRedirectResult(getAction(invalidParams));

    AssertHelper.assertContains(
        Const.ActionURIs.INSTRUCTOR_HOME_PAGE, redirect.getDestinationWithParams());
    AssertHelper.assertContains(
        Const.StatusMessages.STUDENT_NOT_FOUND_FOR_RECORDS, redirect.getStatusMessage());

    ______TS("Typical case: student has some records and has profile");

    String[] submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email
        };

    InstructorStudentRecordsPageAction a = getAction(submissionParams);
    ShowPageResult r = getShowPageResult(a);

    assertEquals(
        Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS + "?error=false&user=idOfInstructor3",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals("", r.getStatusMessage());

    InstructorStudentRecordsPageData actualData = (InstructorStudentRecordsPageData) r.data;
    StudentProfileAttributes expectedProfile = new StudentProfileAttributes();
    expectedProfile.googleId = student.googleId;
    expectedProfile.modifiedDate = actualData.spa.modifiedDate;
    expectedProfile.pictureKey = actualData.spa.pictureKey;

    assertEquals(instructorId, actualData.account.googleId);
    assertEquals(instructor.courseId, actualData.getCourseId());
    assertEquals(1, actualData.getCommentsForStudentTable().get(0).getRows().size());
    assertEquals(6, actualData.getSessionNames().size());
    assertEquals(student.googleId, actualData.spa.googleId);

    String expectedLogMessage =
        "TEAMMATESLOG|||instructorStudentRecordsPage|||instructorStudentRecordsPage"
            + "|||true|||Instructor|||Instructor 3 of Course 1 and 2|||idOfInstructor3"
            + "|||[email protected]|||instructorStudentRecords Page Load<br>"
            + "Viewing <span class=\"bold\">"
            + student.email
            + "'s</span> records "
            + "for Course <span class=\"bold\">["
            + instructor.courseId
            + "]</span><br>"
            + "Number of sessions: 6<br>"
            + "Student Profile: "
            + expectedProfile.toString()
            + "|||/page/instructorStudentRecordsPage";
    AssertHelper.assertLogMessageEquals(expectedLogMessage, a.getLogMessage());

    ______TS("Typical case: instructor cannot view sections");

    instructor = dataBundle.instructors.get("helperOfCourse1");
    gaeSimulation.loginAsInstructor(instructor.googleId);

    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, instructor.courseId,
          Const.ParamsNames.STUDENT_EMAIL, student.email
        };

    a = getAction(submissionParams);
    r = getShowPageResult(a);

    assertEquals(
        Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS + "?error=false&user=idOfHelperOfCourse1",
        r.getDestinationWithParams());
    assertFalse(r.isError);
    assertEquals(
        "Normally, we would show the student’s profile here. "
            + "However, you do not have access to view this student's profile<br>"
            + "No records were found for this student",
        r.getStatusMessage());

    ______TS("Typical case: student has no records, no profiles");

    String instructor4Id = dataBundle.instructors.get("instructor4").googleId;
    // re-login as another instructor for new test
    gaeSimulation.loginAsInstructor(instructor4Id);
    String courseIdWithNoSession = "idOfCourseNoEvals";

    StudentAttributes testStudent = createStudentInTypicalDataBundleForCourseWithNoSession();

    String[] submissionParamsWithNoSession =
        new String[] {
          Const.ParamsNames.COURSE_ID,
          courseIdWithNoSession,
          Const.ParamsNames.STUDENT_EMAIL,
          "*****@*****.**"
        };

    InstructorStudentRecordsPageAction aWithNoSession = getAction(submissionParamsWithNoSession);
    ShowPageResult rWithNoSession = getShowPageResult(aWithNoSession);
    List<String> expectedMessages = new ArrayList<String>();
    expectedMessages.add("No records were found for this student");
    expectedMessages.add(Const.StatusMessages.STUDENT_NOT_JOINED_YET_FOR_RECORDS);
    AssertHelper.assertContains(expectedMessages, rWithNoSession.getStatusMessage());

    ______TS("Typical case: student has profile but no records");

    testStudent.googleId = "valid.no.sessions";
    StudentsLogic.inst().updateStudentCascadeWithoutDocument(testStudent.email, testStudent);
    logic.createAccount(
        testStudent.googleId, testStudent.name, false, testStudent.email, "valid institute");

    a = getAction(submissionParamsWithNoSession);
    r = getShowPageResult(a);

    AssertHelper.assertContains("No records were found for this student", r.getStatusMessage());
  }