Search in sources :

Example 1 with CommentAddRemoveRequest

use of org.apache.metron.indexing.dao.update.CommentAddRemoveRequest in project metron by apache.

the class MultiIndexDaoTest method removeCommentShouldRemoveCommentFromAlert.

@Test
public void removeCommentShouldRemoveCommentFromAlert() throws Exception {
    Document latest = mock(Document.class);
    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);
    assertEquals(expected, multiIndexDao.removeCommentFromAlert(request, latest));
}
Also used : CommentAddRemoveRequest(org.apache.metron.indexing.dao.update.CommentAddRemoveRequest) Document(org.apache.metron.indexing.dao.update.Document) Test(org.junit.jupiter.api.Test)

Example 2 with CommentAddRemoveRequest

use of org.apache.metron.indexing.dao.update.CommentAddRemoveRequest in project metron by apache.

the class UpdateDaoTest method removeCommentShouldThrowExceptionOnEmptyComments.

@Test
public void removeCommentShouldThrowExceptionOnEmptyComments() throws Exception {
    CommentAddRemoveRequest request = new CommentAddRemoveRequest();
    request.setGuid("guid");
    Document latest = new Document(new HashMap<>(), "guid", "bro", System.currentTimeMillis());
    IOException e = assertThrows(IOException.class, () -> getUpdateDao().removeCommentFromAlert(request, latest));
    assertEquals("Unable to remove comment. Document with guid guid has no comments.", e.getMessage());
}
Also used : CommentAddRemoveRequest(org.apache.metron.indexing.dao.update.CommentAddRemoveRequest) IOException(java.io.IOException) Document(org.apache.metron.indexing.dao.update.Document) Test(org.junit.jupiter.api.Test)

Example 3 with CommentAddRemoveRequest

use of org.apache.metron.indexing.dao.update.CommentAddRemoveRequest in project metron by apache.

the class UpdateDaoTest method addCommentShouldThrowExceptionOnMissingAlert.

@Test
public void addCommentShouldThrowExceptionOnMissingAlert() {
    CommentAddRemoveRequest request = new CommentAddRemoveRequest();
    request.setGuid("guid");
    IOException e = assertThrows(IOException.class, () -> getUpdateDao().addCommentToAlert(request, null));
    assertEquals("Unable to add comment. Document with guid guid cannot be found.", e.getMessage());
}
Also used : CommentAddRemoveRequest(org.apache.metron.indexing.dao.update.CommentAddRemoveRequest) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test)

Example 4 with CommentAddRemoveRequest

use of org.apache.metron.indexing.dao.update.CommentAddRemoveRequest in project metron by apache.

the class UpdateIntegrationTest method buildAlertRequest.

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;
}
Also used : CommentAddRemoveRequest(org.apache.metron.indexing.dao.update.CommentAddRemoveRequest)

Example 5 with CommentAddRemoveRequest

use of org.apache.metron.indexing.dao.update.CommentAddRemoveRequest in project metron by apache.

the class ElasticsearchMetaAlertDaoTest method testInvalidInit.

@Test
public void testInvalidInit() {
    IndexDao dao = new IndexDao() {

        @Override
        public SearchResponse search(SearchRequest searchRequest) {
            return null;
        }

        @Override
        public GroupResponse group(GroupRequest groupRequest) {
            return null;
        }

        @Override
        public void init(AccessConfig config) {
        }

        @Override
        public Document getLatest(String guid, String sensorType) {
            return null;
        }

        @Override
        public Iterable<Document> getAllLatest(List<GetRequest> getRequests) {
            return null;
        }

        @Override
        public Document update(Document update, Optional<String> index) {
            return update;
        }

        @Override
        public Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates) {
            return updates;
        }

        @Override
        public Map<String, FieldType> getColumnMetadata(List<String> indices) {
            return null;
        }

        @Override
        public Document addCommentToAlert(CommentAddRemoveRequest request) {
            return null;
        }

        @Override
        public Document removeCommentFromAlert(CommentAddRemoveRequest request) {
            return null;
        }

        @Override
        public Document addCommentToAlert(CommentAddRemoveRequest request, Document latest) {
            return null;
        }

        @Override
        public Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest) {
            return null;
        }
    };
    ElasticsearchMetaAlertDao metaAlertDao = new ElasticsearchMetaAlertDao();
    assertThrows(IllegalArgumentException.class, () -> metaAlertDao.init(dao));
}
Also used : CommentAddRemoveRequest(org.apache.metron.indexing.dao.update.CommentAddRemoveRequest) AccessConfig(org.apache.metron.indexing.dao.AccessConfig) Document(org.apache.metron.indexing.dao.update.Document) IndexDao(org.apache.metron.indexing.dao.IndexDao) MultiIndexDao(org.apache.metron.indexing.dao.MultiIndexDao) Test(org.junit.jupiter.api.Test)

Aggregations

CommentAddRemoveRequest (org.apache.metron.indexing.dao.update.CommentAddRemoveRequest)12 Test (org.junit.jupiter.api.Test)11 Document (org.apache.metron.indexing.dao.update.Document)7 IOException (java.io.IOException)3 SearchIntegrationTest (org.apache.metron.indexing.dao.SearchIntegrationTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 ResultActions (org.springframework.test.web.servlet.ResultActions)2 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)1 IndexDao (org.apache.metron.indexing.dao.IndexDao)1 MultiIndexDao (org.apache.metron.indexing.dao.MultiIndexDao)1