Search in sources :

Example 41 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackResponsesLogicTest method testIsNameVisibleTo.

private void testIsNameVisibleTo() {
    ______TS("testIsNameVisibleTo");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    StudentAttributes student2 = dataBundle.students.get("student2InCourse1");
    StudentAttributes student3 = dataBundle.students.get("student3InCourse1");
    StudentAttributes student5 = dataBundle.students.get("student5InCourse1");
    FeedbackQuestionAttributes fq = getQuestionFromDatastore("qn3InSession1InCourse1");
    FeedbackResponseAttributes fr = getResponseFromDatastore("response1ForQ3S1C1");
    CourseRoster roster = new CourseRoster(new StudentsDb().getStudentsForCourse(fq.courseId), new InstructorsDb().getInstructorsForCourse(fq.courseId));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, instructor.email, UserRole.INSTRUCTOR, true, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, instructor.email, UserRole.INSTRUCTOR, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    ______TS("test if visible to own team members");
    fr.giver = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    ______TS("test if visible to receiver/reciever team members");
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER);
    fr.recipient = student.team;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.STUDENTS;
    fr.recipient = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student2.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER_TEAM_MEMBERS);
    fr.recipient = student.team;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.STUDENTS;
    fr.recipient = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student2.email, UserRole.STUDENT, false, roster));
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.email, UserRole.STUDENT, false, roster));
    ______TS("test anonymous team recipients");
    // Only members of the recipient team should be able to see the recipient name
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER);
    fq.showResponsesTo.add(FeedbackParticipantType.STUDENTS);
    fr.recipient = "Team 1.1";
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.email, UserRole.STUDENT, false, roster));
    ______TS("null question");
    assertFalse(frLogic.isNameVisibleToUser(null, fr, student.email, UserRole.STUDENT, false, roster));
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) CourseRoster(teammates.common.datatransfer.CourseRoster) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentsDb(teammates.storage.api.StudentsDb) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 42 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes 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 43 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes 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 44 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes 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 45 with FeedbackResponseAttributes

use of teammates.common.datatransfer.attributes.FeedbackResponseAttributes in project teammates by TEAMMATES.

the class FeedbackSessionsLogicTest method getResponseFromDatastore.

private FeedbackResponseAttributes getResponseFromDatastore(String jsonId, DataBundle bundle) {
    FeedbackResponseAttributes response = bundle.feedbackResponses.get(jsonId);
    String questionId = null;
    try {
        int qnNumber = Integer.parseInt(response.feedbackQuestionId);
        questionId = fqLogic.getFeedbackQuestion(response.feedbackSessionName, response.courseId, qnNumber).getId();
    } catch (NumberFormatException e) {
        questionId = response.feedbackQuestionId;
    }
    return frLogic.getFeedbackResponse(questionId, response.giver, response.recipient);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes)

Aggregations

FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)143 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)70 ArrayList (java.util.ArrayList)63 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)36 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)35 List (java.util.List)29 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)28 HashMap (java.util.HashMap)27 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)22 HashSet (java.util.HashSet)20 LinkedHashMap (java.util.LinkedHashMap)20 Map (java.util.Map)18 Test (org.testng.annotations.Test)18 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)18 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)18 Text (com.google.appengine.api.datastore.Text)15 Set (java.util.Set)11 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)10 Comparator (java.util.Comparator)9 FeedbackParticipantType (teammates.common.datatransfer.FeedbackParticipantType)9