Search in sources :

Example 16 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsLogicTest method testGetFeedbackSessionQuestionsForInstructor.

private void testGetFeedbackSessionQuestionsForInstructor() throws Exception {
    ______TS("standard test");
    FeedbackSessionQuestionsBundle actual = fsLogic.getFeedbackSessionQuestionsForInstructor("Instructor feedback session", "idOfTypicalCourse2", "instructor1@course2.tmt");
    // We just test this once.
    assertEquals(dataBundle.feedbackSessions.get("session2InCourse2").toString(), actual.feedbackSession.toString());
    // There should be 2 question for students to do in session 1.
    // The final question is set for SELF (creator) only.
    assertEquals(2, actual.questionResponseBundle.size());
    // Question 1
    FeedbackQuestionAttributes expectedQuestion = getQuestionFromDatastore("qn1InSession2InCourse2");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    String expectedResponsesString = getResponseFromDatastore("response1ForQ1S2C2", dataBundle).toString();
    List<String> actualResponses = new ArrayList<>();
    for (FeedbackResponseAttributes responsesForQn : actual.questionResponseBundle.get(expectedQuestion)) {
        actualResponses.add(responsesForQn.toString());
    }
    assertEquals(1, actualResponses.size());
    AssertHelper.assertContains(actualResponses, expectedResponsesString);
    // Question 2
    expectedQuestion = getQuestionFromDatastore("qn2InSession2InCourse2");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    assertTrue(actual.questionResponseBundle.get(expectedQuestion).isEmpty());
    ______TS("private test: not creator");
    actual = fsLogic.getFeedbackSessionQuestionsForInstructor("Private feedback session", "idOfTypicalCourse2", "instructor2@course2.tmt");
    assertEquals(0, actual.questionResponseBundle.size());
    ______TS("private test: is creator");
    actual = fsLogic.getFeedbackSessionQuestionsForInstructor("Private feedback session", "idOfTypicalCourse2", "instructor1@course2.tmt");
    assertEquals(1, actual.questionResponseBundle.size());
    expectedQuestion = getQuestionFromDatastore("qn1InSession1InCourse2");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    ______TS("failure: invalid session");
    try {
        fsLogic.getFeedbackSessionQuestionsForInstructor("invalid session", "idOfTypicalCourse1", "instructor1@course1.tmt");
        signalFailureToDetectException("Did not detect that session does not exist.");
    } catch (EntityDoesNotExistException e) {
        assertEquals("Trying to get a non-existent feedback session: " + "idOfTypicalCourse1" + "/" + "invalid session", e.getMessage());
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) FeedbackSessionQuestionsBundle(teammates.common.datatransfer.FeedbackSessionQuestionsBundle) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 17 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsLogicTest method testGetFeedbackSessionQuestionsForStudent.

private void testGetFeedbackSessionQuestionsForStudent() throws Exception {
    ______TS("standard test");
    FeedbackSessionQuestionsBundle actual = fsLogic.getFeedbackSessionQuestionsForStudent("First feedback session", "idOfTypicalCourse1", "student1InCourse1@gmail.tmt");
    // We just test this once.
    assertEquals(actual.feedbackSession.toString(), dataBundle.feedbackSessions.get("session1InCourse1").toString());
    // There should be 3 questions for students to do in session 1.
    // Other questions are set for instructors.
    assertEquals(3, actual.questionResponseBundle.size());
    // Question 1
    FeedbackQuestionAttributes expectedQuestion = getQuestionFromDatastore("qn1InSession1InCourse1");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    String expectedResponsesString = getResponseFromDatastore("response1ForQ1S1C1", dataBundle).toString();
    List<String> actualResponses = new ArrayList<>();
    for (FeedbackResponseAttributes responsesForQn : actual.questionResponseBundle.get(expectedQuestion)) {
        actualResponses.add(responsesForQn.toString());
    }
    assertEquals(1, actualResponses.size());
    AssertHelper.assertContains(actualResponses, expectedResponsesString);
    // Question 2
    expectedQuestion = getQuestionFromDatastore("qn2InSession1InCourse1");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    expectedResponsesString = getResponseFromDatastore("response2ForQ2S1C1", dataBundle).toString();
    actualResponses.clear();
    for (FeedbackResponseAttributes responsesForQn : actual.questionResponseBundle.get(expectedQuestion)) {
        actualResponses.add(responsesForQn.toString());
    }
    assertEquals(1, actualResponses.size());
    AssertHelper.assertContains(actualResponses, expectedResponsesString);
    // Question for students to instructors
    expectedQuestion = getQuestionFromDatastore("qn5InSession1InCourse1");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    // Check that instructors (except the one who is not displayed to student) appear as recipients
    Map<String, String> recipients = actual.recipientList.get(expectedQuestion.getId());
    assertTrue(recipients.containsKey("instructor1@course1.tmt"));
    assertTrue(recipients.containsKey("instructor2@course1.tmt"));
    assertTrue(recipients.containsKey("instructor3@course1.tmt"));
    assertTrue(recipients.containsKey("instructorNotYetJoinedCourse1@email.tmt"));
    assertFalse(recipients.containsKey("helper@course1.tmt"));
    ______TS("team feedback test");
    // Check that student3 get team member's (student4) feedback response as well (for team question).
    actual = fsLogic.getFeedbackSessionQuestionsForStudent("Second feedback session", "idOfTypicalCourse1", "student3InCourse1@gmail.tmt");
    assertEquals(2, actual.questionResponseBundle.size());
    // Question 1
    expectedQuestion = getQuestionFromDatastore("team.feedback");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    expectedResponsesString = getResponseFromDatastore("response1ForQ1S2C1", dataBundle).toString();
    actualResponses.clear();
    for (FeedbackResponseAttributes responsesForQn : actual.questionResponseBundle.get(expectedQuestion)) {
        actualResponses.add(responsesForQn.toString());
    }
    assertEquals(1, actualResponses.size());
    AssertHelper.assertContains(actualResponses, expectedResponsesString);
    // Question 2, no responses from this student yet
    expectedQuestion = getQuestionFromDatastore("team.members.feedback");
    assertTrue(actual.questionResponseBundle.containsKey(expectedQuestion));
    assertTrue(actual.questionResponseBundle.get(expectedQuestion).isEmpty());
    ______TS("failure: invalid session");
    try {
        fsLogic.getFeedbackSessionQuestionsForStudent("invalid session", "idOfTypicalCourse1", "student3InCourse1@gmail.tmt");
        signalFailureToDetectException("Did not detect that session does not exist.");
    } catch (EntityDoesNotExistException e) {
        assertEquals("Trying to get a non-existent feedback session: " + "idOfTypicalCourse1" + "/" + "invalid session", e.getMessage());
    }
    ______TS("failure: non-existent student");
    try {
        fsLogic.getFeedbackSessionQuestionsForStudent("Second feedback session", "idOfTypicalCourse1", "randomUserId");
        signalFailureToDetectException("Did not detect that student does not exist.");
    } catch (EntityDoesNotExistException edne) {
        assertEquals("Error getting feedback session(s): Student does not exist.", edne.getMessage());
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) FeedbackSessionQuestionsBundle(teammates.common.datatransfer.FeedbackSessionQuestionsBundle) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 18 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class FeedbackSessionsLogicTest method testGetFeedbackSessionResultsForUser.

private void testGetFeedbackSessionResultsForUser() throws Exception {
    // This file contains a session with a private session + a standard
    // session which needs to have enough qn/response combinations to cover as much
    // of the SUT as possible
    DataBundle responseBundle = loadDataBundle("/FeedbackSessionResultsTest.json");
    removeAndRestoreDataBundle(responseBundle);
    ______TS("standard session with varied visibilities");
    FeedbackSessionAttributes session = responseBundle.feedbackSessions.get("standard.session");
    /**
     * Test result bundle for student1 **
     */
    StudentAttributes student = responseBundle.students.get("student1InCourse1");
    FeedbackSessionResultsBundle results = fsLogic.getFeedbackSessionResultsForStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email);
    // We just check for correct session once
    assertEquals(session.toString(), results.feedbackSession.toString());
    // Student can see responses: q1r1, q2r1,3, q3r1, qr4r2-3, q5r1, q7r1-2, q8r1-2
    // We don't check the actual IDs as this is also implicitly tested
    // later when checking the visibility table.
    assertEquals(11, results.responses.size());
    assertEquals(7, results.questions.size());
    // Test the user email-name maps used for display purposes
    String mapString = results.emailNameTable.toString();
    List<String> expectedStrings = new ArrayList<>();
    String student2AnonEmail = getStudentAnonEmail(responseBundle, "student2InCourse1");
    String student2AnonName = getStudentAnonName(responseBundle, "student2InCourse1");
    String student4AnonEmail = getStudentAnonEmail(responseBundle, "student4InCourse1");
    String student4AnonName = getStudentAnonName(responseBundle, "student4InCourse1");
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "FSRTest.student4InCourse1@gmail.tmt=student4 In Course1", "Team 1.1</td></div>'\"=Team 1.1</td></div>'\"", "Team 1.2=Team 1.2", "Team 1.3=Team 1.3", "Team 1.4=Team 1.4", "FSRTest.instr1@course1.tmt=Instructor1 Course1", "FSRTest.student1InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.1", "FSRTest.student2InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.1", "FSRTest.student4InCourse1@gmail.tmt" + Const.TEAM_OF_EMAIL_OWNER + "=Team 1.2", student2AnonEmail + "=" + student2AnonName, student4AnonEmail + "=" + student4AnonName);
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student4InCourse1@gmail.tmt=Team 1.2", "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student1InCourse1@gmail.tmt's Team=", "FSRTest.student2InCourse1@gmail.tmt's Team=", "FSRTest.student4InCourse1@gmail.tmt's Team=", "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.1</td></div>'\"=", "Team 1.3=", "Team 1.2=", "Team 1.4=", "FSRTest.instr1@course1.tmt=Instructors", student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student4AnonEmail + "=" + student4AnonName + Const.TEAM_OF_EMAIL_OWNER);
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailTeamNameTable.size());
    // Test 'Append TeamName to Name' for display purposes with Typical Cases
    expectedStrings.clear();
    List<String> actualStrings = new ArrayList<>();
    for (FeedbackResponseAttributes response : results.responses) {
        String giverName = results.getNameForEmail(response.giver);
        String giverTeamName = results.getTeamNameForEmail(response.giver);
        giverName = results.appendTeamNameToName(giverName, giverTeamName);
        String recipientName = results.getNameForEmail(response.recipient);
        String recipientTeamName = results.getTeamNameForEmail(response.recipient);
        recipientName = results.appendTeamNameToName(recipientName, recipientTeamName);
        actualStrings.add(giverName);
        actualStrings.add(recipientName);
    }
    Collections.addAll(expectedStrings, getStudentAnonName(responseBundle, "student2InCourse1"), getStudentAnonName(responseBundle, "student4InCourse1"), "student1 In Course1</td></div>'\" (Team 1.1</td></div>'\")", "student2 In Course1 (Team 1.1</td></div>'\")", "student4 In Course1 (Team 1.2)", "Instructor1 Course1 (Instructors)", "Team 1.1</td></div>'\"", "Team 1.2", "Team 1.3", "Team 1.4");
    AssertHelper.assertContains(expectedStrings, actualStrings.toString());
    // Test 'Append TeamName to Name' for display purposes with Special Cases
    expectedStrings.clear();
    actualStrings.clear();
    // case: Unknown User
    String unknownUserName = Const.USER_UNKNOWN_TEXT;
    String someTeamName = "Some Team Name";
    unknownUserName = results.appendTeamNameToName(unknownUserName, someTeamName);
    actualStrings.add(unknownUserName);
    // case: Nobody
    String nobodyUserName = Const.USER_NOBODY_TEXT;
    nobodyUserName = results.appendTeamNameToName(nobodyUserName, someTeamName);
    actualStrings.add(nobodyUserName);
    // case: Anonymous User
    String anonymousUserName = Const.DISPLAYED_NAME_FOR_ANONYMOUS_PARTICIPANT + " " + System.currentTimeMillis();
    anonymousUserName = results.appendTeamNameToName(anonymousUserName, someTeamName);
    actualStrings.add(anonymousUserName);
    Collections.addAll(expectedStrings, Const.USER_UNKNOWN_TEXT, Const.USER_NOBODY_TEXT, anonymousUserName);
    assertEquals(expectedStrings.toString(), actualStrings.toString());
    // Test the generated response visibilityTable for userNames.
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("qn1.resp1", responseBundle) + "={true,true}", getResponseId("qn2.resp1", responseBundle) + "={true,true}", getResponseId("qn2.resp3", responseBundle) + "={true,true}", getResponseId("qn3.resp1", responseBundle) + "={true,true}", getResponseId("qn4.resp2", responseBundle) + "={true,true}", getResponseId("qn4.resp3", responseBundle) + "={false,true}", getResponseId("qn5.resp1", responseBundle) + "={true,false}", getResponseId("qn7.resp1", responseBundle) + "={true,true}", getResponseId("qn7.resp2", responseBundle) + "={true,true}", getResponseId("qn8.resp1", responseBundle) + "={true,true}", getResponseId("qn8.resp2", responseBundle) + "={true,true}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(11, results.visibilityTable.size());
    /**
     * Test result bundle for instructor1 within a course **
     */
    InstructorAttributes instructor = responseBundle.instructors.get("instructor1OfCourse1");
    results = fsLogic.getFeedbackSessionResultsForInstructor(session.getFeedbackSessionName(), session.getCourseId(), instructor.email);
    // Instructor can see responses: q2r1-3, q3r1-2, q4r1-3, q5r1, q6r1
    assertEquals(10, results.responses.size());
    // Instructor should still see all questions
    assertEquals(8, results.questions.size());
    // Test the user email-name maps used for display purposes
    mapString = results.emailNameTable.toString();
    expectedStrings.clear();
    String student1AnonEmail = getStudentAnonEmail(responseBundle, "student1InCourse1");
    String student1AnonName = getStudentAnonName(responseBundle, "student1InCourse1");
    String student3AnonEmail = getStudentAnonEmail(responseBundle, "student3InCourse1");
    String student3AnonName = getStudentAnonName(responseBundle, "student3InCourse1");
    String student6AnonEmail = getStudentAnonEmail(responseBundle, "student6InCourse1");
    String student6AnonName = getStudentAnonName(responseBundle, "student6InCourse1");
    String instructor1AnonEmail = FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor1OfCourse1").name);
    String instructor1AnonName = FeedbackSessionResultsBundle.getAnonName(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor1OfCourse1").name);
    String instructor2AnonEmail = FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor2OfCourse1").name);
    String instructor2AnonName = FeedbackSessionResultsBundle.getAnonName(FeedbackParticipantType.INSTRUCTORS, responseBundle.instructors.get("instructor2OfCourse1").name);
    Collections.addAll(expectedStrings, "%GENERAL%=%NOBODY%", "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1</td></div>'\"", "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "FSRTest.student3InCourse1@gmail.tmt=student3 In Course1", "FSRTest.student4InCourse1@gmail.tmt=student4 In Course1", "FSRTest.student5InCourse1@gmail.tmt=student5 In Course1", "FSRTest.student6InCourse1@gmail.tmt=student6 In Course1", "FSRTest.instr1@course1.tmt=Instructor1 Course1", "FSRTest.instr2@course1.tmt=Instructor2 Course1", student1AnonEmail + "=" + student1AnonName, student2AnonEmail + "=" + student2AnonName, student3AnonEmail + "=" + student3AnonName, student6AnonEmail + "=" + student6AnonName, instructor1AnonEmail + "=" + instructor1AnonName, instructor2AnonEmail + "=" + instructor2AnonName, "Team 1.2=Team 1.2", "Team 1.3=Team 1.3", "Team 1.4=Team 1.4");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(18, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "%GENERAL%=", "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "FSRTest.student3InCourse1@gmail.tmt=Team 1.2", "FSRTest.student4InCourse1@gmail.tmt=Team 1.2", "FSRTest.student5InCourse1@gmail.tmt=Team 1.3", "FSRTest.student6InCourse1@gmail.tmt=Team 1.4", "FSRTest.instr2@course1.tmt=Instructors", "FSRTest.instr1@course1.tmt=Instructors", student1AnonEmail + "=" + student1AnonName + Const.TEAM_OF_EMAIL_OWNER, student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student3AnonEmail + "=" + student3AnonName + Const.TEAM_OF_EMAIL_OWNER, student6AnonEmail + "=" + student6AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor1AnonEmail + "=" + instructor1AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor2AnonEmail + "=" + instructor2AnonName + Const.TEAM_OF_EMAIL_OWNER, "Team 1.3=", "Team 1.2=", "Team 1.4=");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(18, results.emailTeamNameTable.size());
    // Test the generated response visibilityTable for userNames.
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("qn2.resp1", responseBundle) + "={false,false}", getResponseId("qn2.resp2", responseBundle) + "={false,false}", getResponseId("qn2.resp3", responseBundle) + "={false,false}", getResponseId("qn3.resp1", responseBundle) + "={true,false}", getResponseId("qn3.resp2", responseBundle) + "={false,false}", getResponseId("qn4.resp1", responseBundle) + "={true,true}", getResponseId("qn4.resp2", responseBundle) + "={true,true}", getResponseId("qn4.resp3", responseBundle) + "={true,true}", getResponseId("qn5.resp1", responseBundle) + "={false,true}", getResponseId("qn6.resp1", responseBundle) + "={true,true}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(10, results.visibilityTable.size());
    /**
     * Test result bundle for instructor1 within a section **
     */
    results = fsLogic.getFeedbackSessionResultsForInstructorInSection(session.getFeedbackSessionName(), session.getCourseId(), instructor.email, "Section A");
    // Instructor can see responses: q2r1-3, q3r1-2, q4r1-3, q5r1, q6r1
    assertEquals(7, results.responses.size());
    // Instructor should still see all questions
    assertEquals(8, results.questions.size());
    // Test the user email-name maps used for display purposes
    mapString = results.emailNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", student1AnonEmail + "=" + student1AnonName, student2AnonEmail + "=" + student2AnonName, student3AnonEmail + "=" + student3AnonName, student6AnonEmail + "=" + student6AnonName, instructor1AnonEmail + "=" + instructor1AnonName, "FSRTest.student2InCourse1@gmail.tmt=student2 In Course1", "Team 1.4=Team 1.4", "FSRTest.instr1@course1.tmt=Instructor1 Course1");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", student1AnonEmail + "=" + student1AnonName + Const.TEAM_OF_EMAIL_OWNER, student2AnonEmail + "=" + student2AnonName + Const.TEAM_OF_EMAIL_OWNER, student3AnonEmail + "=" + student3AnonName + Const.TEAM_OF_EMAIL_OWNER, student6AnonEmail + "=" + student6AnonName + Const.TEAM_OF_EMAIL_OWNER, instructor1AnonEmail + "=" + instructor1AnonName + Const.TEAM_OF_EMAIL_OWNER, "FSRTest.student2InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.4=", "FSRTest.instr1@course1.tmt=Instructors");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(13, results.emailTeamNameTable.size());
    // Test the generated response visibilityTable for userNames.
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("qn3.resp1", responseBundle) + "={true,false}", getResponseId("qn4.resp3", responseBundle) + "={true,true}", getResponseId("qn2.resp3", responseBundle) + "={false,false}", getResponseId("qn2.resp1", responseBundle) + "={false,false}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(7, results.visibilityTable.size());
    // TODO: test student2 too.
    ______TS("private session");
    session = responseBundle.feedbackSessions.get("private.session");
    /**
     * Test result bundle for student1 **
     */
    student = responseBundle.students.get("student1InCourse1");
    results = fsLogic.getFeedbackSessionResultsForStudent(session.getFeedbackSessionName(), session.getCourseId(), student.email);
    assertEquals(0, results.questions.size());
    assertEquals(0, results.responses.size());
    assertEquals(0, results.emailNameTable.size());
    assertEquals(0, results.emailTeamNameTable.size());
    assertEquals(0, results.visibilityTable.size());
    /**
     * Test result bundle for instructor1 **
     */
    instructor = responseBundle.instructors.get("instructor1OfCourse1");
    results = fsLogic.getFeedbackSessionResultsForInstructor(session.getFeedbackSessionName(), session.getCourseId(), instructor.email);
    // Can see all responses regardless of visibility settings.
    assertEquals(2, results.questions.size());
    assertEquals(2, results.responses.size());
    // Test the user email-name maps used for display purposes
    mapString = results.emailNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=student1 In Course1", "Team 1.2=Team 1.2", FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.TEAMS, responseBundle.students.get("student3InCourse1").team), "FSRTest.instr1@course1.tmt=Instructor1 Course1");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(4, results.emailNameTable.size());
    // Test the user email-teamName maps used for display purposes
    mapString = results.emailTeamNameTable.toString();
    expectedStrings.clear();
    Collections.addAll(expectedStrings, "FSRTest.student1InCourse1@gmail.tmt=Team 1.1</td></div>'\"", "Team 1.2=", FeedbackSessionResultsBundle.getAnonEmail(FeedbackParticipantType.TEAMS, responseBundle.students.get("student3InCourse1").team), "FSRTest.instr1@course1.tmt=Instructors");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(4, results.emailTeamNameTable.size());
    // Test that name visibility is adhered to even when
    // it is a private session. (to protect anonymity during session type conversion)"
    mapString = tableToString(results.visibilityTable);
    expectedStrings.clear();
    Collections.addAll(expectedStrings, getResponseId("p.qn1.resp1", responseBundle) + "={true,true}", getResponseId("p.qn2.resp1", responseBundle) + "={true,false}");
    AssertHelper.assertContains(expectedStrings, mapString);
    assertEquals(2, results.visibilityTable.size());
    ______TS("failure: no session");
    try {
        fsLogic.getFeedbackSessionResultsForInstructor("invalid session", session.getCourseId(), instructor.email);
        signalFailureToDetectException("Did not detect that session does not exist.");
    } catch (EntityDoesNotExistException e) {
        assertEquals("Trying to view a non-existent feedback session: " + session.getCourseId() + "/" + "invalid session", e.getMessage());
    }
// TODO: check for cases where a person is both a student and an instructor
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) DataBundle(teammates.common.datatransfer.DataBundle) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 19 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class InstructorsLogicTest method testUpdateInstructorByGoogleId.

private void testUpdateInstructorByGoogleId() throws Exception {
    ______TS("typical case: update an instructor");
    String courseId = "idOfTypicalCourse1";
    String googleId = "idOfInstructor2OfCourse1";
    InstructorAttributes instructorToBeUpdated = instructorsLogic.getInstructorForGoogleId(courseId, googleId);
    instructorToBeUpdated.name = "New Name";
    instructorToBeUpdated.email = "new-email@course1.tmt";
    instructorsLogic.updateInstructorByGoogleId(googleId, instructorToBeUpdated);
    InstructorAttributes instructorUpdated = instructorsLogic.getInstructorForGoogleId(courseId, googleId);
    verifySameInstructor(instructorToBeUpdated, instructorUpdated);
    ______TS("failure: instructor doesn't exist");
    instructorsLogic.deleteInstructorCascade(courseId, instructorUpdated.email);
    try {
        instructorsLogic.updateInstructorByGoogleId(googleId, instructorUpdated);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals("Instructor " + googleId + " does not belong to course " + courseId, e.getMessage());
    }
    ______TS("failure: course doesn't exist");
    courseId = "random-course";
    instructorToBeUpdated.courseId = courseId;
    try {
        instructorsLogic.updateInstructorByGoogleId(googleId, instructorToBeUpdated);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals("Course does not exist: " + courseId, e.getMessage());
    }
    ______TS("failure: null parameter");
    try {
        instructorsLogic.updateInstructorByGoogleId(googleId, null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Supplied parameter was null", e.getMessage());
    }
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 20 with EntityDoesNotExistException

use of teammates.common.exception.EntityDoesNotExistException in project teammates by TEAMMATES.

the class InstructorsLogicTest method testUpdateInstructorByEmail.

private void testUpdateInstructorByEmail() throws Exception {
    ______TS("typical case: update an instructor");
    String email = "instructor1@course1.tmt";
    String courseId = "idOfTypicalCourse1";
    String newName = "New name for instructor 1";
    String newGoogleId = "newIdForInstructor1";
    InstructorAttributes instructorToBeUpdated = instructorsLogic.getInstructorForEmail(courseId, email);
    instructorToBeUpdated.googleId = newGoogleId;
    instructorToBeUpdated.name = newName;
    instructorsLogic.updateInstructorByEmail(email, instructorToBeUpdated);
    InstructorAttributes instructorUpdated = instructorsLogic.getInstructorForEmail(courseId, email);
    verifySameInstructor(instructorToBeUpdated, instructorUpdated);
    ______TS("failure: instructor doesn't belong to course");
    instructorsLogic.deleteInstructorCascade(courseId, instructorToBeUpdated.email);
    try {
        instructorsLogic.updateInstructorByEmail(email, instructorToBeUpdated);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals("Instructor " + email + " does not belong to course " + courseId, e.getMessage());
    }
    ______TS("failure: course doesn't exist");
    courseId = "random-course";
    instructorToBeUpdated.courseId = courseId;
    try {
        instructorsLogic.updateInstructorByEmail(email, instructorToBeUpdated);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        assertEquals("Course does not exist: " + courseId, e.getMessage());
    }
    ______TS("failure: null parameter");
    try {
        instructorsLogic.updateInstructorByEmail(email, null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains("Supplied parameter was null", e.getMessage());
    }
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Aggregations

EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)107 InvalidParametersException (teammates.common.exception.InvalidParametersException)35 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)29 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)26 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)24 ArrayList (java.util.ArrayList)21 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)17 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 List (java.util.List)10 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)9 FeedbackSession (teammates.storage.entity.FeedbackSession)9 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)8 StatusMessage (teammates.common.util.StatusMessage)8 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)7 Text (com.google.appengine.api.datastore.Text)6 TeamDetailsBundle (teammates.common.datatransfer.TeamDetailsBundle)6 VoidWork (com.googlecode.objectify.VoidWork)4 HashSet (java.util.HashSet)4