AbstractLuceneMetaAlertUpdateDao implements MetaAlertUpdateDao { protected Map<Document, Optional<String>> buildAddAlertToMetaAlertUpdates(Document metaAlert, Iterable<Document> alerts) { Map<Document, Optional<String>> updates = new HashMap<>(); boolean metaAlertUpdated = addAlertsToMetaAlert(metaAlert, alerts); if (metaAlertUpdated) { MetaScores .calculateMetaScores(metaAlert, config.getThreatTriageField(), config.getThreatSort()); updates.put(metaAlert, Optional.of(config.getMetaAlertIndex())); for (Document alert : alerts) { if (addMetaAlertToAlert(metaAlert.getGuid(), alert)) { updates.put(alert, Optional.empty()); } } } return updates; } protected  AbstractLuceneMetaAlertUpdateDao(
      UpdateDao updateDao,
      MetaAlertRetrieveLatestDao retrieveLatestDao,
      MetaAlertConfig config); UpdateDao getUpdateDao(); MetaAlertRetrieveLatestDao getRetrieveLatestDao(); MetaAlertConfig getConfig(); @Override Document patch(RetrieveLatestDao retrieveLatestDao, PatchRequest request,
      Optional<Long> timestamp); @Override Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates); @Override Document addAlertsToMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests); @Override @SuppressWarnings("unchecked") Document removeAlertsFromMetaAlert(String metaAlertGuid, List<GetRequest> alertRequests); @Override Document updateMetaAlertStatus(String metaAlertGuid, MetaAlertStatus status);  }
@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()); }
@Test public void testBuildAddAlertToMetaAlertUpdates() { List<Document> alerts = buildChildAlerts(1, METAALERT_GUID, null); Document metaDoc = buildMetaAlert(alerts); List<Document> newAlerts = buildChildAlerts(2, null, "new_"); Map<Document, Optional<String>> actual = dao .buildAddAlertToMetaAlertUpdates(metaDoc, newAlerts); assertEquals(3, actual.size()); HashMap<String, Object> expectedExistingAlert = new HashMap<>(); expectedExistingAlert.put(Constants.GUID, "child_0"); expectedExistingAlert.put(METAALERT_FIELD, Collections.singletonList(METAALERT_GUID)); expectedExistingAlert.put(THREAT_FIELD_DEFAULT, 0.0f); List<Map<String, Object>> expectedAlerts = new ArrayList<>(); expectedAlerts.add(expectedExistingAlert); expectedAlerts.addAll(getRawMaps(newAlerts)); List<Double> scores = new ArrayList<>(); scores.add(0.0d); scores.add(0.0d); scores.add(0.0d); Map<String, Object> expectedMetaAlertMap = new HashMap<>(); expectedMetaAlertMap.put(Constants.GUID, METAALERT_GUID); expectedMetaAlertMap.put(ALERT_FIELD, expectedAlerts); expectedMetaAlertMap.put(THREAT_FIELD_DEFAULT, 0.0f); expectedMetaAlertMap.putAll(new MetaScores(scores).getMetaScores()); Document expectedMetaAlertDoc = new Document(expectedMetaAlertMap, METAALERT_GUID, METAALERT_TYPE, 0L); Map<Document, Optional<String>> expected = new HashMap<>(); expected.put(expectedMetaAlertDoc, Optional.of(METAALERT_INDEX)); expected.put(newAlerts.get(0), Optional.empty()); expected.put(newAlerts.get(1), Optional.empty()); assertTrue(updatesMapEquals(expected, actual)); }