@Test public void getLatestShouldReturnLatestAlert() throws Exception { Document document1 = new Document(new HashMap<>(), "guid", "bro", 1L); Document document2 = new Document(new HashMap<>(), "guid", "bro", 2L); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); when(dao1.getLatest("guid", "bro")).thenReturn(document1); when(dao2.getLatest("guid", "bro")).thenReturn(document2); Document expected = new Document(new HashMap<>(), "guid", "bro", 2L); Assert.assertEquals(expected, multiIndexDao.getLatest("guid", "bro")); }
@Test public void addCommentShouldAddCommentToAlert() throws Exception { Document latest = mock(Document.class); Document document1 = new Document(new HashMap<>(), "guid", "bro", 1L); Document document2 = new Document(new HashMap<>(), "guid", "bro", 2L); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); when(dao1.addCommentToAlert(request, latest)).thenReturn(document1); when(dao2.addCommentToAlert(request, latest)).thenReturn(document2); Document expected = new Document(new HashMap<>(), "guid", "bro", 2L); Assert.assertEquals(expected, multiIndexDao.addCommentToAlert(request, latest)); }
@Test public void removeCommentShouldRemoveCommentFromAlert() throws Exception { Document latest = mock(Document.class); Document document1 = new Document(new HashMap<>(), "guid", "bro", 1L); Document document2 = new Document(new HashMap<>(), "guid", "bro", 2L); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); when(dao1.removeCommentFromAlert(request, latest)).thenReturn(document1); when(dao2.removeCommentFromAlert(request, latest)).thenReturn(document2); Document expected = new Document(new HashMap<>(), "guid", "bro", 2L); Assert.assertEquals(expected, multiIndexDao.removeCommentFromAlert(request, latest)); } }
@Test public void removeCommentShouldThrowExceptionOnEmptyComments() throws Exception { exception.expect(IOException.class); exception.expectMessage("Unable to remove comment. Document with guid guid has no comments."); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); Document latest = new Document(new HashMap<>(), "guid", "bro", System.currentTimeMillis()); getUpdateDao().removeCommentFromAlert(request, latest); }
private CommentAddRemoveRequest buildAlertRequest(String guid, String comment, String username, long timestamp) { CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid(guid); request.setComment(comment); request.setUsername(username); request.setTimestamp(timestamp); request.setSensorType(SENSOR_NAME); return request; }
@Test public void removeCommentShouldThrowExceptionOnMissingAlert() throws Exception { exception.expect(IOException.class); exception.expectMessage("Unable to remove comment. Document with guid guid cannot be found."); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); getUpdateDao().removeCommentFromAlert(request, null); }
@Test public void addCommentShouldThrowExceptionOnMissingAlert() throws Exception { exception.expect(IOException.class); exception.expectMessage("Unable to add comment. Document with guid guid cannot be found."); CommentAddRemoveRequest request = new CommentAddRemoveRequest(); request.setGuid("guid"); getUpdateDao().addCommentToAlert(request, null); }