protected Document buildMetaAlert(List<Document> alerts) { Map<String, Object> metaAlertMap = new HashMap<>(); metaAlertMap.put(ALERT_FIELD, getRawMaps(alerts)); metaAlertMap.put(Constants.GUID, METAALERT_GUID); return new Document( metaAlertMap, METAALERT_GUID, METAALERT_TYPE, 0L ); } }
@Test public void testBuildAddAlertToMetaAlertUpdatesEmpty() { Document metaDoc = new Document( new HashMap<>(), METAALERT_GUID, METAALERT_TYPE, 0L ); metaDoc.getDocument().put( ALERT_FIELD, getRawMaps(buildChildAlerts(1, METAALERT_GUID, null)) ); Map<Document, Optional<String>> actual = dao .buildAddAlertToMetaAlertUpdates(metaDoc, new ArrayList<>()); assertEquals(0, actual.size()); }
expectedAlerts.addAll(getRawMaps(newAlerts));
metaAlertMap.put(ALERT_FIELD, getRawMaps(alerts)); metaAlertMap.put(Constants.GUID, METAALERT_GUID); metaAlertMap.put(STATUS_FIELD, MetaAlertStatus.ACTIVE.getStatusString());
metaAlertMap.put(ALERT_FIELD, getRawMaps(alerts)); metaAlertMap.put(Constants.GUID, METAALERT_GUID); metaAlertMap.put(STATUS_FIELD, MetaAlertStatus.INACTIVE.getStatusString());
@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); }