Esempio n. 1
0
  @Test
  public void testGetStudent() throws InvalidParametersException, EntityDoesNotExistException {
    int currentNumberOfStudent = studentsDb.getAllStudents().size();
    StudentAttributes s = createNewStudent();
    s.googleId = "validGoogleId";
    s.googleId = "validTeam";
    studentsDb.updateStudent(s.course, s.email, s.name, s.team, s.email, s.googleId, s.comments);

    ______TS("typical success case: existent");
    StudentAttributes retrieved = studentsDb.getStudentForEmail(s.course, s.email);
    assertNotNull(retrieved);
    assertNotNull(studentsDb.getStudentForRegistrationKey(retrieved.key));
    assertNotNull(studentsDb.getStudentForRegistrationKey(StringHelper.encrypt(retrieved.key)));
    assertNull(studentsDb.getStudentForRegistrationKey("notExistingKey"));
    ______TS("non existant student case");
    retrieved = studentsDb.getStudentForEmail("any-course-id", "*****@*****.**");
    assertNull(retrieved);

    StudentAttributes s2 = createNewStudent("*****@*****.**");
    s2.googleId = "validGoogleId2";
    studentsDb.updateStudent(
        s2.course, s2.email, s2.name, s2.team, s2.email, s2.googleId, s2.comments);
    studentsDb.deleteStudentsForGoogleId(s2.googleId);
    assertNull(studentsDb.getStudentForGoogleId(s2.course, s2.googleId));

    s2 = createNewStudent("*****@*****.**");
    assertEquals(
        true, studentsDb.getUnregisteredStudentsForCourse(s2.course).get(0).isEnrollInfoSameAs(s2));

    s2.googleId = null;
    studentsDb.updateStudent(
        s2.course, s2.email, s2.name, s2.team, s2.email, s2.googleId, s2.comments);
    assertEquals(
        true, studentsDb.getUnregisteredStudentsForCourse(s2.course).get(0).isEnrollInfoSameAs(s2));

    assertTrue(s.isEnrollInfoSameAs(studentsDb.getStudentsForGoogleId(s.googleId).get(0)));
    assertEquals(true, studentsDb.getStudentsForCourse(s.course).get(0).isEnrollInfoSameAs(s));
    assertEquals(
        true, studentsDb.getStudentsForTeam(s.team, s.course).get(0).isEnrollInfoSameAs(s));
    assertEquals(2 + currentNumberOfStudent, studentsDb.getAllStudents().size());

    ______TS("null params case");
    try {
      studentsDb.getStudentForEmail(null, "*****@*****.**");
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }
    try {
      studentsDb.getStudentForEmail("any-course-id", null);
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }
  }
Esempio n. 2
0
  @Test
  public void testDeleteStudent() throws InvalidParametersException, EntityDoesNotExistException {
    StudentAttributes s = createNewStudent();
    s.googleId = "validGoogleId";
    studentsDb.updateStudent(s.course, s.email, s.name, s.team, s.email, s.googleId, s.comments);
    // Delete
    studentsDb.deleteStudent(s.course, s.email);

    StudentAttributes deleted = studentsDb.getStudentForEmail(s.course, s.email);

    assertNull(deleted);
    studentsDb.deleteStudentsForGoogleId(s.googleId);
    assertEquals(null, studentsDb.getStudentForGoogleId(s.course, s.googleId));
    int currentStudentNum = studentsDb.getAllStudents().size();
    s = createNewStudent();
    createNewStudent("*****@*****.**");
    assertEquals(2 + currentStudentNum, studentsDb.getAllStudents().size());
    studentsDb.deleteStudentsForCourse(s.course);
    assertEquals(currentStudentNum, studentsDb.getAllStudents().size());
    // delete again - should fail silently
    studentsDb.deleteStudent(s.course, s.email);

    // Null params check:
    try {
      studentsDb.deleteStudent(null, s.email);
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }

    try {
      studentsDb.deleteStudent(s.course, null);
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }
  }