@Test @SuppressWarnings("unchecked") public void testPatchAllowedName() throws ParseException { PatchRequest pr = new PatchRequest(); Map<String, Object> patch = (JSONObject) new JSONParser().parse(namePatchRequest); pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0))); assertTrue(dao.isPatchAllowed(pr)); }
@Test @SuppressWarnings("unchecked") public void testPatchNotAllowedAlert() throws ParseException { PatchRequest pr = new PatchRequest(); Map<String, Object> patch = (JSONObject) new JSONParser().parse(alertPatchRequest); pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0))); assertFalse(dao.isPatchAllowed(pr)); }
@Test @SuppressWarnings("unchecked") public void testPatchNotAllowedStatus() throws ParseException { PatchRequest pr = new PatchRequest(); Map<String, Object> patch = (JSONObject) new JSONParser().parse(statusPatchRequest); pr.setPatch(Collections.singletonList((JSONObject) ((JSONArray) patch.get("patch")).get(0))); assertFalse(dao.isPatchAllowed(pr)); }
private void escalateMetaAlert(String guid) throws Exception { // create the patch that 'escalates' the meta-alert Map<String, Object> patch = new HashMap<>(); patch.put("op", "add"); patch.put("path", "/alert_status"); patch.put("value", "escalate"); // 'escalate' the meta-alert PatchRequest patchRequest = new PatchRequest(); patchRequest.setGuid(guid); patchRequest.setIndex(getMetaAlertIndex()); patchRequest.setSensorType(METAALERT_TYPE); patchRequest.setPatch(Collections.singletonList(patch)); metaDao.patch(metaDao, patchRequest, Optional.of(System.currentTimeMillis())); // ensure the alert status was changed to 'escalate' assertEventually(() -> { Document updated = metaDao.getLatest(guid, METAALERT_TYPE); Assert.assertEquals("escalate", updated.getDocument().get("alert_status")); }); }
@Test public void testPatchDocumentThatHasComment() throws Exception { Document document = createAndIndexDocument("testPatchDocumentWithComment"); // comment on the document String commentText = "New Comment"; String commentUser = "test_user"; long commentTimestamp = 152630493050L; Document withComment = addAlertComment(document.getGuid(), commentText, commentUser, commentTimestamp); // create a patch List<Map<String, Object>> patches = new ArrayList<>(); Map<String, Object> patch = new HashMap<>(); patch.put("op", "add"); patch.put("path", "/project"); patch.put("value", "metron"); patches.add(patch); PatchRequest pr = new PatchRequest(); pr.setGuid(withComment.getGuid()); pr.setIndex(SENSOR_NAME); pr.setSensorType(SENSOR_NAME); pr.setPatch(patches); // patch the document that has been commented on Document patched = getDao().patch(getDao(), pr, Optional.of(withComment.getTimestamp())); Assert.assertEquals("metron", patched.getDocument().get("project")); // ensure the patch was made on the indexed document Document indexed = findUpdatedDoc(patched.getDocument(), patched.getGuid(), SENSOR_NAME); Assert.assertEquals("metron", indexed.getDocument().get("project")); }