use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.
the class ElasticsearchMetaAlertIntegrationTest method shouldCreateMetaAlert.
@Test
public void shouldCreateMetaAlert() throws Exception {
// Load alerts
List<Map<String, Object>> alerts = buildAlerts(3);
elasticsearchAdd(alerts, INDEX, SENSOR_NAME);
// Verify load was successful
findCreatedDocs(Arrays.asList(new GetRequest("message_0", SENSOR_NAME), new GetRequest("message_1", SENSOR_NAME), new GetRequest("message_2", SENSOR_NAME)));
{
MetaAlertCreateRequest metaAlertCreateRequest = new MetaAlertCreateRequest() {
{
setAlerts(new ArrayList<GetRequest>() {
{
add(new GetRequest("message_1", SENSOR_NAME));
add(new GetRequest("message_2", SENSOR_NAME, INDEX));
}
});
setGroups(Collections.singletonList("group"));
}
};
MetaAlertCreateResponse metaAlertCreateResponse = metaDao.createMetaAlert(metaAlertCreateRequest);
{
// Verify metaAlert was created
findCreatedDoc(metaAlertCreateResponse.getGuid(), MetaAlertDao.METAALERT_TYPE);
}
{
// Verify alert 0 was not updated with metaalert field
Document alert = metaDao.getLatest("message_0", SENSOR_NAME);
Assert.assertEquals(4, alert.getDocument().size());
Assert.assertNull(alert.getDocument().get(METAALERT_FIELD));
}
{
// Verify alert 1 was properly updated with metaalert field
Document alert = metaDao.getLatest("message_1", SENSOR_NAME);
Assert.assertEquals(5, alert.getDocument().size());
Assert.assertEquals(1, ((List) alert.getDocument().get(METAALERT_FIELD)).size());
Assert.assertEquals(metaAlertCreateResponse.getGuid(), ((List) alert.getDocument().get(METAALERT_FIELD)).get(0));
}
{
// Verify alert 2 was properly updated with metaalert field
Document alert = metaDao.getLatest("message_2", SENSOR_NAME);
Assert.assertEquals(5, alert.getDocument().size());
Assert.assertEquals(1, ((List) alert.getDocument().get(METAALERT_FIELD)).size());
Assert.assertEquals(metaAlertCreateResponse.getGuid(), ((List) alert.getDocument().get(METAALERT_FIELD)).get(0));
}
}
}
use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.
the class SolrMetaAlertDaoTest method testCreateMetaAlertEmptyGuids.
@Test
public void testCreateMetaAlertEmptyGuids() {
SolrDao solrDao = new SolrDao();
solrDao.init(accessConfig);
SolrMetaAlertDao emaDao = new SolrMetaAlertDao();
emaDao.init(solrDao);
MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.
the class SolrMetaAlertDaoTest method testCreateMetaAlertEmptyGroups.
@Test
public void testCreateMetaAlertEmptyGroups() {
SolrDao solrDao = new SolrDao();
solrDao.init(accessConfig);
MultiIndexDao miDao = new MultiIndexDao(solrDao);
SolrMetaAlertDao emaDao = new SolrMetaAlertDao();
emaDao.init(miDao);
MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
createRequest.setAlerts(Collections.singletonList(new GetRequest("don't", "care")));
assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.
the class ElasticsearchMetaAlertDaoTest method testCreateMetaAlertEmptyGuids.
@Test
public void testCreateMetaAlertEmptyGuids() {
ElasticsearchDao esDao = new ElasticsearchDao();
ElasticsearchMetaAlertDao emaDao = new ElasticsearchMetaAlertDao();
emaDao.init(esDao);
MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
use of org.apache.metron.indexing.dao.metaalert.MetaAlertCreateRequest in project metron by apache.
the class ElasticsearchMetaAlertDaoTest method testCreateMetaAlertEmptyGroups.
@Test
public void testCreateMetaAlertEmptyGroups() {
ElasticsearchDao esDao = new ElasticsearchDao();
MultiIndexDao miDao = new MultiIndexDao(esDao);
ElasticsearchMetaAlertDao emaDao = new ElasticsearchMetaAlertDao();
emaDao.init(miDao);
MetaAlertCreateRequest createRequest = new MetaAlertCreateRequest();
createRequest.setAlerts(Collections.singletonList(new GetRequest("don't", "care")));
assertThrows(InvalidCreateException.class, () -> emaDao.createMetaAlert(createRequest));
}
Aggregations