@Override public int hashCode() { int result = getComment() != null ? getComment().hashCode() : 0; result = 31 * result + (getUsername() != null ? getUsername().hashCode() : 0); result = 31 * result + (int) (getTimestamp() ^ (getTimestamp() >>> 32)); return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AlertComment that = (AlertComment) o; if (getTimestamp() != that.getTimestamp()) { return false; } if (getComment() != null ? !getComment().equals(that.getComment()) : that.getComment() != null) { return false; } return getUsername() != null ? getUsername().equals(that.getUsername()) : that.getUsername() == null; }
@Test public void testAddComment() throws Exception { Document document = createAndIndexDocument("testAddCommentAndPatch"); // comment on the document String commentText = "New Comment"; String commentUser = "test_user"; long commentTimestamp = 152630493050L; Document withComment = addAlertComment(document.getGuid(), commentText, commentUser, commentTimestamp); { // validate that the comment was made on the returned document List<AlertComment> comments = getComments(withComment); Assert.assertEquals(1, comments.size()); Assert.assertEquals(commentText, comments.get(0).getComment()); Assert.assertEquals(commentUser, comments.get(0).getUsername()); Assert.assertEquals(commentTimestamp, comments.get(0).getTimestamp()); } { // validate that the comment was made on the indexed document Document indexed = findUpdatedDoc(withComment.getDocument(), withComment.getGuid(), SENSOR_NAME); List<AlertComment> comments = getComments(indexed); Assert.assertEquals(1, comments.size()); Assert.assertEquals(commentText, comments.get(0).getComment()); Assert.assertEquals(commentUser, comments.get(0).getUsername()); Assert.assertEquals(commentTimestamp, comments.get(0).getTimestamp()); } }
@Test public void testRemoveComments() throws Exception { String guid = "testRemoveComments"; createAndIndexDocument(guid); // add a comment on the document Document withComments = addAlertComment(guid, "comment", "user1", 1526401584951L); Assert.assertEquals(1, getComments(withComments).size()); // ensure the comment was added to the document in the index Document indexedWithComments = findUpdatedDoc(withComments.getDocument(), withComments.getGuid(), withComments.getSensorType()); Assert.assertEquals(1, getComments(indexedWithComments).size()); // remove a comment from the document AlertComment toRemove = getComments(withComments).get(0); Document noComments = removeAlertComment(guid, toRemove.getComment(), toRemove.getUsername(), toRemove.getTimestamp()); Assert.assertEquals(0, getComments(noComments).size()); // ensure the comment was removed from the index Document indexedNoComments = findUpdatedDoc(noComments.getDocument(), withComments.getGuid(), withComments.getSensorType()); Assert.assertEquals(0, getComments(indexedNoComments).size()); }