예제 #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());
    }
  }
예제 #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 {
    StudentsDb studentsDb = new StudentsDb();
    AccountsDb accountsDb = new AccountsDb();

    StudentAttributes student1InCourse1 = dataBundle.students.get("student1InCourse1");
    student1InCourse1 =
        studentsDb.getStudentForGoogleId(student1InCourse1.course, student1InCourse1.googleId);

    gaeSimulation.loginAsStudent(student1InCourse1.googleId);

    ______TS("not enough parameters");

    verifyAssumptionFailure();

    ______TS("invalid key");

    String invalidKey = StringHelper.encrypt("invalid key");
    String[] submissionParams =
        new String[] {
          Const.ParamsNames.REGKEY,
          invalidKey,
          Const.ParamsNames.NEXT_URL,
          Const.ActionURIs.STUDENT_HOME_PAGE
        };

    try {
      StudentCourseJoinAuthenticatedAction authenticatedAction = getAction(submissionParams);
      getRedirectResult(authenticatedAction);
    } catch (UnauthorizedAccessException uae) {
      assertEquals("No student with given registration key:" + invalidKey, uae.getMessage());
    }

    ______TS("already registered student");

    submissionParams =
        new String[] {
          Const.ParamsNames.REGKEY,
          StringHelper.encrypt(student1InCourse1.key),
          Const.ParamsNames.NEXT_URL,
          Const.ActionURIs.STUDENT_PROFILE_PAGE
        };

    StudentCourseJoinAuthenticatedAction authenticatedAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(authenticatedAction);

    assertEquals(
        Const.ActionURIs.STUDENT_HOME_PAGE + "?error=true&user="******"You (student1InCourse1) have already joined this course",
        redirectResult.getStatusMessage());

    /*______TS("student object belongs to another account");

            StudentAttributes student2InCourse1 = dataBundle.students
                    .get("student2InCourse1");
            student2InCourse1 = studentsDb.getStudentForGoogleId(
                    student2InCourse1.course, student2InCourse1.googleId);

            submissionParams = new String[] {
                    Const.ParamsNames.REGKEY,
                    StringHelper.encrypt(student2InCourse1.key),
                    Const.ParamsNames.NEXT_URL, Const.ActionURIs.STUDENT_HOME_PAGE
            };

            authenticatedAction = getAction(submissionParams);
            redirectResult = getRedirectResult(authenticatedAction);

            assertEquals(
                    Const.ActionURIs.STUDENT_HOME_PAGE
                            + "?persistencecourse=" + student1InCourse1.course
                            + "&error=true&user="******"The join link used belongs to a different user"
                            + " whose Google ID is stude..ourse1 "
                            + "(only part of the Google ID is shown to protect privacy)."
                            + " If that Google ID is owned by you, "
                            + "please logout and re-login using that Google account."
                            + " If it doesn’t belong to you, please "
                            + "<a href=\"mailto:" + Config.SUPPORT_EMAIL
                            + "?body=Your name:%0AYour course:%0AYour university:\">"
                            + "contact us</a> so that we can investigate.",
                    redirectResult.getStatusMessage());
    */
    ______TS("join course with no feedback sessions, profile is empty");
    AccountAttributes studentWithEmptyProfile = dataBundle.accounts.get("noFSStudent");
    studentWithEmptyProfile = accountsDb.getAccount(studentWithEmptyProfile.googleId, true);
    assertNotNull(studentWithEmptyProfile.studentProfile);
    assertEquals("", studentWithEmptyProfile.studentProfile.pictureKey);
    assertEquals("", studentWithEmptyProfile.studentProfile.shortName);
    assertEquals("", studentWithEmptyProfile.studentProfile.nationality);
    assertEquals("", studentWithEmptyProfile.studentProfile.moreInfo);
    assertEquals("", studentWithEmptyProfile.studentProfile.email);

    StudentAttributes studentWithEmptyProfileAttributes =
        dataBundle.students.get("noFSStudentWithNoProfile");
    studentWithEmptyProfileAttributes =
        studentsDb.getStudentForEmail(
            studentWithEmptyProfileAttributes.course, studentWithEmptyProfileAttributes.email);

    gaeSimulation.loginUser("idOfNoFSStudent");

    submissionParams =
        new String[] {
          Const.ParamsNames.REGKEY,
          StringHelper.encrypt(studentWithEmptyProfileAttributes.key),
          Const.ParamsNames.NEXT_URL,
          Const.ActionURIs.STUDENT_HOME_PAGE
        };

    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);

    assertEquals(
        Const.ActionURIs.STUDENT_HOME_PAGE
            + "?persistencecourse=idOfCourseNoEvals"
            + "&error=false&user=idOfNoFSStudent",
        redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(
        String.format(
                Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL,
                "[idOfCourseNoEvals] Typical Course 3 with 0 Evals")
            + "<br>"
            + String.format(
                Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT,
                "[idOfCourseNoEvals] Typical Course 3 with 0 Evals")
            + "<br>"
            + Const.StatusMessages.STUDENT_UPDATE_PROFILE,
        redirectResult.getStatusMessage());

    ______TS("join course with no feedback sessions, profile has only one missing field");
    AccountAttributes studentWithoutProfilePicture = dataBundle.accounts.get("noFSStudent2");
    studentWithoutProfilePicture =
        accountsDb.getAccount(studentWithoutProfilePicture.googleId, true);
    assertNotNull(studentWithoutProfilePicture.studentProfile);
    assertEquals("", studentWithoutProfilePicture.studentProfile.pictureKey);
    assertFalse(studentWithoutProfilePicture.studentProfile.nationality.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.shortName.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.moreInfo.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.email.isEmpty());

    StudentAttributes studentWithoutProfilePictureAttributes =
        dataBundle.students.get("noFSStudentWithPartialProfile");

    studentWithoutProfilePictureAttributes =
        studentsDb.getStudentForEmail(
            studentWithoutProfilePictureAttributes.course,
            studentWithoutProfilePictureAttributes.email);

    gaeSimulation.loginUser("idOfNoFSStudent2");

    submissionParams =
        new String[] {
          Const.ParamsNames.REGKEY,
          StringHelper.encrypt(studentWithoutProfilePictureAttributes.key),
          Const.ParamsNames.NEXT_URL,
          Const.ActionURIs.STUDENT_HOME_PAGE
        };

    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);

    assertEquals(
        Const.ActionURIs.STUDENT_HOME_PAGE
            + "?persistencecourse=idOfCourseNoEvals"
            + "&error=false&user=idOfNoFSStudent2",
        redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(
        String.format(
                Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL,
                "[idOfCourseNoEvals] Typical Course 3 with 0 Evals")
            + "<br>"
            + String.format(
                Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT,
                "[idOfCourseNoEvals] Typical Course 3 with 0 Evals")
            + "<br>"
            + Const.StatusMessages.STUDENT_UPDATE_PROFILE_PICTURE,
        redirectResult.getStatusMessage());

    ______TS("join course with no feedback sessions, profile has no missing field");
    AccountAttributes studentWithFullProfile = dataBundle.accounts.get("noFSStudent3");

    studentWithFullProfile = accountsDb.getAccount(studentWithFullProfile.googleId, true);
    assertNotNull(studentWithFullProfile.studentProfile);
    assertFalse(studentWithFullProfile.studentProfile.pictureKey.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.nationality.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.shortName.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.moreInfo.isEmpty());
    assertFalse(studentWithoutProfilePicture.studentProfile.email.isEmpty());

    StudentAttributes studentWithFullProfileAttributes =
        dataBundle.students.get("noFSStudentWithFullProfile");
    studentWithFullProfileAttributes =
        studentsDb.getStudentForEmail(
            studentWithFullProfileAttributes.course, studentWithFullProfileAttributes.email);

    gaeSimulation.loginUser("idOfNoFSStudent3");

    submissionParams =
        new String[] {
          Const.ParamsNames.REGKEY,
          StringHelper.encrypt(studentWithFullProfileAttributes.key),
          Const.ParamsNames.NEXT_URL,
          Const.ActionURIs.STUDENT_HOME_PAGE
        };

    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);

    assertEquals(
        Const.ActionURIs.STUDENT_HOME_PAGE
            + "?persistencecourse=idOfCourseNoEvals"
            + "&error=false&user=idOfNoFSStudent3",
        redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(
        String.format(
                Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL,
                "[idOfCourseNoEvals] Typical Course 3 with 0 Evals")
            + "<br>"
            + String.format(
                Const.StatusMessages.HINT_FOR_NO_SESSIONS_STUDENT,
                "[idOfCourseNoEvals] Typical Course 3 with 0 Evals"),
        redirectResult.getStatusMessage());

    ______TS("typical case");

    AccountAttributes newStudentAccount =
        new AccountAttributes(
            "idOfNewStudent",
            "nameOfNewStudent",
            false,
            "*****@*****.**",
            "TEAMMATES Test Institute 5");
    accountsDb.createAccount(newStudentAccount);

    StudentAttributes newStudentAttributes =
        new StudentAttributes(
            student1InCourse1.section,
            student1InCourse1.team,
            "nameOfNewStudent",
            "*****@*****.**",
            "This is a new student",
            student1InCourse1.course);

    studentsDb.createEntity(newStudentAttributes);
    newStudentAttributes =
        studentsDb.getStudentForEmail(newStudentAttributes.course, newStudentAttributes.email);

    gaeSimulation.loginUser("idOfNewStudent");

    submissionParams =
        new String[] {
          Const.ParamsNames.REGKEY,
          StringHelper.encrypt(newStudentAttributes.key),
          Const.ParamsNames.NEXT_URL,
          Const.ActionURIs.STUDENT_PROFILE_PAGE
        };

    authenticatedAction = getAction(submissionParams);
    redirectResult = getRedirectResult(authenticatedAction);

    assertEquals(
        Const.ActionURIs.STUDENT_PROFILE_PAGE
            + "?persistencecourse=idOfTypicalCourse1"
            + "&error=false&user=idOfNewStudent",
        redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals(
        String.format(
            Const.StatusMessages.STUDENT_COURSE_JOIN_SUCCESSFUL,
            "[idOfTypicalCourse1] Typical Course 1 with 2 Evals"),
        redirectResult.getStatusMessage());
  }
예제 #4
0
  public void testCreateCourseAndInstructor() throws Exception {

    /* Explanation: SUT has 5 paths. They are,
     * path 1 - exit because the account doesn't' exist.
     * path 2 - exit because the account exists but doesn't have instructor privileges.
     * path 3 - exit because course creation failed.
     * path 4 - exit because instructor creation failed.
     * path 5 - success.
     * Accordingly, we have 5 test cases.
     */

    ______TS("fails: account doesn't exist");

    CourseAttributes c = new CourseAttributes();
    c.id = "fresh-course-tccai";
    c.name = "Fresh course for tccai";

    @SuppressWarnings("deprecation")
    InstructorAttributes i =
        new InstructorAttributes(
            "instructor-for-tccai", c.id, "Instructor for tccai", "*****@*****.**");

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains("for a non-existent instructor", e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);
    TestHelper.verifyAbsentInDatastore(i);

    ______TS("fails: account doesn't have instructor privileges");

    AccountAttributes a = new AccountAttributes();
    a.googleId = i.googleId;
    a.name = i.name;
    a.email = i.email;
    a.institute = "TEAMMATES Test Institute 5";
    a.isInstructor = false;
    a.studentProfile = new StudentProfileAttributes();
    a.studentProfile.googleId = i.googleId;
    accountsDb.createAccount(a);
    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains("doesn't have instructor privileges", e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);
    TestHelper.verifyAbsentInDatastore(i);

    ______TS("fails: error during course creation");

    a.isInstructor = true;
    accountsDb.updateAccount(a);

    c.id = "invalid id";

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (InvalidParametersException e) {
      AssertHelper.assertContains("not acceptable to TEAMMATES as a Course ID", e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);
    TestHelper.verifyAbsentInDatastore(i);

    ______TS("fails: error during instructor creation due to duplicate instructor");

    c.id = "fresh-course-tccai";
    instructorsDb.createEntity(i); // create a duplicate instructor

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains(
          "Unexpected exception while trying to create instructor for a new course",
          e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);

    ______TS("fails: error during instructor creation due to invalid parameters");

    i.email = "ins.for.iccai.gmail.tmt";

    try {
      coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      AssertHelper.assertContains(
          "Unexpected exception while trying to create instructor for a new course",
          e.getMessage());
    }
    TestHelper.verifyAbsentInDatastore(c);

    ______TS("success: typical case");

    i.email = "*****@*****.**";

    // remove the duplicate instructor object from the datastore.
    instructorsDb.deleteInstructor(i.courseId, i.email);

    coursesLogic.createCourseAndInstructor(i.googleId, c.id, c.name);
    TestHelper.verifyPresentInDatastore(c);
    TestHelper.verifyPresentInDatastore(i);

    ______TS("Null parameter");

    try {
      coursesLogic.createCourseAndInstructor(null, c.id, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }