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());
    }
  }
Esempio n. 3
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());
    }
  }
Esempio n. 4
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());
    }
  }