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"));
}
Aggregations