@Test public void testRemoveAlertsFromMetaAlertNoChildAlerts() { Document empty = new Document(new HashMap<>(), "empty", METAALERT_TYPE, 0L); boolean actual = dao.removeAlertsFromMetaAlert(empty, Collections.singletonList("child")); assertFalse(actual); }
@Test public void testRemoveAlertsFromMetaAlertEmptyRemoveMultiple() { Document metDoc = new Document(new HashMap<>(), METAALERT_GUID, METAALERT_TYPE, 0L); metDoc.getDocument().put(STATUS_FIELD, ACTIVE.getStatusString()); List<Document> alerts = buildChildAlerts(3, null, null); metDoc.getDocument().put(ALERT_FIELD, getRawMaps(alerts)); List<String> removeGuids = new ArrayList<>(); removeGuids.add("child_0"); removeGuids.add("child_2"); removeGuids.add("child_doesn't_exist"); boolean actual = dao.removeAlertsFromMetaAlert(metDoc, removeGuids); // Build the expected metaalert Document expected = new Document(new HashMap<>(), METAALERT_GUID, METAALERT_TYPE, 0L); expected.getDocument().put(STATUS_FIELD, ACTIVE.getStatusString()); List<Map<String, Object>> alertsExpected = new ArrayList<>(); alertsExpected.add(new HashMap<String, Object>() {{ put(METAALERT_FIELD, new ArrayList<>()); put(Constants.GUID, "child_1"); put(THREAT_FIELD_DEFAULT, 0.0f); }} ); expected.getDocument().put(ALERT_FIELD, alertsExpected); assertEquals(expected, metDoc); assertTrue(actual); }
alerts ); boolean actual = dao.removeAlertsFromMetaAlert(metaDoc, Collections.singletonList("child_0"));
@Test public void testRemoveAlertsFromMetaAlertEmptyRemoveList() { Document metaDoc = new Document( new HashMap<>(), METAALERT_GUID, METAALERT_TYPE, 0L ); metaDoc.getDocument().put( STATUS_FIELD, ACTIVE.getStatusString() ); metaDoc.getDocument().put( ALERT_FIELD, new HashMap<String, Object>() {{ put(Constants.GUID, "child_0"); }} ); boolean actual = dao.removeAlertsFromMetaAlert(metaDoc, new ArrayList<>()); assertFalse(actual); }
@Test(expected = IllegalStateException.class) public void testRemoveAlertsFromMetaAlertInactive() throws IOException { dao.removeAlertsFromMetaAlert(INACTIVE.getStatusString(), null); }
@Test public void removeAlertsFromMetaAlertShouldThrowExceptionOnMissingMetaAlert() throws Exception { thrown.expect(IOException.class); thrown.expectMessage("Unable to remove alerts from meta alert. Meta alert with guid some_guid cannot be found."); dao.removeAlertsFromMetaAlert("some_guid", new ArrayList<>()); }