Search in sources :

Example 1 with MetaAlertAddRemoveRequest

use of org.apache.metron.indexing.dao.metaalert.MetaAlertAddRemoveRequest in project metron by apache.

the class MetaAlertControllerIntegrationTest method shouldAddRemoveAlerts.

@Test
public void shouldAddRemoveAlerts() throws Exception {
    MetaAlertCreateRequest metaAlertCreateRequest = new MetaAlertCreateRequest();
    metaAlertCreateRequest.setGroups(Arrays.asList("group_one", "group_two"));
    metaAlertCreateRequest.setAlerts(new ArrayList<GetRequest>() {

        {
            add(new GetRequest("bro_1", "bro", "bro_index_2017.01.01.01"));
            add(new GetRequest("snort_2", "snort", "snort_index_2017.01.01.01"));
        }
    });
    MetaAlertCreateResponse metaAlertCreateResponse = metaAlertService.create(metaAlertCreateRequest);
    MetaAlertAddRemoveRequest addRequest = new MetaAlertAddRemoveRequest();
    addRequest.setMetaAlertGuid(metaAlertCreateResponse.getGuid());
    addRequest.setAlerts(new ArrayList<GetRequest>() {

        {
            add(new GetRequest("bro_2", "bro", "bro_index_2017.01.01.01"));
            add(new GetRequest("bro_3", "bro", "bro_index_2017.01.01.01"));
        }
    });
    ResultActions result = this.mockMvc.perform(post(metaalertUrl + "/add/alert").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(JSONUtils.INSTANCE.toJSON(addRequest, false)));
    result.andExpect(status().isOk()).andExpect(content().string("true"));
    MetaAlertAddRemoveRequest addDuplicateRequest = new MetaAlertAddRemoveRequest();
    addDuplicateRequest.setMetaAlertGuid(metaAlertCreateResponse.getGuid());
    addDuplicateRequest.setAlerts(new ArrayList<GetRequest>() {

        {
            add(new GetRequest("bro_1", "bro"));
        }
    });
    result = this.mockMvc.perform(post(metaalertUrl + "/add/alert").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(JSONUtils.INSTANCE.toJSON(addDuplicateRequest, false)));
    result.andExpect(status().isOk()).andExpect(content().string("false"));
    MetaAlertAddRemoveRequest removeRequest = new MetaAlertAddRemoveRequest();
    removeRequest.setMetaAlertGuid(metaAlertCreateResponse.getGuid());
    removeRequest.setAlerts(new ArrayList<GetRequest>() {

        {
            add(new GetRequest("bro_2", "bro"));
            add(new GetRequest("bro_3", "bro"));
        }
    });
    result = this.mockMvc.perform(post(metaalertUrl + "/remove/alert").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(JSONUtils.INSTANCE.toJSON(removeRequest, false)));
    result.andExpect(status().isOk()).andExpect(content().string("true"));
    MetaAlertAddRemoveRequest removeMissingRequest = new MetaAlertAddRemoveRequest();
    addRequest.setMetaAlertGuid(metaAlertCreateResponse.getGuid());
    removeMissingRequest.setAlerts(new ArrayList<GetRequest>() {

        {
            add(new GetRequest("bro_1", "bro"));
        }
    });
    result = this.mockMvc.perform(post(metaalertUrl + "/remove/alert").with(httpBasic(user, password)).with(csrf()).contentType(MediaType.parseMediaType("application/json;charset=UTF-8")).content(JSONUtils.INSTANCE.toJSON(removeMissingRequest, false)));
    result.andExpect(status().isOk()).andExpect(content().string("false"));
}
Also used : GetRequest(org.apache.metron.indexing.dao.search.GetRequest) MetaAlertCreateResponse(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateResponse) ResultActions(org.springframework.test.web.servlet.ResultActions) MetaAlertCreateRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest) MetaAlertAddRemoveRequest(org.apache.metron.indexing.dao.metaalert.MetaAlertAddRemoveRequest) SearchIntegrationTest(org.apache.metron.indexing.dao.SearchIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

SearchIntegrationTest (org.apache.metron.indexing.dao.SearchIntegrationTest)1 MetaAlertAddRemoveRequest (org.apache.metron.indexing.dao.metaalert.MetaAlertAddRemoveRequest)1 MetaAlertCreateRequest (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest)1 MetaAlertCreateResponse (org.apache.metron.indexing.dao.metaalert.MetaAlertCreateResponse)1 GetRequest (org.apache.metron.indexing.dao.search.GetRequest)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 ResultActions (org.springframework.test.web.servlet.ResultActions)1