Example #1
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());
    }
  }
Example #2
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());
    }
  }
Example #3
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());
    }
  }
Example #4
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());
    }
  }
Example #5
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());
    }
  }
Example #6
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());
    }
  }