Exemplo n.º 1
0
 protected static void removeAndRestoreDatastoreFromJson(String pathToJsonFile) throws Exception {
   BackDoorLogic backDoorLogic = new BackDoorLogic();
   DataBundle dataBundle = loadDataBundle(pathToJsonFile);
   backDoorLogic.deleteExistingData(dataBundle);
   backDoorLogic.persistDataBundle(dataBundle);
 }
Exemplo n.º 2
0
 /** Creates in the datastore a fresh copy of data in typicalDataBundle.json */
 protected static void restoreTypicalDataInDatastore() throws Exception {
   BackDoorLogic backDoorLogic = new BackDoorLogic();
   DataBundle dataBundle = getTypicalDataBundle();
   backDoorLogic.persistDataBundle(dataBundle);
 }
Exemplo n.º 3
0
 protected static void removeTypicalDataInDatastore() throws Exception {
   BackDoorLogic backDoorLogic = new BackDoorLogic();
   DataBundle dataBundle = getTypicalDataBundle();
   backDoorLogic.deleteExistingData(dataBundle);
 }
Exemplo n.º 4
0
  public void testGetCourseDetailsListForStudent() throws Exception {

    ______TS("student having multiple evaluations in multiple courses");

    CourseAttributes expectedCourse1 = dataBundle.courses.get("typicalCourse1");
    CourseAttributes expectedCourse2 = dataBundle.courses.get("typicalCourse2");

    EvaluationAttributes expectedEval1InCourse1 =
        dataBundle.evaluations.get("evaluation1InCourse1");
    EvaluationAttributes expectedEval2InCourse1 =
        dataBundle.evaluations.get("evaluation2InCourse1");

    EvaluationAttributes expectedEval1InCourse2 =
        dataBundle.evaluations.get("evaluation1InCourse2");

    // This student is in both course 1 and 2
    StudentAttributes studentInBothCourses = dataBundle.students.get("student2InCourse1");

    // Make sure all evaluations in course1 are visible (i.e., not AWAITING)
    expectedEval1InCourse1.startTime = TimeHelper.getDateOffsetToCurrentTime(-2);
    expectedEval1InCourse1.endTime = TimeHelper.getDateOffsetToCurrentTime(-1);
    expectedEval1InCourse1.published = false;
    assertEquals(EvalStatus.CLOSED, expectedEval1InCourse1.getStatus());
    BackDoorLogic backDoorLogic = new BackDoorLogic();
    backDoorLogic.updateEvaluation(expectedEval1InCourse1);

    expectedEval2InCourse1.startTime = TimeHelper.getDateOffsetToCurrentTime(-1);
    expectedEval2InCourse1.endTime = TimeHelper.getDateOffsetToCurrentTime(1);
    assertEquals(EvalStatus.OPEN, expectedEval2InCourse1.getStatus());
    backDoorLogic.updateEvaluation(expectedEval2InCourse1);

    // Make sure all evaluations in course2 are still AWAITING
    expectedEval1InCourse2.startTime = TimeHelper.getDateOffsetToCurrentTime(1);
    expectedEval1InCourse2.endTime = TimeHelper.getDateOffsetToCurrentTime(2);
    expectedEval1InCourse2.activated = false;
    assertEquals(EvalStatus.AWAITING, expectedEval1InCourse2.getStatus());
    backDoorLogic.updateEvaluation(expectedEval1InCourse2);

    // Get course details for student
    List<CourseDetailsBundle> courseList =
        coursesLogic.getCourseDetailsListForStudent(studentInBothCourses.googleId);

    // Verify number of courses received
    assertEquals(2, courseList.size());

    // Verify details of course 1 (note: index of course 1 is not 0)
    CourseDetailsBundle actualCourse1 = courseList.get(1);
    assertEquals(expectedCourse1.id, actualCourse1.course.id);
    assertEquals(expectedCourse1.name, actualCourse1.course.name);
    assertEquals(2, actualCourse1.evaluations.size());

    // Verify details of evaluation 1 in course 1
    EvaluationAttributes actualEval1InCourse1 = actualCourse1.evaluations.get(1).evaluation;
    TestHelper.verifySameEvaluationData(expectedEval1InCourse1, actualEval1InCourse1);

    // Verify some details of evaluation 2 in course 1
    EvaluationAttributes actualEval2InCourse1 = actualCourse1.evaluations.get(0).evaluation;
    TestHelper.verifySameEvaluationData(expectedEval2InCourse1, actualEval2InCourse1);

    // For course 2, verify no evaluations returned (because the evaluation
    // in this course is still AWAITING.
    CourseDetailsBundle actualCourse2 = courseList.get(0);
    assertEquals(expectedCourse2.id, actualCourse2.course.id);
    assertEquals(expectedCourse2.name, actualCourse2.course.name);
    assertEquals(0, actualCourse2.evaluations.size());

    ______TS("student in a course with no evaluations");

    StudentAttributes studentWithNoEvaluations = dataBundle.students.get("student1InCourse2");
    courseList = coursesLogic.getCourseDetailsListForStudent(studentWithNoEvaluations.googleId);
    assertEquals(1, courseList.size());
    assertEquals(0, courseList.get(0).evaluations.size());

    // student with no courses is not applicable

    ______TS("non-existent student");

    try {
      coursesLogic.getCourseDetailsListForStudent("non-existent-student");
      signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
      AssertHelper.assertContains("does not exist", e.getMessage());
    }

    ______TS("null parameter");

    try {
      coursesLogic.getCourseDetailsListForStudent(null);
      signalFailureToDetectException();
    } catch (AssertionError e) {
      assertEquals("Supplied parameter was null\n", e.getMessage());
    }
  }