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);
}
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);
}
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());
}
}
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);
}
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);
}
Aggregations