Example #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());
    }
  }
Example #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 {
    InstructorsDb instrDb = new InstructorsDb();

    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    instructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);

    gaeSimulation.loginAsInstructor(instructor.googleId);

    ______TS("not enough parameters");

    verifyAssumptionFailure();

    ______TS("invalid key");

    String[] submissionParams = new String[] {Const.ParamsNames.REGKEY, "invalidKey"};

    InstructorCourseJoinAuthenticatedAction a = getAction(submissionParams);
    RedirectResult r = (RedirectResult) a.executeAndPostProcess();

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_HOME_PAGE
            + "?message=You+have+used+an+invalid+join+link"
            + "%3A+%2Fpage%2FinstructorCourseJoin%3Fregkey%3DinvalidKey"
            + "&error=true&user="******"instructor already registered");

    submissionParams =
        new String[] {Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key)};

    a = getAction(submissionParams);
    r = (RedirectResult) a.executeAndPostProcess();

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_HOME_PAGE
            + "?message=idOfInstructor1OfCourse1+has+already+joined+this+course"
            + "&persistencecourse="
            + instructor.courseId
            + "&error=true&user="******"instructor object belongs to another account");

    InstructorAttributes instructor2 = dataBundle.instructors.get("instructor2OfCourse1");
    instructor2 = instrDb.getInstructorForGoogleId(instructor2.courseId, instructor2.googleId);

    submissionParams =
        new String[] {Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor2.key)};

    a = getAction(submissionParams);
    r = (RedirectResult) a.executeAndPostProcess();

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_HOME_PAGE
            + "?message=The+join+link+used+belongs+to+a+different+user"
            + "+whose+Google+ID+is+idOfInst..fCourse1"
            + "+%28only+part+of+the+Google+ID+is+shown+to+protect+privacy%29."
            + "+If+that+Google+ID+is+owned+by+you%2C+please+logout+and"
            + "+re-login+using+that+Google+account.+If+it+doesn%E2%80%99t"
            + "+belong+to+you%2C+please+%3Ca+href%3D%22mailto"
            + "%3Ateammates%40comp.nus.edu.sg%3Fbody%3D"
            + "Your+name%3A%250AYour+course%3A%250AYour+university%3A%22%3E"
            + "contact+us%3C%2Fa%3E+so+that+we+can+investigate."
            + "&persistencecourse="
            + instructor2.courseId
            + "&error=true&user="******"typical case");

    instructor =
        new InstructorAttributes(
            "ICJAAT.instr", instructor.courseId, "New Instructor", "*****@*****.**");
    InstructorsLogic.inst().addInstructor(instructor.courseId, instructor.name, instructor.email);

    AccountAttributes newInstructorAccount =
        new AccountAttributes(instructor.googleId, instructor.name, false, instructor.email, "NUS");
    AccountsLogic.inst().createAccount(newInstructorAccount);

    InstructorAttributes newInstructor =
        instrDb.getInstructorForEmail(instructor.courseId, instructor.email);

    gaeSimulation.loginUser(instructor.googleId);

    submissionParams =
        new String[] {Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key)};

    a = getAction(submissionParams);
    r = (RedirectResult) a.executeAndPostProcess();

    assertEquals(
        Const.ActionURIs.INSTRUCTOR_HOME_PAGE
            + "?persistencecourse=idOfTypicalCourse1"
            + "&error=false&user=ICJAAT.instr",
        r.getDestinationWithParams());
    assertFalse(r.isError);

    InstructorAttributes retrievedInstructor =
        instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    assertEquals(instructor.googleId, retrievedInstructor.googleId);
  }