AbstractLuceneMetaAlertUpdateDao implements MetaAlertUpdateDao { protected Document buildCreateDocument(Iterable<Document> alerts, List<String> groups, String alertField) { Map<String, Object> metaSource = new HashMap<>(); List<Map<String, Object>> alertList = new ArrayList<>(); for (Document alert : alerts) { alertList.add(alert.getDocument()); } metaSource.put(alertField, alertList); String guid = UUID.randomUUID().toString(); metaSource.put(GUID, guid); metaSource.put(Constants.Fields.TIMESTAMP.getName(), System.currentTimeMillis()); metaSource.put(MetaAlertConstants.GROUPS_FIELD, groups); metaSource.put(MetaAlertConstants.STATUS_FIELD, MetaAlertStatus.ACTIVE.getStatusString()); return new Document(metaSource, guid, MetaAlertConstants.METAALERT_TYPE, System.currentTimeMillis()); } 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 testBuildCreateDocumentSingleAlert() { List<String> groups = new ArrayList<>(); groups.add("group_one"); groups.add("group_two"); Map<String, Object> alertOne = new HashMap<>(); alertOne.put(Constants.GUID, "alert_one"); alertOne.put(THREAT_FIELD_DEFAULT, 10.0d); List<Document> alerts = new ArrayList<Document>() {{ add(new Document(alertOne, "", "", 0L)); }}; Document actual = dao.buildCreateDocument(alerts, groups, ALERT_FIELD); ArrayList<Map<String, Object>> alertList = new ArrayList<>(); alertList.add(alertOne); Map<String, Object> actualDocument = actual.getDocument(); assertEquals( MetaAlertStatus.ACTIVE.getStatusString(), actualDocument.get(STATUS_FIELD) ); assertEquals( alertList, actualDocument.get(ALERT_FIELD) ); assertEquals( groups, actualDocument.get(GROUPS_FIELD) ); UUID.fromString((String) actualDocument.get(Constants.GUID)); }
@Test public void testBuildCreateDocumentMultipleAlerts() { List<String> groups = new ArrayList<>(); groups.add("group_one"); groups.add("group_two"); Map<String, Object> alertOne = new HashMap<>(); alertOne.put(Constants.GUID, "alert_one"); alertOne.put(THREAT_FIELD_DEFAULT, 10.0d); Map<String, Object> alertTwo = new HashMap<>(); alertTwo.put(Constants.GUID, "alert_one"); alertTwo.put(THREAT_FIELD_DEFAULT, 5.0d); List<Document> alerts = new ArrayList<>(); alerts.add(new Document(alertOne, "", "", 0L)); alerts.add(new Document(alertTwo, "", "", 0L)); Document actual = dao.buildCreateDocument(alerts, groups, ALERT_FIELD); ArrayList<Map<String, Object>> alertList = new ArrayList<>(); alertList.add(alertOne); alertList.add(alertTwo); Map<String, Object> actualDocument = actual.getDocument(); assertNotNull(actualDocument.get(Fields.TIMESTAMP.getName())); assertEquals( alertList, actualDocument.get(ALERT_FIELD) ); assertEquals( groups, actualDocument.get(GROUPS_FIELD) ); UUID.fromString((String) actualDocument.get(Constants.GUID)); }