Search in sources :

Example 11 with FeedbackResponseCommentAttributes

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

the class FeedbackResponseCommentsLogicTest method testCreateFeedbackResponseComment.

@Test
public void testCreateFeedbackResponseComment() throws Exception {
    FeedbackResponseCommentAttributes frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
    ______TS("fail: non-existent course");
    frComment.courseId = "no-such-course";
    verifyExceptionThrownFromCreateFrComment(frComment, "Trying to create feedback response comments for a course that does not exist.");
    frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
    ______TS("fail: giver is not instructor");
    frComment.giverEmail = "student2InCourse1@gmail.com";
    verifyExceptionThrownFromCreateFrComment(frComment, "User " + frComment.giverEmail + " is not a registered instructor for course " + frComment.courseId + ".");
    frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
    ______TS("fail: giver is not an instructor for the course");
    frComment.giverEmail = "instructor1@course2.com";
    verifyExceptionThrownFromCreateFrComment(frComment, "User " + frComment.giverEmail + " is not a registered instructor for course " + frComment.courseId + ".");
    frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
    ______TS("fail: feedback session is not a session for the course");
    frComment.feedbackSessionName = "Private feedback session";
    verifyExceptionThrownFromCreateFrComment(frComment, "Feedback session " + frComment.feedbackSessionName + " is not a session for course " + frComment.courseId + ".");
    frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
    ______TS("typical successful case");
    frComment.setId(null);
    frComment.feedbackQuestionId = getQuestionIdInDataBundle("qn1InSession1InCourse1");
    frComment.feedbackResponseId = getResponseIdInDataBundle("response2ForQ1S1C1", "qn1InSession1InCourse1");
    frcLogic.createFeedbackResponseComment(frComment);
    verifyPresentInDatastore(frComment);
    ______TS("typical successful case: frComment already exists");
    frcLogic.createFeedbackResponseComment(frComment);
    List<FeedbackResponseCommentAttributes> actualFrComments = frcLogic.getFeedbackResponseCommentForSession(frComment.courseId, frComment.feedbackSessionName);
    FeedbackResponseCommentAttributes actualFrComment = null;
    for (int i = 0; i < actualFrComments.size(); i++) {
        if (actualFrComments.get(i).commentText.equals(frComment.commentText)) {
            actualFrComment = actualFrComments.get(i);
            break;
        }
    }
    assertNotNull(actualFrComment);
    // delete afterwards
    frcLogic.deleteFeedbackResponseComment(frComment);
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Test(org.testng.annotations.Test)

Example 12 with FeedbackResponseCommentAttributes

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

the class FeedbackResponseCommentsLogicTest method testDeleteFeedbackResponseComment.

@Test
public void testDeleteFeedbackResponseComment() throws Exception {
    // create a frComment to delete
    FeedbackResponseCommentAttributes frComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q1S1C1");
    frComment.setId(null);
    frComment.feedbackQuestionId = getQuestionIdInDataBundle("qn2InSession1InCourse1");
    frComment.feedbackResponseId = getResponseIdInDataBundle("response2ForQ2S1C1", "qn2InSession1InCourse1");
    frcLogic.createFeedbackResponseComment(frComment);
    ______TS("silent fail nothing to delete");
    frComment.feedbackResponseId = "invalid responseId";
    // without proper frCommentId and its feedbackResponseId,
    // it cannot be deleted
    frcLogic.deleteFeedbackResponseComment(frComment);
    FeedbackResponseCommentAttributes actualFrComment = frcLogic.getFeedbackResponseCommentForSession(frComment.courseId, frComment.feedbackSessionName).get(1);
    verifyPresentInDatastore(actualFrComment);
    ______TS("typical success case");
    frcLogic.deleteFeedbackResponseComment(actualFrComment);
    verifyAbsentInDatastore(actualFrComment);
    ______TS("typical success case for response");
    FeedbackResponseCommentAttributes anotherFrComment = restoreFrCommentFromDataBundle("comment1FromT1C1ToR1Q2S1C1");
    verifyPresentInDatastore(anotherFrComment);
    frcLogic.deleteFeedbackResponseCommentsForResponse(anotherFrComment.feedbackResponseId);
    verifyAbsentInDatastore(anotherFrComment);
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Test(org.testng.annotations.Test)

Example 13 with FeedbackResponseCommentAttributes

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

the class FeedbackResponseCommentsDbTest method testUpdateFeedbackResponseComment.

private void testUpdateFeedbackResponseComment() throws Exception {
    ______TS("null parameter");
    try {
        frcDb.updateFeedbackResponseComment(null);
        signalFailureToDetectException();
    } catch (AssertionError ae) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, ae.getMessage());
    }
    ______TS("typical success case");
    FeedbackResponseCommentAttributes frcaTemp = dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q2S1C1");
    frcaTemp.createdAt = Instant.now();
    frcaTemp.commentText = new Text("Update feedback response comment");
    frcDb.createEntity(frcaTemp);
    frcaTemp = frcDb.getFeedbackResponseComment(frcaTemp.feedbackResponseId, frcaTemp.giverEmail, frcaTemp.createdAt);
    FeedbackResponseCommentAttributes frcaExpected = frcDb.getFeedbackResponseComment(frcaTemp.courseId, frcaTemp.createdAt, frcaTemp.giverEmail);
    frcaExpected.commentText = new Text("This is new Text");
    frcDb.updateFeedbackResponseComment(frcaExpected);
    FeedbackResponseCommentAttributes frcaActual = frcDb.getFeedbackResponseComment(frcaExpected.courseId, frcaExpected.createdAt, frcaExpected.giverEmail);
    frcaExpected.setId(frcaActual.getId());
    frcaExpected.feedbackQuestionId = frcaActual.feedbackQuestionId;
    assertEquals(frcaExpected.courseId, frcaActual.courseId);
    assertEquals(frcaExpected.commentText, frcaActual.commentText);
    frcDb.deleteEntity(frcaTemp);
    ______TS("non-existent comment");
    frcaExpected.setId(-1L);
    try {
        frcDb.updateFeedbackResponseComment(frcaExpected);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException edne) {
        assertEquals(EntitiesDb.ERROR_UPDATE_NON_EXISTENT + frcaExpected.toString(), edne.getMessage());
    }
    // set responseId back
    frcaExpected.feedbackResponseId = frId;
    ______TS("invalid parameters");
    frcaExpected.courseId = "";
    frcaExpected.feedbackSessionName = "%asdt";
    frcaExpected.giverEmail = "test-no-at-funny.com";
    try {
        frcDb.updateFeedbackResponseComment(frcaExpected);
        signalFailureToDetectException();
    } catch (InvalidParametersException ipe) {
        assertEquals(StringHelper.toString(frcaExpected.getInvalidityInfo()), ipe.getMessage());
    }
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException)

Example 14 with FeedbackResponseCommentAttributes

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

the class FeedbackResponseCommentsDbTest method testEntityCreationAndDeletion.

private void testEntityCreationAndDeletion() throws Exception {
    FeedbackResponseCommentAttributes frcaTemp = dataBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q2S1C1");
    frcaTemp.createdAt = Instant.now();
    frcaTemp.commentText = new Text("test creation and deletion");
    ______TS("Entity creation");
    frcDb.createEntity(frcaTemp);
    verifyPresentInDatastore(frcaTemp);
    ______TS("Entity deletion");
    frcDb.deleteEntity(frcaTemp);
    verifyAbsentInDatastore(frcaTemp);
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text)

Example 15 with FeedbackResponseCommentAttributes

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

the class FeedbackResponseCommentsDbTest method verifyListsContainSameResponseCommentAttributes.

private void verifyListsContainSameResponseCommentAttributes(List<FeedbackResponseCommentAttributes> expectedFrcas, List<FeedbackResponseCommentAttributes> actualFrcas) {
    for (FeedbackResponseCommentAttributes frca : expectedFrcas) {
        frca.feedbackQuestionId = "";
        frca.feedbackResponseId = "";
        frca.setId(0L);
    }
    for (FeedbackResponseCommentAttributes frca : actualFrcas) {
        frca.feedbackQuestionId = "";
        frca.feedbackResponseId = "";
        frca.setId(0L);
    }
    AssertHelper.assertSameContentIgnoreOrder(expectedFrcas, actualFrcas);
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)

Aggregations

FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)46 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)15 Test (org.testng.annotations.Test)13 Text (com.google.appengine.api.datastore.Text)12 ArrayList (java.util.ArrayList)12 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)9 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)9 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)9 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 FeedbackResponseCommentsDb (teammates.storage.api.FeedbackResponseCommentsDb)6 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)5 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)5 InstructorFeedbackResponseCommentAjaxPageData (teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData)4 FeedbackResponseCommentRow (teammates.ui.template.FeedbackResponseCommentRow)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)2 FeedbackSessionResultsBundle (teammates.common.datatransfer.FeedbackSessionResultsBundle)2