Search in sources :

Example 46 with FeedbackQuestionAttributes

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

the class FeedbackResponseCommentsLogicTest method getQuestionIdInDataBundle.

private String getQuestionIdInDataBundle(String questionInDataBundle) {
    FeedbackQuestionAttributes question = dataBundle.feedbackQuestions.get(questionInDataBundle);
    question = fqLogic.getFeedbackQuestion(question.feedbackSessionName, question.courseId, question.questionNumber);
    return question.getId();
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 47 with FeedbackQuestionAttributes

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

the class FeedbackResponsesLogicTest method getQuestionFromDatastore.

private FeedbackQuestionAttributes getQuestionFromDatastore(DataBundle dataBundle, String jsonId) {
    FeedbackQuestionAttributes questionToGet = dataBundle.feedbackQuestions.get(jsonId);
    questionToGet = fqLogic.getFeedbackQuestion(questionToGet.feedbackSessionName, questionToGet.courseId, questionToGet.questionNumber);
    return questionToGet;
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 48 with FeedbackQuestionAttributes

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

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

use of teammates.common.datatransfer.attributes.FeedbackQuestionAttributes 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)

Aggregations

FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)154 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)64 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)48 ArrayList (java.util.ArrayList)47 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)38 Test (org.testng.annotations.Test)35 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)25 List (java.util.List)23 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)23 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)19 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)18 HashMap (java.util.HashMap)17 RedirectResult (teammates.ui.controller.RedirectResult)17 HashSet (java.util.HashSet)12 FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)12 Text (com.google.appengine.api.datastore.Text)11 Map (java.util.Map)10 FeedbackQuestionDetails (teammates.common.datatransfer.questions.FeedbackQuestionDetails)10 LinkedHashMap (java.util.LinkedHashMap)9 DataBundle (teammates.common.datatransfer.DataBundle)9