Пример #1
0
  public void testIsSampleCourse() {

    ______TS("typical case: not a sample course");

    CourseAttributes c = new CourseAttributes();
    c.id = "course.id";

    assertEquals(false, coursesLogic.isSampleCourse(c.id));

    ______TS("typical case: is a sample course");

    c.id = c.id.concat("-demo3");
    assertEquals(true, coursesLogic.isSampleCourse(c.id));

    ______TS("typical case: is a sample course with '-demo' in the middle of its id");

    c.id = c.id.concat("-demo33");
    assertEquals(true, coursesLogic.isSampleCourse(c.id));

    ______TS("Null parameter");

    try {
      coursesLogic.isSampleCourse(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Course ID is null", e.getMessage());
    }
  }
Пример #2
0
  public void testHasIndicatedSections() throws Exception {

    ______TS("Typical case: course with sections");

    CourseAttributes typicalCourse1 = dataBundle.courses.get("typicalCourse1");
    assertTrue(coursesLogic.hasIndicatedSections(typicalCourse1.id));

    ______TS("Typical case: course without sections");

    CourseAttributes typicalCourse2 = dataBundle.courses.get("typicalCourse2");
    assertEquals(false, coursesLogic.hasIndicatedSections(typicalCourse2.id));

    ______TS("Failure case: course does not exists");

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

    ______TS("Failure case: null parameter");

    try {
      coursesLogic.hasIndicatedSections(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #3
0
  public void testGetCourse() throws Exception {

    ______TS("failure: course doesn't exist");

    assertNull(coursesLogic.getCourse("nonexistant-course"));

    ______TS("success: typical case");

    CourseAttributes c = new CourseAttributes();
    c.id = "Computing101-getthis";
    c.name = "Basic Computing Getting";
    coursesDb.createEntity(c);

    assertEquals(c.id, coursesLogic.getCourse(c.id).id);
    assertEquals(c.name, coursesLogic.getCourse(c.id).name);

    coursesDb.deleteEntity(c);
    ______TS("Null parameter");

    try {
      coursesLogic.getCourse(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #4
0
  public void testGetCoursesForInstructor() throws Exception {

    ______TS("success: instructor with present courses");

    String instructorId = dataBundle.accounts.get("instructor3").googleId;

    List<CourseAttributes> courses = coursesLogic.getCoursesForInstructor(instructorId);

    assertEquals(2, courses.size());

    ______TS("boundary: instructor without any courses");

    instructorId = dataBundle.accounts.get("instructorWithoutCourses").googleId;

    courses = coursesLogic.getCoursesForInstructor(instructorId);

    assertEquals(0, courses.size());

    ______TS("Null parameter");

    try {
      coursesLogic.getCoursesForInstructor(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #5
0
  public void testGetArchivedCoursesForInstructor() throws Exception {

    ______TS("success: instructor with archive course");
    String instructorId = dataBundle.instructors.get("instructorOfArchivedCourse").googleId;

    List<CourseAttributes> archivedCourses =
        coursesLogic.getArchivedCoursesForInstructor(instructorId);

    assertEquals(1, archivedCourses.size());
    assertEquals(true, archivedCourses.get(0).isArchived);

    ______TS("boundary: instructor without archive courses");
    instructorId = dataBundle.instructors.get("instructor1OfCourse1").googleId;

    archivedCourses = coursesLogic.getArchivedCoursesForInstructor(instructorId);

    assertEquals(0, archivedCourses.size());

    ______TS("Null parameter");

    try {
      coursesLogic.getArchivedCoursesForInstructor(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #6
0
  public void testGetNumberOfSections() throws Exception {

    ______TS("Typical case");

    CourseAttributes course = dataBundle.courses.get("typicalCourse1");
    int sectionNum = coursesLogic.getNumberOfSections(course.id);

    assertEquals(2, sectionNum);

    ______TS("Course with no sections");

    course = dataBundle.courses.get("typicalCourse2");
    sectionNum = coursesLogic.getNumberOfSections(course.id);

    assertEquals(0, sectionNum);

    ______TS("non-existent");

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

    ______TS("null parameter");

    try {
      coursesLogic.getNumberOfSections(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #7
0
  public void testVerifyCourseIsPresent() throws Exception {

    ______TS("typical case: verify an inexistent course");

    CourseAttributes c = new CourseAttributes();
    c.id = "non-existent-course";

    try {
      coursesLogic.verifyCourseIsPresent(c.id);
      signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
      AssertHelper.assertContains("Course does not exist: ", e.getMessage());
    }

    ______TS("typical case: verify an existent course");

    c.id = "idOfTypicalCourse1";
    coursesLogic.verifyCourseIsPresent(c.id);

    ______TS("Null parameter");

    try {
      coursesLogic.verifyCourseIsPresent(null);
      signalFailureToDetectException();
    } catch (AssertionError | EntityDoesNotExistException e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #8
0
  public void testGetCoursesForStudentAccount() throws Exception {

    ______TS("student having two courses");

    StudentAttributes studentInTwoCourses = dataBundle.students.get("student2InCourse1");
    List<CourseAttributes> courseList =
        coursesLogic.getCoursesForStudentAccount(studentInTwoCourses.googleId);
    assertEquals(2, courseList.size());
    // For some reason, index 0 is Course2 and index 1 is Course1
    // Anyway in DataStore which follows a HashMap structure,
    // there is no guarantee on the order of Entities' storage
    CourseAttributes course1 = dataBundle.courses.get("typicalCourse2");
    assertEquals(course1.id, courseList.get(0).id);
    assertEquals(course1.name, courseList.get(0).name);

    CourseAttributes course2 = dataBundle.courses.get("typicalCourse1");
    assertEquals(course2.id, courseList.get(1).id);
    assertEquals(course2.name, courseList.get(1).name);

    ______TS("student having one course");

    StudentAttributes studentInOneCourse = dataBundle.students.get("student1InCourse1");
    courseList = coursesLogic.getCoursesForStudentAccount(studentInOneCourse.googleId);
    assertEquals(1, courseList.size());
    course1 = dataBundle.courses.get("typicalCourse1");
    assertEquals(course1.id, courseList.get(0).id);
    assertEquals(course1.name, courseList.get(0).name);

    // Student having zero courses is not applicable

    ______TS("non-existent student");

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

    ______TS("null parameter");

    try {
      coursesLogic.getCoursesForStudentAccount(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #9
0
  public void testCreateCourse() throws Exception {

    /*Explanation:
     * The SUT (i.e. CoursesLogic::createCourse) has only 1 path. Therefore, we
     * should typically have 1 test cases here.
     */
    ______TS("typical case");

    CourseAttributes c = new CourseAttributes();
    c.id = "Computing101-fresh";
    c.name = "Basic Computing";
    coursesLogic.createCourse(c.id, c.name);
    TestHelper.verifyPresentInDatastore(c);
    coursesLogic.deleteCourseCascade(c.id);
    ______TS("Null parameter");

    try {
      coursesLogic.createCourse(null, c.name);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Non-null value expected", e.getMessage());
    }
  }
Пример #10
0
  public void testGetCourseSummariesForInstructor() throws Exception {

    ______TS("Instructor with 2 courses");

    InstructorAttributes instructor = dataBundle.instructors.get("instructor3OfCourse1");
    HashMap<String, CourseDetailsBundle> courseList =
        coursesLogic.getCourseSummariesForInstructor(instructor.googleId);
    assertEquals(2, courseList.size());
    for (CourseDetailsBundle cdd : courseList.values()) {
      // check if course belongs to this instructor
      assertTrue(
          InstructorsLogic.inst()
              .isGoogleIdOfInstructorOfCourse(instructor.googleId, cdd.course.id));
    }

    ______TS("Instructor with 0 courses");
    courseList = coursesLogic.getCourseSummariesForInstructor("instructorWithoutCourses");
    assertEquals(0, courseList.size());

    ______TS("Non-existent instructor");

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

    ______TS("Null parameter");

    try {
      coursesLogic.getCourseSummariesForInstructor(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #11
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());
    }
  }
Пример #12
0
  public void testIsCoursePresent() {

    ______TS("typical case: not an existent course");

    CourseAttributes c = new CourseAttributes();
    c.id = "non-existent-course";

    assertEquals(false, coursesLogic.isCoursePresent(c.id));

    ______TS("typical case: an existent course");

    c.id = "idOfTypicalCourse1";

    assertEquals(true, coursesLogic.isCoursePresent(c.id));

    ______TS("Null parameter");

    try {
      coursesLogic.isCoursePresent(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #13
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());
    }
  }
Пример #14
0
  public void testSetArchiveStatusOfCourse() throws Exception {

    CourseAttributes course = new CourseAttributes("CLogicT.new-course", "New course");
    coursesDb.createEntity(course);

    ______TS("success: archive a course");

    coursesLogic.setArchiveStatusOfCourse(course.id, true);

    CourseAttributes courseRetrieved = coursesLogic.getCourse(course.id);
    assertEquals(true, courseRetrieved.isArchived);

    ______TS("success: unarchive a course");

    coursesLogic.setArchiveStatusOfCourse(course.id, false);

    courseRetrieved = coursesLogic.getCourse(course.id);
    assertEquals(false, courseRetrieved.isArchived);

    ______TS("fail: course doesn't exist");

    coursesDb.deleteCourse(course.id);

    try {
      coursesLogic.setArchiveStatusOfCourse(course.id, true);
      signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
      AssertHelper.assertContains("Course does not exist: CLogicT.new-course", e.getMessage());
    }

    ______TS("Null parameter");

    try {
      coursesLogic.setArchiveStatusOfCourse(null, true);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #15
0
  public void testGetCoursesSummaryWithoutStatsForInstructor() throws Exception {

    ______TS("Typical case");

    HashMap<String, CourseSummaryBundle> courseListForInstructor =
        coursesLogic.getCoursesSummaryWithoutStatsForInstructor("idOfInstructor3");
    assertEquals(2, courseListForInstructor.size());
    String course1Id = "idOfTypicalCourse1";

    // course with 2 evaluations
    ArrayList<EvaluationAttributes> course1Evals =
        courseListForInstructor.get(course1Id).evaluations;
    String course1EvalsAttributes = "";
    for (EvaluationAttributes evalAttr : course1Evals) {
      course1EvalsAttributes =
          course1EvalsAttributes + Utils.getTeammatesGson().toJson(evalAttr) + Const.EOL;
    }
    int numberOfEvalsInCourse1 = course1Evals.size();
    assertEquals(course1EvalsAttributes, 2, numberOfEvalsInCourse1);
    assertEquals(course1Id, course1Evals.get(0).courseId);
    TestHelper.verifyEvaluationInfoExistsInAttributeList(
        dataBundle.evaluations.get("evaluation1InCourse1"), course1Evals);
    TestHelper.verifyEvaluationInfoExistsInAttributeList(
        dataBundle.evaluations.get("evaluation2InCourse1"), course1Evals);

    // course with 1 evaluation
    assertEquals(course1Id, course1Evals.get(1).courseId);
    ArrayList<EvaluationAttributes> course2Evals =
        courseListForInstructor.get("idOfTypicalCourse2").evaluations;
    assertEquals(1, course2Evals.size());
    TestHelper.verifyEvaluationInfoExistsInAttributeList(
        dataBundle.evaluations.get("evaluation1InCourse2"), course2Evals);

    ______TS("Instructor has a course with 0 evaluations");

    courseListForInstructor =
        coursesLogic.getCoursesSummaryWithoutStatsForInstructor("idOfInstructor4");
    assertEquals(1, courseListForInstructor.size());
    assertEquals(0, courseListForInstructor.get("idOfCourseNoEvals").evaluations.size());

    ______TS("Instructor with 0 courses");

    courseListForInstructor =
        coursesLogic.getCoursesSummaryWithoutStatsForInstructor("instructorWithoutCourses");
    assertEquals(0, courseListForInstructor.size());

    ______TS("Non-existent instructor");

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

    ______TS("Null parameter");

    try {
      coursesLogic.getCoursesSummaryWithoutStatsForInstructor(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #16
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());
    }
  }
Пример #17
0
  public void testGetCourseDetailsListForStudent() throws Exception {

    ______TS("student having multiple evaluations in multiple courses");

    CourseAttributes expectedCourse1 = dataBundle.courses.get("typicalCourse1");
    CourseAttributes expectedCourse2 = dataBundle.courses.get("typicalCourse2");

    EvaluationAttributes expectedEval1InCourse1 =
        dataBundle.evaluations.get("evaluation1InCourse1");
    EvaluationAttributes expectedEval2InCourse1 =
        dataBundle.evaluations.get("evaluation2InCourse1");

    EvaluationAttributes expectedEval1InCourse2 =
        dataBundle.evaluations.get("evaluation1InCourse2");

    // This student is in both course 1 and 2
    StudentAttributes studentInBothCourses = dataBundle.students.get("student2InCourse1");

    // Make sure all evaluations in course1 are visible (i.e., not AWAITING)
    expectedEval1InCourse1.startTime = TimeHelper.getDateOffsetToCurrentTime(-2);
    expectedEval1InCourse1.endTime = TimeHelper.getDateOffsetToCurrentTime(-1);
    expectedEval1InCourse1.published = false;
    assertEquals(EvalStatus.CLOSED, expectedEval1InCourse1.getStatus());
    BackDoorLogic backDoorLogic = new BackDoorLogic();
    backDoorLogic.updateEvaluation(expectedEval1InCourse1);

    expectedEval2InCourse1.startTime = TimeHelper.getDateOffsetToCurrentTime(-1);
    expectedEval2InCourse1.endTime = TimeHelper.getDateOffsetToCurrentTime(1);
    assertEquals(EvalStatus.OPEN, expectedEval2InCourse1.getStatus());
    backDoorLogic.updateEvaluation(expectedEval2InCourse1);

    // Make sure all evaluations in course2 are still AWAITING
    expectedEval1InCourse2.startTime = TimeHelper.getDateOffsetToCurrentTime(1);
    expectedEval1InCourse2.endTime = TimeHelper.getDateOffsetToCurrentTime(2);
    expectedEval1InCourse2.activated = false;
    assertEquals(EvalStatus.AWAITING, expectedEval1InCourse2.getStatus());
    backDoorLogic.updateEvaluation(expectedEval1InCourse2);

    // Get course details for student
    List<CourseDetailsBundle> courseList =
        coursesLogic.getCourseDetailsListForStudent(studentInBothCourses.googleId);

    // Verify number of courses received
    assertEquals(2, courseList.size());

    // Verify details of course 1 (note: index of course 1 is not 0)
    CourseDetailsBundle actualCourse1 = courseList.get(1);
    assertEquals(expectedCourse1.id, actualCourse1.course.id);
    assertEquals(expectedCourse1.name, actualCourse1.course.name);
    assertEquals(2, actualCourse1.evaluations.size());

    // Verify details of evaluation 1 in course 1
    EvaluationAttributes actualEval1InCourse1 = actualCourse1.evaluations.get(1).evaluation;
    TestHelper.verifySameEvaluationData(expectedEval1InCourse1, actualEval1InCourse1);

    // Verify some details of evaluation 2 in course 1
    EvaluationAttributes actualEval2InCourse1 = actualCourse1.evaluations.get(0).evaluation;
    TestHelper.verifySameEvaluationData(expectedEval2InCourse1, actualEval2InCourse1);

    // For course 2, verify no evaluations returned (because the evaluation
    // in this course is still AWAITING.
    CourseDetailsBundle actualCourse2 = courseList.get(0);
    assertEquals(expectedCourse2.id, actualCourse2.course.id);
    assertEquals(expectedCourse2.name, actualCourse2.course.name);
    assertEquals(0, actualCourse2.evaluations.size());

    ______TS("student in a course with no evaluations");

    StudentAttributes studentWithNoEvaluations = dataBundle.students.get("student1InCourse2");
    courseList = coursesLogic.getCourseDetailsListForStudent(studentWithNoEvaluations.googleId);
    assertEquals(1, courseList.size());
    assertEquals(0, courseList.get(0).evaluations.size());

    // student with no courses is not applicable

    ______TS("non-existent student");

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

    ______TS("null parameter");

    try {
      coursesLogic.getCourseDetailsListForStudent(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
Пример #18
0
  public void testDeleteCourse() throws Exception {

    ______TS("typical case");

    CourseAttributes course1OfInstructor = dataBundle.courses.get("typicalCourse1");
    StudentAttributes studentInCourse = dataBundle.students.get("student1InCourse1");

    // Ensure there are entities in the datastore under this course
    assertTrue(StudentsLogic.inst().getStudentsForCourse(course1OfInstructor.id).size() != 0);

    TestHelper.verifyPresentInDatastore(course1OfInstructor);
    TestHelper.verifyPresentInDatastore(studentInCourse);
    TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor1OfCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.instructors.get("instructor3OfCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.students.get("student1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.students.get("student5InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1"));
    TestHelper.verifyPresentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1"));
    assertEquals(course1OfInstructor.id, studentInCourse.course);

    coursesLogic.deleteCourseCascade(course1OfInstructor.id);

    // Ensure the course and related entities are deleted
    TestHelper.verifyAbsentInDatastore(course1OfInstructor);
    TestHelper.verifyAbsentInDatastore(studentInCourse);
    TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.evaluations.get("evaluation2InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor1OfCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.instructors.get("instructor3OfCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.students.get("student5InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session1InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.feedbackSessions.get("session2InCourse1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI1C1toS1C1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment2FromI1C1toS1C1"));
    TestHelper.verifyAbsentInDatastore(dataBundle.comments.get("comment1FromI3C1toS2C1"));

    ArrayList<SubmissionAttributes> submissionsOfCourse =
        new ArrayList<SubmissionAttributes>(dataBundle.submissions.values());
    for (SubmissionAttributes s : submissionsOfCourse) {
      if (s.course.equals(course1OfInstructor.id)) {
        TestHelper.verifyAbsentInDatastore(s);
      }
    }

    ______TS("non-existent");

    // try to delete again. Should fail silently.
    coursesLogic.deleteCourseCascade(course1OfInstructor.id);

    ______TS("null parameter");

    try {
      coursesLogic.deleteCourseCascade(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }
  @Test
  public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    String instructorId = instructor.googleId;
    String courseId = instructor.courseId;
    String courseName = CoursesLogic.inst().getCourse(courseId).getName();
    String courseTimeZone = "UTC";
    String statusMessage = "";
    String[] submissionParams;
    InstructorCourseEditSaveAction courseEditSaveAction;
    RedirectResult redirectResult;

    gaeSimulation.loginAsInstructor(instructorId);

    ______TS("Not enough parameters");
    verifyAssumptionFailure();

    ______TS("Typical case: edit course name with same name");
    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, courseId,
          Const.ParamsNames.COURSE_NAME, courseName,
          Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone
        };

    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);

    // get updated results and compare
    statusMessage = Const.StatusMessages.COURSE_EDITED;
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE
            + "?error=false&user="******"&courseid="
            + courseId,
        redirectResult.getDestinationWithParams());

    ______TS("Typical case: edit course name with valid characters");
    String courseNameWithValidCharacters = courseName + " valid";
    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, courseId,
          Const.ParamsNames.COURSE_NAME, courseNameWithValidCharacters,
          Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone
        };

    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);

    // get updated results and compare
    statusMessage = Const.StatusMessages.COURSE_EDITED;
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE
            + "?error=false&user="******"&courseid="
            + courseId,
        redirectResult.getDestinationWithParams());

    ______TS("Failure case: edit course name with empty string");
    courseName = "";
    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, courseId,
          Const.ParamsNames.COURSE_NAME, courseName,
          Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone
        };

    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);

    // get updated results and compare
    statusMessage =
        getPopulatedErrorMessage(
            FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE,
            courseName,
            FieldValidator.COURSE_NAME_FIELD_NAME,
            FieldValidator.REASON_EMPTY,
            FieldValidator.COURSE_NAME_MAX_LENGTH);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE
            + "?error=true&user="******"&courseid="
            + courseId,
        redirectResult.getDestinationWithParams());

    ______TS("Failure case: edit course name with non-alphanumeric start character");
    courseName = "@#$@#$";
    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, courseId,
          Const.ParamsNames.COURSE_NAME, courseName,
          Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone
        };

    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);

    // get updated results and compare
    statusMessage =
        getPopulatedErrorMessage(
            FieldValidator.INVALID_NAME_ERROR_MESSAGE,
            courseName,
            FieldValidator.COURSE_NAME_FIELD_NAME,
            FieldValidator.REASON_START_WITH_NON_ALPHANUMERIC_CHAR);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE
            + "?error=true&user="******"&courseid="
            + courseId,
        redirectResult.getDestinationWithParams());

    ______TS("Failure case: edit course name with name containing | and %");
    courseName = "normal|name%";
    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, courseId,
          Const.ParamsNames.COURSE_NAME, courseName,
          Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone
        };

    // execute the action
    courseEditSaveAction = getAction(submissionParams);
    redirectResult = getRedirectResult(courseEditSaveAction);

    // get updated results and compare
    statusMessage =
        getPopulatedErrorMessage(
            FieldValidator.INVALID_NAME_ERROR_MESSAGE,
            courseName,
            FieldValidator.COURSE_NAME_FIELD_NAME,
            FieldValidator.REASON_CONTAINS_INVALID_CHAR);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE
            + "?error=true&user="******"&courseid="
            + courseId,
        redirectResult.getDestinationWithParams());

    ______TS("Failure case: invalid time zone");
    courseName = CoursesLogic.inst().getCourse(courseId).getName();
    courseTimeZone = "InvalidTimeZone";
    submissionParams =
        new String[] {
          Const.ParamsNames.COURSE_ID, courseId,
          Const.ParamsNames.COURSE_NAME, courseName,
          Const.ParamsNames.COURSE_TIME_ZONE, courseTimeZone
        };

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

    statusMessage =
        getPopulatedErrorMessage(
            FieldValidator.COURSE_TIME_ZONE_ERROR_MESSAGE,
            courseTimeZone,
            FieldValidator.COURSE_TIME_ZONE_FIELD_NAME,
            FieldValidator.REASON_UNAVAILABLE_AS_CHOICE);
    assertEquals(statusMessage, redirectResult.getStatusMessage());
    assertEquals(
        Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE
            + "?error=true&user="******"&courseid="
            + courseId,
        redirectResult.getDestinationWithParams());
  }
  @Test
  public void testExecute() throws Exception {
    InstructorAttributes instructor1OfCourse1 = dataBundle.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");

    Action addAction =
        getAction(
            Const.ParamsNames.COURSE_ID, "ticac,tpa1,id",
            Const.ParamsNames.COURSE_NAME, "ticac tpa1 name");
    ShowPageResult pageResult = (ShowPageResult) addAction.executeAndPostProcess();

    assertEquals(
        Const.ViewURIs.INSTRUCTOR_COURSES + "?error=true&user=idOfInstructor1OfCourse1",
        pageResult.getDestinationWithParams());
    assertEquals(true, pageResult.isError);
    assertEquals(Const.StatusMessages.COURSE_INVALID_ID, pageResult.getStatusMessage());

    InstructorCoursesPageData pageData = (InstructorCoursesPageData) pageResult.data;
    assertEquals(1, pageData.allCourses.size());

    String expectedLogMessage =
        "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd"
            + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1|||[email protected]"
            + "|||Please use only alphabets, numbers, dots, hyphens, underscores and dollar signs in course ID."
            + "|||/page/instructorCourseAdd";
    assertEquals(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");
    pageResult = (ShowPageResult) addAction.executeAndPostProcess();

    pageData = (InstructorCoursesPageData) pageResult.data;
    assertEquals(2, pageData.allCourses.size());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorCourseAdd"
            + "|||instructorCourseAdd|||true|||Instructor|||Instructor 1 of Course 1"
            + "|||idOfInstructor1OfCourse1|||[email protected]"
            + "|||Course added : ticac.tpa1.id<br>Total courses: 2|||/page/instructorCourseAdd";
    assertEquals(expectedLogMessage, addAction.getLogMessage());

    String expected =
        Const.StatusMessages.COURSE_ADDED
            .replace(
                "${courseEnrollLink}",
                "/page/instructorCourseEnrollPage?courseid=ticac.tpa1.id&user=idOfInstructor1OfCourse1")
            .replace(
                "${courseEditLink}",
                "/page/instructorCourseEditPage?courseid=ticac.tpa1.id&user=idOfInstructor1OfCourse1");
    assertEquals(expected, pageResult.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");
    pageResult = (ShowPageResult) addAction.executeAndPostProcess();

    assertEquals(
        Const.ViewURIs.INSTRUCTOR_COURSES + "?error=true&user=idOfInstructor1OfCourse1",
        pageResult.getDestinationWithParams());
    assertEquals(true, pageResult.isError);
    assertEquals(Const.StatusMessages.COURSE_EXISTS, pageResult.getStatusMessage());

    pageData = (InstructorCoursesPageData) pageResult.data;
    assertEquals(2, pageData.allCourses.size());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd"
            + "|||true|||Instructor|||Instructor 1 of Course 1|||idOfInstructor1OfCourse1"
            + "|||[email protected]|||A course by the same ID already exists in the system, possibly created by another user. Please choose a different course ID"
            + "|||/page/instructorCourseAdd";
    assertEquals(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");
    pageResult = (ShowPageResult) addAction.executeAndPostProcess();

    String expectedDestination =
        Const.ViewURIs.INSTRUCTOR_COURSES + "?error=false&user=idOfInstructor1OfCourse1";
    assertEquals(expectedDestination, pageResult.getDestinationWithParams());
    assertEquals(false, pageResult.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, pageResult.getStatusMessage());

    pageData = (InstructorCoursesPageData) pageResult.data;
    assertEquals(1, pageData.allCourses.size());

    expectedLogMessage =
        "TEAMMATESLOG|||instructorCourseAdd|||instructorCourseAdd"
            + "|||true|||Instructor(M)|||Instructor 1 of Course 1"
            + "|||idOfInstructor1OfCourse1|||[email protected]|||Course added : ticac.tpa2.id<br>Total courses: 1"
            + "|||/page/instructorCourseAdd";
    assertEquals(expectedLogMessage, addAction.getLogMessage());

    // delete the new course
    CoursesLogic.inst().deleteCourseCascade("ticac.tpa2.id");
  }
Пример #21
0
  public void testGetCourseStudentListAsCsv() throws Exception {

    ______TS("Typical case: course with section");

    InstructorAttributes instructor1OfCourse1 = dataBundle.instructors.get("instructor1OfCourse1");

    String instructorId = instructor1OfCourse1.googleId;
    String courseId = instructor1OfCourse1.courseId;

    String csvString = coursesLogic.getCourseStudentListAsCsv(courseId, instructorId);
    String expectedCsvString =
        "Course ID,\"idOfTypicalCourse1\""
            + Const.EOL
            + "Course Name,\"Typical Course 1 with 2 Evals\""
            + Const.EOL
            + Const.EOL
            + Const.EOL
            + "Section,Team,Full Name,Last Name,Status,Email"
            + Const.EOL
            + "\"Section 1\",\"Team 1.1\",\"student1 In Course1\",\"Course1\",\"Joined\",\"[email protected]\""
            + Const.EOL
            + "\"Section 1\",\"Team 1.1\",\"student2 In Course1\",\"Course1\",\"Joined\",\"[email protected]\""
            + Const.EOL
            + "\"Section 1\",\"Team 1.1\",\"student3 In Course1\",\"Course1\",\"Joined\",\"[email protected]\""
            + Const.EOL
            + "\"Section 1\",\"Team 1.1\",\"student4 In Course1\",\"Course1\",\"Joined\",\"[email protected]\""
            + Const.EOL
            + "\"Section 2\",\"Team 1.2\",\"student5 In Course1\",\"Course1\",\"Joined\",\"[email protected]\""
            + Const.EOL;

    assertEquals(expectedCsvString, csvString);

    ______TS("Typical case: course without sections");

    InstructorAttributes instructor1OfCourse2 = dataBundle.instructors.get("instructor1OfCourse2");

    instructorId = instructor1OfCourse2.googleId;
    courseId = instructor1OfCourse2.courseId;

    csvString = coursesLogic.getCourseStudentListAsCsv(courseId, instructorId);
    expectedCsvString =
        "Course ID,\"idOfTypicalCourse1\""
            + Const.EOL
            + "Course Name,\"Typical Course 1 with 2 Evals\""
            + Const.EOL
            + Const.EOL
            + Const.EOL
            + "Team,Full Name,Last Name,Status,Email"
            + Const.EOL
            + "\"Team 2.1\",\"student1 In Course2\",\"Course2\",\"Joined\",\"[email protected]\""
            + Const.EOL
            + "\"Team 2.1\",\"student2 In Course2\",\"Course2\",\"Joined\",\"[email protected]\""
            + Const.EOL;

    ______TS("Typical case: course with unregistered student");

    InstructorAttributes instructor5 = dataBundle.instructors.get("instructor5");

    instructorId = instructor5.googleId;
    courseId = instructor5.courseId;

    csvString = coursesLogic.getCourseStudentListAsCsv(courseId, instructorId);
    expectedCsvString =
        "Course ID,\"idOfUnregisteredCourse\""
            + Const.EOL
            + "Course Name,\"Unregistered Course\""
            + Const.EOL
            + Const.EOL
            + Const.EOL
            + "Section,Team,Full Name,Last Name,Status,Email"
            + Const.EOL
            + "\"Section 1\",\"Team 1\",\"student1 In unregisteredCourse\",\"unregisteredCourse\",\"Yet to join\",\"[email protected]\""
            + Const.EOL
            + "\"Section 2\",\"Team 2\",\"student2 In unregisteredCourse\",\"unregisteredCourse\",\"Yet to join\",\"[email protected]\""
            + Const.EOL;

    assertEquals(expectedCsvString, csvString);

    ______TS("Failure case: non existent instructor");

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

    ______TS("Failure case: non existent course in the list of courses of the instructor");

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

    ______TS("Failure case: null parameter");

    try {
      coursesLogic.getCourseStudentListAsCsv(courseId, null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }