Search in sources :

Example 66 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method testGetViewableResponsesForQuestionInSection.

private void testGetViewableResponsesForQuestionInSection() throws Exception {
    ______TS("success: GetViewableResponsesForQuestion - instructor");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    FeedbackQuestionAttributes fq = getQuestionFromDatastore("qn3InSession1InCourse1");
    List<FeedbackResponseAttributes> responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, instructor.email, UserRole.INSTRUCTOR, null);
    assertEquals(responses.size(), 1);
    ______TS("success: GetViewableResponsesForQuestionInSection - instructor");
    fq = getQuestionFromDatastore("qn2InSession1InCourse1");
    responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, instructor.email, UserRole.INSTRUCTOR, "Section 1");
    assertEquals(responses.size(), 3);
    responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, instructor.email, UserRole.INSTRUCTOR, "Section 2");
    assertEquals(responses.size(), 0);
    ______TS("success: GetViewableResponsesForQuestion - student");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    fq = getQuestionFromDatastore("qn2InSession1InCourse1");
    responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, student.email, UserRole.STUDENT, null);
    assertEquals(responses.size(), 2);
    fq = getQuestionFromDatastore("qn3InSession1InCourse1");
    responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, student.email, UserRole.STUDENT, null);
    assertEquals(responses.size(), 1);
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showResponsesTo.add(FeedbackParticipantType.RECEIVER);
    fq.showResponsesTo.add(FeedbackParticipantType.RECEIVER_TEAM_MEMBERS);
    fq.showResponsesTo.remove(FeedbackParticipantType.STUDENTS);
    FeedbackResponseAttributes fr = getResponseFromDatastore("response1ForQ3S1C1");
    fr.recipient = student.email;
    frLogic.updateFeedbackResponse(fr);
    responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, student.email, UserRole.STUDENT, null);
    assertEquals(responses.size(), 1);
    ______TS("success: Null student in response, should skip over null student");
    fq = getQuestionFromDatastore("qn2InSession1InCourse1");
    fq.showResponsesTo.add(FeedbackParticipantType.RECEIVER_TEAM_MEMBERS);
    FeedbackResponseAttributes existingResponse = getResponseFromDatastore("response1ForQ2S1C1");
    // Create a "null" response to simulate trying to get a null student's response
    FeedbackResponseAttributes newResponse = new FeedbackResponseAttributes(existingResponse.feedbackSessionName, "nullCourse", existingResponse.feedbackQuestionId, existingResponse.feedbackQuestionType, existingResponse.giver, "Section 1", "nullRecipient@gmail.tmt", "Section 1", existingResponse.responseMetaData);
    frLogic.createFeedbackResponse(newResponse);
    student = dataBundle.students.get("student2InCourse1");
    responses = frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, student.email, UserRole.STUDENT, null);
    assertEquals(responses.size(), 4);
    ______TS("failure: GetViewableResponsesForQuestion invalid role");
    try {
        frLogic.getViewableFeedbackResponsesForQuestionInSection(fq, instructor.email, UserRole.ADMIN, null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(e.getMessage(), "The role of the requesting use has to be Student or Instructor");
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 67 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method getFeedbackResponseCommentsForResponsesFromDatastore.

private List<FeedbackResponseCommentAttributes> getFeedbackResponseCommentsForResponsesFromDatastore(List<FeedbackResponseAttributes> responses) {
    List<FeedbackResponseCommentAttributes> responseComments = new ArrayList<>();
    for (FeedbackResponseAttributes response : responses) {
        List<FeedbackResponseCommentAttributes> responseCommentsForResponse = frcLogic.getFeedbackResponseCommentForResponse(response.getId());
        responseComments.addAll(responseCommentsForResponse);
    }
    return responseComments;
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) ArrayList(java.util.ArrayList)

Example 68 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method testUpdateFeedbackResponsesForChangingTeam.

private void testUpdateFeedbackResponsesForChangingTeam() throws Exception {
    ______TS("standard update team case");
    StudentAttributes studentToUpdate = dataBundle.students.get("student4InCourse1");
    // Student 4 has 1 responses to him from team members,
    // 1 response from him a team member, and
    // 1 team response from him to another team.
    FeedbackQuestionAttributes teamQuestion = getQuestionFromDatastore("team.members.feedback");
    assertEquals(frLogic.getFeedbackResponsesForReceiverForQuestion(teamQuestion.getId(), studentToUpdate.email).size(), 1);
    assertEquals(frLogic.getFeedbackResponsesFromGiverForQuestion(teamQuestion.getId(), studentToUpdate.email).size(), 1);
    teamQuestion = getQuestionFromDatastore("team.feedback");
    assertEquals(frLogic.getFeedbackResponsesFromGiverForQuestion(teamQuestion.getId(), studentToUpdate.email).size(), 1);
    // Add one more non-team response
    FeedbackResponseAttributes responseToAdd = new FeedbackResponseAttributes("First feedback session", "idOfTypicalCourse1", getQuestionFromDatastore("qn1InSession1InCourse1").getId(), FeedbackQuestionType.TEXT, studentToUpdate.email, "Section 1", studentToUpdate.email, "Section 1", new Text("New Response to self"));
    frLogic.createFeedbackResponse(responseToAdd);
    // All these responses should be gone after he changes teams
    frLogic.updateFeedbackResponsesForChangingTeam(studentToUpdate.course, studentToUpdate.email, studentToUpdate.team, "Team 1.2");
    teamQuestion = getQuestionFromDatastore("team.members.feedback");
    assertEquals(frLogic.getFeedbackResponsesForReceiverForQuestion(teamQuestion.getId(), studentToUpdate.email).size(), 0);
    assertEquals(frLogic.getFeedbackResponsesFromGiverForQuestion(teamQuestion.getId(), studentToUpdate.email).size(), 0);
    teamQuestion = getQuestionFromDatastore("team.feedback");
    assertEquals(frLogic.getFeedbackResponsesForReceiverForQuestion(teamQuestion.getId(), studentToUpdate.email).size(), 0);
    // Non-team response should remain
    assertEquals(frLogic.getFeedbackResponsesFromGiverForQuestion(getQuestionFromDatastore("qn1InSession1InCourse1").getId(), studentToUpdate.email).size(), 1);
    ______TS("test updateFeedbackResponseForChangingTeam for recipient type = giver's team members including giver");
    FeedbackQuestionAttributes questionToTeamMembersAndSelf = getQuestionFromDatastore(questionTypeBundle, "qn1InContribSession2InCourse2");
    studentToUpdate = questionTypeBundle.students.get("student2InCourse2");
    FeedbackResponseAttributes responseToBeDeleted = getResponseFromDatastore(questionTypeBundle, "response1ForQ1ContribSession2Course2");
    StudentEnrollDetails studentDetails1 = new StudentEnrollDetails(StudentUpdateStatus.MODIFIED, studentToUpdate.course, studentToUpdate.email, studentToUpdate.team, studentToUpdate.team + "tmp", studentToUpdate.section, studentToUpdate.section + "tmp");
    assertNotNull(frLogic.getFeedbackResponse(questionToTeamMembersAndSelf.getId(), responseToBeDeleted.giver, responseToBeDeleted.recipient));
    assertTrue(frLogic.updateFeedbackResponseForChangingTeam(studentDetails1, responseToBeDeleted));
    assertNull(frLogic.getFeedbackResponse(questionToTeamMembersAndSelf.getId(), responseToBeDeleted.giver, responseToBeDeleted.recipient));
    // restore DataStore so other tests are unaffected
    restoreStudentFeedbackResponseToDatastore(responseToBeDeleted);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) Text(com.google.appengine.api.datastore.Text) StudentEnrollDetails(teammates.common.datatransfer.StudentEnrollDetails) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 69 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method testUpdateFeedbackResponsesForChangingEmail.

private void testUpdateFeedbackResponsesForChangingEmail() throws Exception {
    ______TS("standard update email case");
    // Student 1 currently has 2 responses to him and 2 from himself.
    // Student 1 currently has 1 response comment for responses to him
    // and 1 response comment from responses from himself.
    StudentAttributes studentToUpdate = dataBundle.students.get("student1InCourse1");
    List<FeedbackResponseAttributes> responsesForReceiver = frLogic.getFeedbackResponsesForReceiverForCourse(studentToUpdate.course, studentToUpdate.email);
    List<FeedbackResponseAttributes> responsesFromGiver = frLogic.getFeedbackResponsesFromGiverForCourse(studentToUpdate.course, studentToUpdate.email);
    List<FeedbackResponseAttributes> responsesToAndFromStudent = new ArrayList<>();
    responsesToAndFromStudent.addAll(responsesForReceiver);
    responsesToAndFromStudent.addAll(responsesFromGiver);
    List<FeedbackResponseCommentAttributes> responseCommentsForStudent = getFeedbackResponseCommentsForResponsesFromDatastore(responsesToAndFromStudent);
    assertEquals(responsesForReceiver.size(), 2);
    assertEquals(responsesFromGiver.size(), 2);
    assertEquals(responseCommentsForStudent.size(), 2);
    frLogic.updateFeedbackResponsesForChangingEmail(studentToUpdate.course, studentToUpdate.email, "new@email.tmt");
    responsesForReceiver = frLogic.getFeedbackResponsesForReceiverForCourse(studentToUpdate.course, studentToUpdate.email);
    responsesFromGiver = frLogic.getFeedbackResponsesFromGiverForCourse(studentToUpdate.course, studentToUpdate.email);
    responsesToAndFromStudent = new ArrayList<>();
    responsesToAndFromStudent.addAll(responsesForReceiver);
    responsesToAndFromStudent.addAll(responsesFromGiver);
    responseCommentsForStudent = getFeedbackResponseCommentsForResponsesFromDatastore(responsesToAndFromStudent);
    assertEquals(responsesForReceiver.size(), 0);
    assertEquals(responsesFromGiver.size(), 0);
    assertEquals(responseCommentsForStudent.size(), 0);
    responsesForReceiver = frLogic.getFeedbackResponsesForReceiverForCourse(studentToUpdate.course, "new@email.tmt");
    responsesFromGiver = frLogic.getFeedbackResponsesFromGiverForCourse(studentToUpdate.course, "new@email.tmt");
    responsesToAndFromStudent = new ArrayList<>();
    responsesToAndFromStudent.addAll(responsesForReceiver);
    responsesToAndFromStudent.addAll(responsesFromGiver);
    responseCommentsForStudent = getFeedbackResponseCommentsForResponsesFromDatastore(responsesToAndFromStudent);
    assertEquals(responsesForReceiver.size(), 2);
    assertEquals(responsesFromGiver.size(), 2);
    assertEquals(responseCommentsForStudent.size(), 2);
    frLogic.updateFeedbackResponsesForChangingEmail(studentToUpdate.course, "new@email.tmt", studentToUpdate.email);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) ArrayList(java.util.ArrayList) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 70 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method testUpdateFeedbackResponse.

private void testUpdateFeedbackResponse() throws Exception {
    ______TS("success: standard update with carried params ");
    FeedbackResponseAttributes responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
    responseToUpdate.responseMetaData = new Text("Updated Response");
    responseToUpdate.feedbackSessionName = "copy over";
    responseToUpdate.recipient = null;
    frLogic.updateFeedbackResponse(responseToUpdate);
    responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
    responseToUpdate.responseMetaData = new Text("Updated Response");
    assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
    ______TS("failure: recipient one that is already exists");
    responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
    FeedbackResponseAttributes existingResponse = new FeedbackResponseAttributes(responseToUpdate.feedbackSessionName, responseToUpdate.courseId, responseToUpdate.feedbackQuestionId, responseToUpdate.feedbackQuestionType, responseToUpdate.giver, responseToUpdate.giverSection, "student3InCourse1@gmail.tmt", responseToUpdate.recipientSection, responseToUpdate.responseMetaData);
    frLogic.createFeedbackResponse(existingResponse);
    responseToUpdate.recipient = "student3InCourse1@gmail.tmt";
    try {
        frLogic.updateFeedbackResponse(responseToUpdate);
        signalFailureToDetectException("Should have detected that same giver->recipient response alr exists");
    } catch (EntityAlreadyExistsException e) {
        AssertHelper.assertContains("Trying to create a Feedback Response that exists", e.getMessage());
    }
    ______TS("success: standard update with carried params - using createFeedbackResponse");
    responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
    responseToUpdate.responseMetaData = new Text("Updated Response 2");
    responseToUpdate.feedbackSessionName = "copy over";
    frLogic.createFeedbackResponse(responseToUpdate);
    responseToUpdate = getResponseFromDatastore("response1ForQ2S1C1");
    responseToUpdate.responseMetaData = new Text("Updated Response 2");
    assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
    ______TS("success: recipient changed to something else");
    responseToUpdate.recipient = "student5InCourse1@gmail.tmt";
    frLogic.updateFeedbackResponse(responseToUpdate);
    assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
    assertNull(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, "student2InCourse1@gmail.tmt"));
    ______TS("success: both giver and recipient changed (teammate changed response)");
    responseToUpdate = getResponseFromDatastore("response1GracePeriodFeedback");
    responseToUpdate.giver = "student5InCourse1@gmail.tmt";
    responseToUpdate.recipient = "Team 1.1";
    assertNotNull(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, "student4InCourse1@gmail.tmt", "Team 1.2"));
    frLogic.updateFeedbackResponse(responseToUpdate);
    assertEquals(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, responseToUpdate.giver, responseToUpdate.recipient).toString(), responseToUpdate.toString());
    assertNull(frLogic.getFeedbackResponse(responseToUpdate.feedbackQuestionId, "student4InCourse1@gmail.tmt", "Team 1.2"));
    ______TS("failure: invalid params");
    // Cannot have invalid params as all possible invalid params
    // are copied over from an existing response.
    ______TS("failure: no such response");
    responseToUpdate.setId("invalidId");
    try {
        frLogic.updateFeedbackResponse(responseToUpdate);
        signalFailureToDetectException("Should have detected that this response does not exist");
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains("Trying to update a feedback response that does not exist.", e.getMessage());
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) Text(com.google.appengine.api.datastore.Text) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

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