예제 #1
0
  @Test
  public void testCreateStudent() throws EntityAlreadyExistsException, InvalidParametersException {

    StudentAttributes s = new StudentAttributes();
    s.name = "valid student";
    s.email = "*****@*****.**";
    s.team = "validTeamName";
    s.comments = "";
    s.googleId = "validGoogleId";

    ______TS("fail : invalid params");
    s.course = "invalid id space";
    try {
      studentsDb.createEntity(s);
      Assert.fail();
    } catch (InvalidParametersException e) {
      AssertHelper.assertContains(
          String.format(COURSE_ID_ERROR_MESSAGE, s.course, REASON_INCORRECT_FORMAT),
          e.getMessage());
    }
    LogicTest.verifyAbsentInDatastore(s);

    ______TS("success : valid params");
    s.course = "valid-course";
    studentsDb.createEntity(s);
    LogicTest.verifyPresentInDatastore(s);
    StudentAttributes retrievedStudent = studentsDb.getStudentForGoogleId(s.course, s.googleId);
    assertEquals(true, retrievedStudent.isEnrollInfoSameAs(s));
    assertEquals(null, studentsDb.getStudentForGoogleId(s.course + "not existing", s.googleId));
    assertEquals(null, studentsDb.getStudentForGoogleId(s.course, s.googleId + "not existing"));
    assertEquals(
        null,
        studentsDb.getStudentForGoogleId(s.course + "not existing", s.googleId + "not existing"));

    ______TS("fail : duplicate");
    try {
      studentsDb.createEntity(s);
      Assert.fail();
    } catch (EntityAlreadyExistsException e) {
      AssertHelper.assertContains(
          String.format(StudentsDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, s.getEntityTypeAsString())
              + s.getIdentificationString(),
          e.getMessage());
    }

    ______TS("null params check");
    try {
      studentsDb.createEntity(null);
      Assert.fail();
    } catch (AssertionError a) {
      assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, a.getMessage());
    }
  }
예제 #2
0
  private StudentAttributes createNewStudent(String email) throws InvalidParametersException {
    StudentAttributes s = new StudentAttributes();
    s.name = "valid student 2";
    s.course = "valid-course";
    s.email = email;
    s.team = "valid team name";
    s.comments = "";
    s.googleId = "";
    try {
      studentsDb.createEntity(s);
    } catch (EntityAlreadyExistsException e) {
      // Okay if it's already inside
    }

    return s;
  }