@Test public void shouldPatchMetaAlertFields() throws Exception { // Load alerts List<Map<String, Object>> alerts = buildAlerts(2); alerts.get(0).put(METAALERT_FIELD, Collections.singletonList("meta_active")); alerts.get(1).put(METAALERT_FIELD, Collections.singletonList("meta_active")); addRecords(alerts, getTestIndexFullName(), SENSOR_NAME); // Put the nested type into the test index, so that it'll match appropriately setupTypings(); // Load metaAlerts Map<String, Object> metaAlert = buildMetaAlert("meta_alert", MetaAlertStatus.ACTIVE, Optional.of(Arrays.asList(alerts.get(0), alerts.get(1)))); // We pass MetaAlertDao.METAALERT_TYPE, because the "_doc" gets appended automatically. addRecords(Collections.singletonList(metaAlert), getMetaAlertIndex(), METAALERT_TYPE); // ensure the test data was loaded findCreatedDocs(Arrays.asList( new GetRequest("message_0", SENSOR_NAME), new GetRequest("message_1", SENSOR_NAME), new GetRequest("meta_alert", METAALERT_TYPE))); // patch the name field String namePatch = namePatchRequest.replace(META_INDEX_FLAG, getMetaAlertIndex()); PatchRequest patchRequest = JSONUtils.INSTANCE.load(namePatch, PatchRequest.class); metaDao.patch(metaDao, patchRequest, Optional.of(System.currentTimeMillis())); // ensure the alert was patched assertEventually(() -> { Document updated = metaDao.getLatest("meta_alert", METAALERT_TYPE); Assert.assertEquals("New Meta Alert", updated.getDocument().get(NAME_FIELD)); }); }
@Test public void shouldThrowExceptionIfPatchStatusField() throws Exception { setupTypings();
@Test public void shouldThrowExceptionIfPatchAlertField() throws Exception { setupTypings();
@Test public void shouldSortMetaAlertsByAlertStatus() throws Exception { final String guid = "meta_alert"; setupTypings(); // should be able to sort meta-alert search results by 'alert_status' SortField sortField = new SortField(); sortField.setField("alert_status"); sortField.setSortOrder("asc"); // when no meta-alerts exist, it should work Assert.assertEquals(0, searchForSortedMetaAlerts(sortField).getTotal()); // when meta-alert just created, it should work createMetaAlert(guid); Assert.assertEquals(1, searchForSortedMetaAlerts(sortField).getTotal()); // when meta-alert 'esclated', it should work escalateMetaAlert(guid); Assert.assertEquals(1, searchForSortedMetaAlerts(sortField).getTotal()); }