Search in sources :

Example 71 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method testUpdateFeedbackResponsesForChangingTeam_deleteLastResponse_decreaseResponseRate.

private void testUpdateFeedbackResponsesForChangingTeam_deleteLastResponse_decreaseResponseRate() throws Exception {
    FeedbackResponseAttributes responseToBeDeleted = getResponseFromDatastore(questionTypeBundle, "response1ForQ1ContribSession2Course2");
    // make sure it's the last response by the student
    assertEquals(1, numResponsesFromGiverInSession(responseToBeDeleted.giver, responseToBeDeleted.feedbackSessionName, responseToBeDeleted.courseId));
    StudentAttributes student = questionTypeBundle.students.get("student2InCourse2");
    StudentEnrollDetails enrollmentDetailsToTriggerDeletion = new StudentEnrollDetails(StudentUpdateStatus.MODIFIED, student.course, student.email, student.team, student.team + "tmp", student.section, student.section + "tmp");
    int originalResponseRate = getResponseRate(responseToBeDeleted.feedbackSessionName, responseToBeDeleted.courseId);
    assertTrue(frLogic.updateFeedbackResponseForChangingTeam(enrollmentDetailsToTriggerDeletion, responseToBeDeleted));
    int responseRateAfterDeletion = getResponseRate(responseToBeDeleted.feedbackSessionName, responseToBeDeleted.courseId);
    assertEquals(originalResponseRate - 1, responseRateAfterDeletion);
    // restore DataStore so other tests are unaffected
    restoreStudentFeedbackResponseToDatastore(responseToBeDeleted);
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) StudentEnrollDetails(teammates.common.datatransfer.StudentEnrollDetails) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes)

Example 72 with FeedbackResponseAttributes

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

the class FeedbackResponsesLogicTest method testDeleteFeedbackResponsesForStudent.

private void testDeleteFeedbackResponsesForStudent() throws Exception {
    ______TS("standard delete");
    StudentAttributes studentToDelete = dataBundle.students.get("student1InCourse1");
    List<FeedbackResponseAttributes> responsesForStudent1 = frLogic.getFeedbackResponsesFromGiverForCourse(studentToDelete.course, studentToDelete.email);
    responsesForStudent1.addAll(frLogic.getFeedbackResponsesForReceiverForCourse(studentToDelete.course, studentToDelete.email));
    frLogic.deleteFeedbackResponsesForStudentAndCascade(studentToDelete.course, studentToDelete.email);
    List<FeedbackResponseAttributes> remainingResponses = new ArrayList<>();
    remainingResponses.addAll(frLogic.getFeedbackResponsesFromGiverForCourse(studentToDelete.course, studentToDelete.email));
    remainingResponses.addAll(frLogic.getFeedbackResponsesForReceiverForCourse(studentToDelete.course, studentToDelete.email));
    assertEquals(remainingResponses.size(), 0);
    List<FeedbackResponseCommentAttributes> remainingComments = new ArrayList<>();
    for (FeedbackResponseAttributes response : responsesForStudent1) {
        remainingComments.addAll(frcLogic.getFeedbackResponseCommentForResponse(response.getId()));
    }
    assertEquals(remainingComments.size(), 0);
    ______TS("shift team then delete");
    remainingResponses.clear();
    studentToDelete = dataBundle.students.get("student2InCourse1");
    studentToDelete.team = "Team 1.3";
    StudentsLogic.inst().updateStudentCascadeWithoutDocument(studentToDelete.email, studentToDelete);
    frLogic.deleteFeedbackResponsesForStudentAndCascade(studentToDelete.course, studentToDelete.email);
    remainingResponses.addAll(frLogic.getFeedbackResponsesFromGiverForCourse(studentToDelete.course, studentToDelete.email));
    remainingResponses.addAll(frLogic.getFeedbackResponsesForReceiverForCourse(studentToDelete.course, studentToDelete.email));
    assertEquals(remainingResponses.size(), 0);
    ______TS("delete last person in team");
    remainingResponses.clear();
    studentToDelete = dataBundle.students.get("student5InCourse1");
    frLogic.deleteFeedbackResponsesForStudentAndCascade(studentToDelete.course, studentToDelete.email);
    remainingResponses.addAll(frLogic.getFeedbackResponsesFromGiverForCourse(studentToDelete.course, studentToDelete.email));
    remainingResponses.addAll(frLogic.getFeedbackResponsesForReceiverForCourse(studentToDelete.course, studentToDelete.email));
    // check that team responses are gone too. already checked giver as it is stored by giver email not team id.
    remainingResponses.addAll(frLogic.getFeedbackResponsesForReceiverForCourse(studentToDelete.course, "Team 1.2"));
    assertEquals(remainingResponses.size(), 0);
}
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 73 with FeedbackResponseAttributes

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

the class FeedbackResponsesDbTest method testUpdateFeedbackResponse.

@Test
public void testUpdateFeedbackResponse() throws Exception {
    ______TS("null params");
    try {
        frDb.updateFeedbackResponse(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("invalid feedback response attributes");
    FeedbackResponseAttributes invalidFra = getResponseAttributes("response3ForQ2S1C1");
    invalidFra.setId(frDb.getFeedbackResponse(invalidFra.feedbackQuestionId, invalidFra.giver, invalidFra.recipient).getId());
    invalidFra.courseId = "invalid course_";
    try {
        frDb.updateFeedbackResponse(invalidFra);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, "invalid course_", FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), e.getLocalizedMessage());
    }
    ______TS("feedback response does not exist");
    FeedbackResponseAttributes nonexistantFr = getResponseAttributes("response3ForQ2S1C1");
    nonexistantFr.setId("non-existent fr id");
    try {
        frDb.updateFeedbackResponse(nonexistantFr);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains(FeedbackResponsesDb.ERROR_UPDATE_NON_EXISTENT, e.getLocalizedMessage());
    }
    ______TS("standard success case");
    FeedbackResponseAttributes modifiedResponse = getResponseAttributes("response3ForQ2S1C1");
    modifiedResponse = frDb.getFeedbackResponse(modifiedResponse.feedbackQuestionId, modifiedResponse.giver, modifiedResponse.recipient);
    FeedbackResponseDetails frd = modifiedResponse.getResponseDetails();
    Map<String, String[]> requestParameters = new HashMap<>();
    requestParameters.put("questiontype-1", new String[] { "TEXT" });
    requestParameters.put("responsetext-1-0", new String[] { "New answer text!" });
    String[] answer = { "New answer text!" };
    frd = FeedbackResponseDetails.createResponseDetails(answer, FeedbackQuestionType.TEXT, null, requestParameters, 1, 0);
    modifiedResponse.setResponseDetails(frd);
    frDb.updateFeedbackResponse(modifiedResponse);
    verifyPresentInDatastore(modifiedResponse);
    modifiedResponse = frDb.getFeedbackResponse(modifiedResponse.feedbackQuestionId, modifiedResponse.giver, modifiedResponse.recipient);
    assertEquals("New answer text!", modifiedResponse.getResponseDetails().getAnswerString());
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) HashMap(java.util.HashMap) InvalidParametersException(teammates.common.exception.InvalidParametersException) FeedbackResponseDetails(teammates.common.datatransfer.questions.FeedbackResponseDetails) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 74 with FeedbackResponseAttributes

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

the class FeedbackResponsesDbTest method getNewFeedbackResponseAttributes.

private FeedbackResponseAttributes getNewFeedbackResponseAttributes() {
    FeedbackResponseAttributes fra = new FeedbackResponseAttributes();
    fra.feedbackSessionName = "fsTest1";
    fra.courseId = "testCourse";
    fra.feedbackQuestionType = FeedbackQuestionType.TEXT;
    fra.giver = "giver@email.tmt";
    fra.giverSection = "None";
    fra.recipient = "recipient@email.tmt";
    fra.recipientSection = "None";
    fra.feedbackQuestionId = "testFeedbackQuestionId";
    FeedbackResponseDetails responseDetails = new FeedbackTextResponseDetails("Text response");
    fra.setResponseDetails(responseDetails);
    return fra;
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseDetails(teammates.common.datatransfer.questions.FeedbackResponseDetails) FeedbackTextResponseDetails(teammates.common.datatransfer.questions.FeedbackTextResponseDetails)

Example 75 with FeedbackResponseAttributes

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

the class FeedbackResponsesDbTest method testCreateDeleteFeedbackResponse.

@Test
public void testCreateDeleteFeedbackResponse() throws Exception {
    ______TS("standard success case");
    FeedbackResponseAttributes fra = getNewFeedbackResponseAttributes();
    // remove possibly conflicting entity from the database
    frDb.deleteEntity(fra);
    frDb.createEntity(fra);
    // sets the id for fra
    verifyPresentInDatastore(fra);
    ______TS("duplicate - with same id.");
    try {
        frDb.createEntity(fra);
        signalFailureToDetectException();
    } catch (EntityAlreadyExistsException e) {
        AssertHelper.assertContains(String.format(FeedbackResponsesDb.ERROR_CREATE_ENTITY_ALREADY_EXISTS, fra.getEntityTypeAsString()) + fra.getIdentificationString(), e.getMessage());
    }
    ______TS("delete - with id specified");
    frDb.deleteEntity(fra);
    verifyAbsentInDatastore(fra);
    ______TS("null params");
    try {
        frDb.createEntity(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        AssertHelper.assertContains(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getLocalizedMessage());
    }
    ______TS("invalid params");
    try {
        fra.courseId = "invalid course id!";
        frDb.createEntity(fra);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.COURSE_ID_ERROR_MESSAGE, "invalid course id!", FieldValidator.COURSE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.COURSE_ID_MAX_LENGTH), e.getLocalizedMessage());
    }
}
Also used : FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) Test(org.testng.annotations.Test)

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