Search in sources :

Example 41 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsLogicTest method testGetRecipientsForQuestion.

private void testGetRecipientsForQuestion() throws Exception {
    FeedbackQuestionAttributes question;
    String email;
    Map<String, String> recipients;
    ______TS("response to students, total 5");
    question = getQuestionFromDatastore("qn2InSession1InCourse1");
    email = dataBundle.students.get("student1InCourse1").email;
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    // 5 students minus giver himself
    assertEquals(recipients.size(), 4);
    email = dataBundle.instructors.get("instructor1OfCourse1").email;
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    // instructor is not student so he can respond to all 5.
    assertEquals(recipients.size(), 5);
    ______TS("response to instructors, total 3");
    question = getQuestionFromDatastore("qn2InSession2InCourse2");
    email = dataBundle.instructors.get("instructor1OfCourse2").email;
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    // 3 - giver = 2
    assertEquals(recipients.size(), 2);
    ______TS("empty case: response to team members, but alone");
    question = getQuestionFromDatastore("team.members.feedback");
    email = dataBundle.students.get("student5InCourse1").email;
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    assertEquals(recipients.size(), 0);
    ______TS("response from team to itself");
    question = getQuestionFromDatastore("graceperiod.session.feedbackFromTeamToSelf");
    email = dataBundle.students.get("student1InCourse1").email;
    String teamName = dataBundle.students.get("student1InCourse1").team;
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    assertEquals(recipients.size(), 1);
    assertTrue(recipients.containsKey(teamName));
    assertEquals(recipients.get(teamName), teamName);
    ______TS("special case: response to other team, instructor is also student");
    question = getQuestionFromDatastore("team.feedback");
    email = dataBundle.students.get("student1InCourse1").email;
    AccountsLogic.inst().makeAccountInstructor(dataBundle.students.get("student1InCourse1").googleId);
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    assertEquals(recipients.size(), 1);
    ______TS("to nobody (general feedback)");
    question = getQuestionFromDatastore("qn3InSession1InCourse1");
    email = dataBundle.students.get("student1InCourse1").email;
    AccountsLogic.inst().makeAccountInstructor(dataBundle.students.get("student1InCourse1").googleId);
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    assertEquals(recipients.get(Const.GENERAL_QUESTION), Const.GENERAL_QUESTION);
    assertEquals(recipients.size(), 1);
    ______TS("to self");
    question = getQuestionFromDatastore("qn1InSession1InCourse1");
    email = dataBundle.students.get("student1InCourse1").email;
    AccountsLogic.inst().makeAccountInstructor(dataBundle.students.get("student1InCourse1").googleId);
    recipients = fqLogic.getRecipientsForQuestion(question, email);
    assertEquals(recipients.get(email), Const.USER_NAME_FOR_SELF);
    assertEquals(recipients.size(), 1);
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 42 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsLogicTest method getQuestionFromDatastore.

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

Example 43 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsLogicTest method testAddQuestion.

private void testAddQuestion() throws Exception {
    ______TS("Add question for feedback session that does not exist");
    FeedbackQuestionAttributes question = getQuestionFromDatastore("qn1InSession1InCourse1");
    question.feedbackSessionName = "non-existent Feedback Session";
    question.setId(null);
    try {
        fqLogic.createFeedbackQuestion(question);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(e.getMessage(), "Session disappeared.");
    }
    ______TS("Add question for course that does not exist");
    question = getQuestionFromDatastore("qn1InSession1InCourse1");
    question.courseId = "non-existent course id";
    question.setId(null);
    try {
        fqLogic.createFeedbackQuestion(question);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(e.getMessage(), "Session disappeared.");
    }
    ______TS("Add questions sequentially");
    List<FeedbackQuestionAttributes> expectedList = new ArrayList<>();
    FeedbackQuestionAttributes q1 = getQuestionFromDatastore("qn1InSession1InCourse1");
    q1.questionNumber = 1;
    FeedbackQuestionAttributes q2 = getQuestionFromDatastore("qn2InSession1InCourse1");
    q2.questionNumber = 2;
    FeedbackQuestionAttributes q3 = getQuestionFromDatastore("qn3InSession1InCourse1");
    q3.questionNumber = 3;
    FeedbackQuestionAttributes q4 = getQuestionFromDatastore("qn4InSession1InCourse1");
    q4.questionNumber = 4;
    FeedbackQuestionAttributes q5 = getQuestionFromDatastore("qn5InSession1InCourse1");
    q5.questionNumber = 5;
    FeedbackQuestionAttributes q6 = getQuestionFromDatastore("qn1InSession1InCourse1");
    q6.questionNumber = 6;
    expectedList.add(q1);
    expectedList.add(q2);
    expectedList.add(q3);
    expectedList.add(q4);
    expectedList.add(q5);
    expectedList.add(q6);
    // Appends a question to the back of the current question list
    FeedbackQuestionAttributes newQuestion = getQuestionFromDatastore("qn1InSession1InCourse1");
    newQuestion.questionNumber = 6;
    // new question should not have an ID.
    newQuestion.setId(null);
    fqLogic.createFeedbackQuestion(newQuestion);
    List<FeedbackQuestionAttributes> actualList = fqLogic.getFeedbackQuestionsForSession(q1.feedbackSessionName, q1.courseId);
    assertEquals(actualList.size(), expectedList.size());
    for (int i = 0; i < actualList.size(); i++) {
        assertEquals(actualList.get(i), expectedList.get(i));
    }
    ______TS("add new question to the front of the list");
    FeedbackQuestionAttributes q7 = getQuestionFromDatastore("qn4InSession1InCourse1");
    q7.questionNumber = 1;
    q1.questionNumber = 2;
    q2.questionNumber = 3;
    q3.questionNumber = 4;
    q4.questionNumber = 5;
    q5.questionNumber = 6;
    q6.questionNumber = 7;
    expectedList.add(0, q7);
    // Add a question to session1course1 and sets its number to 1
    newQuestion = getQuestionFromDatastore("qn4InSession1InCourse1");
    newQuestion.questionNumber = 1;
    // new question should not have an ID.
    newQuestion.setId(null);
    fqLogic.createFeedbackQuestion(newQuestion);
    actualList = fqLogic.getFeedbackQuestionsForSession(q1.feedbackSessionName, q1.courseId);
    assertEquals(actualList.size(), expectedList.size());
    for (int i = 0; i < actualList.size(); i++) {
        assertEquals(actualList.get(i), expectedList.get(i));
    }
    ______TS("add new question inbetween 2 existing questions");
    FeedbackQuestionAttributes q8 = getQuestionFromDatastore("qn4InSession1InCourse1");
    q8.questionNumber = 3;
    q2.questionNumber = 4;
    q3.questionNumber = 5;
    q4.questionNumber = 6;
    q5.questionNumber = 7;
    q6.questionNumber = 8;
    expectedList.add(2, q8);
    // Add a question to session1course1 and place it between existing question 2 and 3
    newQuestion = getQuestionFromDatastore("qn4InSession1InCourse1");
    newQuestion.questionNumber = 3;
    // new question should not have an ID.
    newQuestion.setId(null);
    fqLogic.createFeedbackQuestion(newQuestion);
    actualList = fqLogic.getFeedbackQuestionsForSession(q1.feedbackSessionName, q1.courseId);
    assertEquals(actualList.size(), expectedList.size());
    for (int i = 0; i < actualList.size(); i++) {
        assertEquals(actualList.get(i), expectedList.get(i));
    }
}
Also used : ArrayList(java.util.ArrayList) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Example 44 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsLogicTest method testUpdateQuestion.

private void testUpdateQuestion() throws Exception {
    ______TS("standard update, no existing responses, with 'keep existing' policy");
    FeedbackQuestionAttributes questionToUpdate = getQuestionFromDatastore("qn2InSession2InCourse2");
    questionToUpdate.questionMetaData = new Text("new question text");
    questionToUpdate.questionNumber = 3;
    List<FeedbackParticipantType> newVisibility = new LinkedList<>();
    newVisibility.add(FeedbackParticipantType.INSTRUCTORS);
    questionToUpdate.showResponsesTo = newVisibility;
    // Check keep existing policy.
    String originalCourseId = questionToUpdate.courseId;
    questionToUpdate.courseId = null;
    fqLogic.updateFeedbackQuestion(questionToUpdate);
    questionToUpdate.courseId = originalCourseId;
    FeedbackQuestionAttributes updatedQuestion = fqLogic.getFeedbackQuestion(questionToUpdate.getId());
    assertEquals(updatedQuestion.toString(), questionToUpdate.toString());
    ______TS("cascading update, non-destructive changes, existing responses are preserved");
    questionToUpdate = getQuestionFromDatastore("qn2InSession1InCourse1");
    questionToUpdate.questionMetaData = new Text("new question text 2");
    questionToUpdate.numberOfEntitiesToGiveFeedbackTo = 2;
    int numberOfResponses = frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).size();
    fqLogic.updateFeedbackQuestion(questionToUpdate);
    updatedQuestion = fqLogic.getFeedbackQuestion(questionToUpdate.getId());
    assertEquals(updatedQuestion.toString(), questionToUpdate.toString());
    assertEquals(frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).size(), numberOfResponses);
    ______TS("cascading update, destructive changes, delete all existing responses");
    questionToUpdate = getQuestionFromDatastore("qn2InSession1InCourse1");
    questionToUpdate.questionMetaData = new Text("new question text 3");
    questionToUpdate.recipientType = FeedbackParticipantType.INSTRUCTORS;
    assertFalse(frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).isEmpty());
    fqLogic.updateFeedbackQuestion(questionToUpdate);
    updatedQuestion = fqLogic.getFeedbackQuestion(questionToUpdate.getId());
    assertEquals(updatedQuestion.toString(), questionToUpdate.toString());
    assertEquals(frLogic.getFeedbackResponsesForQuestion(questionToUpdate.getId()).size(), 0);
    ______TS("failure: question does not exist");
    questionToUpdate = getQuestionFromDatastore("qn3InSession1InCourse1");
    fqLogic.deleteFeedbackQuestionCascade(questionToUpdate.getId());
    try {
        fqLogic.updateFeedbackQuestion(questionToUpdate);
        signalFailureToDetectException("Expected EntityDoesNotExistException not caught.");
    } catch (EntityDoesNotExistException e) {
        assertEquals(e.getMessage(), "Trying to update a feedback question that does not exist.");
    }
    ______TS("failure: invalid parameters");
    questionToUpdate = getQuestionFromDatastore("qn3InSession1InCourse1");
    questionToUpdate.giverType = FeedbackParticipantType.TEAMS;
    questionToUpdate.recipientType = FeedbackParticipantType.OWN_TEAM_MEMBERS;
    try {
        fqLogic.updateFeedbackQuestion(questionToUpdate);
        signalFailureToDetectException("Expected InvalidParametersException not caught.");
    } catch (InvalidParametersException e) {
        assertEquals(e.getMessage(), String.format(FieldValidator.PARTICIPANT_TYPE_TEAM_ERROR_MESSAGE, questionToUpdate.recipientType.toDisplayRecipientName(), questionToUpdate.giverType.toDisplayGiverName()));
    }
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) FeedbackParticipantType(teammates.common.datatransfer.FeedbackParticipantType) LinkedList(java.util.LinkedList) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 45 with FeedbackQuestionAttributes

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

the class FeedbackQuestionsLogicTest method testAddQuestionNoIntegrityCheck.

private void testAddQuestionNoIntegrityCheck() throws InvalidParametersException, EntityDoesNotExistException {
    ______TS("Add questions sequentially - test for initial template question");
    FeedbackQuestionAttributes q1 = getQuestionFromDatastore("qn1InSession1InCourse1");
    q1.questionNumber = 1;
    int initialNumQuestions = fqLogic.getFeedbackQuestionsForSession(q1.feedbackSessionName, q1.courseId).size();
    // Appends a question to the back of the current question list
    FeedbackQuestionAttributes newQuestion = getQuestionFromDatastore("qn1InSession1InCourse1");
    newQuestion.questionNumber = initialNumQuestions + 1;
    // new question should not have an ID.
    newQuestion.setId(null);
    fqLogic.createFeedbackQuestionNoIntegrityCheck(newQuestion, newQuestion.questionNumber);
    List<FeedbackQuestionAttributes> actualList = fqLogic.getFeedbackQuestionsForSession(q1.feedbackSessionName, q1.courseId);
    assertEquals(actualList.size(), initialNumQuestions + 1);
    // The list starts from 0, so no need to + 1 here.
    assertEquals(actualList.get(initialNumQuestions), newQuestion);
}
Also used : FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

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