Add comment fails in Create/Update comments

Hi,

I’m facing problem with addComment method, comment is not inserted in DB, and fails only one test case ‘testUserUpdatesOwnComments’.
Is there any problem in my code?

public Comment addComment(Comment comment) {
if (comment == null || comment.getId() == null || comment.getId().isEmpty())
{
throw new IncorrectDaoOperation(“Comment object should not be null”);
}
try {
commentCollection.insertOne(comment);
} catch (Exception e) {
throw new IncorrectDaoOperation(“Insert exception”);
}
return comment;
}

Solution:

Its not problem with addComment method problem with updateComment and deleteComment methods.
I had not used ObjectId(commentId) for _id field of comments.
Once changed to ObjectId(commentId) it worked fine.

Thanks,
Simhachalam.

1 Like