public void testModifyExternalGradeRecords() throws Exception {
    // Add an external assessment
    gradebookExternalAssessmentService.addExternalAssessment(
        GRADEBOOK_UID,
        EXT_ID_1,
        null,
        EXT_TITLE_1,
        new Double(10),
        new Date(),
        "Samigo",
        new Boolean(false));

    // Add the external assessment score
    Gradebook gb = gradebookManager.getGradebook(GRADEBOOK_UID);
    gradebookExternalAssessmentService.updateExternalAssessmentScore(
        gb.getUid(), EXT_ID_1, "student1", new String("2"));

    // Ensure that the course grade record for student1 has been updated
    CourseGradeRecord cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student1");
    Assert.assertTrue(
        cgr.getPointsEarned()
            .equals(new Double(12))); // 10 points on internal, 2 points on external

    // Update the score with null points
    gradebookExternalAssessmentService.updateExternalAssessmentScore(
        gb.getUid(), EXT_ID_1, "student1", null);

    // Ensure that the course grade record for student1 has been updated
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student1");
    Assert.assertEquals(
        new Double(10), cgr.getPointsEarned()); // 10 points on internal, 0 points on external
  }
  public void testUpdateMultipleScores() throws Exception {
    // Add an external assessment
    gradebookExternalAssessmentService.addExternalAssessment(
        GRADEBOOK_UID,
        EXT_ID_1,
        null,
        EXT_TITLE_1,
        new Double(10),
        new Date(),
        "Samigo",
        new Boolean(false));

    // Add the external assessment score
    Gradebook gb = gradebookManager.getGradebook(GRADEBOOK_UID);
    gradebookExternalAssessmentService.updateExternalAssessmentScore(
        gb.getUid(), EXT_ID_1, "student1", new String("2"));

    // Ensure that the course grade record for student1 has been updated
    CourseGradeRecord cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student1");
    Assert.assertTrue(
        cgr.getPointsEarned()
            .equals(new Double(12))); // 10 points on internal, 2 points on external

    // Update multiple scores at once.
    Map studentUidsToScores = new HashMap();
    studentUidsToScores.put("student1", null);
    studentUidsToScores.put("student2", new Double(4).toString());
    studentUidsToScores.put("student3", new Double(5).toString());
    gradebookExternalAssessmentService.updateExternalAssessmentScoresString(
        gb.getUid(), EXT_ID_1, studentUidsToScores);
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student1");
    Assert.assertTrue(cgr.getPointsEarned().equals(new Double(10)));
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student2");
    Assert.assertTrue(cgr.getPointsEarned().equals(new Double(4)));

    // Do a bogus update of a null collection of scores, a la Assignments.
    gradebookExternalAssessmentService.updateExternalAssessmentScoresString(
        gb.getUid(), EXT_ID_1, new HashMap());
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student2");
    Assert.assertTrue(cgr.getPointsEarned().equals(new Double(4)));
  }
  public void testRemoveExternalAssignment() throws Exception {
    Gradebook gb = gradebookManager.getGradebook(GRADEBOOK_UID);

    // Grade a second student on the internal assignment to test
    // course grade calculations later.
    Assignment asn = gradebookManager.getAssignmentWithStats(asn_1Id);
    List gradeRecords = new ArrayList();
    gradeRecords.add(new AssignmentGradeRecord(asn, "student2", new Double(10)));
    gradebookManager.updateAssignmentGradeRecords(asn, gradeRecords);

    // Add an external assessment
    gradebookExternalAssessmentService.addExternalAssessment(
        GRADEBOOK_UID,
        EXT_ID_1,
        null,
        EXT_TITLE_1,
        new Double(10),
        new Date(),
        "Samigo",
        new Boolean(false));

    // Add the external assessment score
    gradebookExternalAssessmentService.updateExternalAssessmentScore(
        GRADEBOOK_UID, EXT_ID_1, "student1", new String("5"));
    CourseGradeRecord cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student1");
    Assert.assertTrue(
        cgr.getPointsEarned()
            .equals(new Double(15))); // 10 points on internal, 10 points on external

    // Check the display grade (which is what the students would see).
    if (log.isDebugEnabled()) log.debug("student1 cgr displayGrade=" + cgr.getDisplayGrade());
    Assert.assertTrue(cgr.getDisplayGrade().equals("C"));
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student2");
    if (log.isDebugEnabled()) log.debug("student2 cgr displayGrade=" + cgr.getDisplayGrade());
    // comment it out because of new calculation method
    //        Assert.assertTrue(cgr.getDisplayGrade().equals("F"));

    // Remove the external assessment
    gradebookExternalAssessmentService.removeExternalAssessment(GRADEBOOK_UID, EXT_ID_1);

    // Ensure that the course grade record for student1 has been updated
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student1");
    Assert.assertTrue(
        cgr.getPointsEarned()
            .equals(new Double(10))); // 10 points on internal, 0 points on external

    // Check the display grade (which is what the students would see).
    if (log.isDebugEnabled()) log.debug("student1 cgr displayGrade=" + cgr.getDisplayGrade());
    Assert.assertTrue(cgr.getDisplayGrade().equals("A+"));
    cgr = gradebookManager.getStudentCourseGradeRecord(gb, "student2");
    if (log.isDebugEnabled()) log.debug("student2 cgr displayGrade=" + cgr.getDisplayGrade());
    Assert.assertTrue(cgr.getDisplayGrade().equals("A+"));

    // Try to add another external assessment with the same external ID as the recently deleted
    // external assessment
    gradebookExternalAssessmentService.addExternalAssessment(
        GRADEBOOK_UID,
        EXT_ID_1,
        null,
        "some other unique title",
        new Double(10),
        new Date(),
        "Samigo",
        new Boolean(false));
  }