use of org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch in project dhis2-core by dhis2.
the class AddOperationTest method testAddAppendArray.
@Test
void testAddAppendArray() throws JsonProcessingException, JsonPatchException {
JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"add\", \"path\": \"/arr/-\", \"value\": 1}," + "{\"op\": \"add\", \"path\": \"/arr/-\", \"value\": 2}," + "{\"op\": \"add\", \"path\": \"/arr/-\", \"value\": 3}" + "]", JsonPatch.class);
assertNotNull(patch);
ObjectNode root = jsonMapper.createObjectNode();
ArrayNode arrayNode = jsonMapper.createArrayNode();
root.set("arr", arrayNode);
root = (ObjectNode) patch.apply(root);
assertTrue(root.has("arr"));
assertEquals(3, arrayNode.size());
assertEquals(1, arrayNode.get(0).asInt());
assertEquals(2, arrayNode.get(1).asInt());
assertEquals(3, arrayNode.get(2).asInt());
}
use of org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch in project dhis2-core by dhis2.
the class AddOperationTest method testAddSimpleStringPropertyPath.
@Test
void testAddSimpleStringPropertyPath() throws JsonProcessingException, JsonPatchException {
JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"add\", \"path\": \"/aaa\", \"value\": \"bbb\"}" + "]", JsonPatch.class);
assertNotNull(patch);
JsonNode root = jsonMapper.createObjectNode();
root = patch.apply(root);
assertTrue(root.has("aaa"));
assertEquals("bbb", root.get("aaa").asText());
}
use of org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch in project dhis2-core by dhis2.
the class AddOperationTest method testAddSimpleNumberPropertyPath.
@Test
void testAddSimpleNumberPropertyPath() throws JsonProcessingException, JsonPatchException {
JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"add\", \"path\": \"/aaa\", \"value\": 2}" + "]", JsonPatch.class);
assertNotNull(patch);
JsonNode root = jsonMapper.createObjectNode();
root = patch.apply(root);
assertTrue(root.has("aaa"));
assertEquals(2, root.get("aaa").asInt());
}
use of org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch in project dhis2-core by dhis2.
the class AddOperationTest method testAddModifyArray.
@Test
void testAddModifyArray() throws JsonProcessingException, JsonPatchException {
JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"add\", \"path\": \"/arr/0\", \"value\": 1}" + "]", JsonPatch.class);
assertNotNull(patch);
ObjectNode root = jsonMapper.createObjectNode();
root.set("arr", jsonMapper.createArrayNode());
root = (ObjectNode) patch.apply(root);
JsonNode arrayNode = root.get("arr");
assertNotNull(arrayNode);
assertEquals(1, arrayNode.get(0).asInt());
}
use of org.hisp.dhis.commons.jackson.jsonpatch.JsonPatch in project dhis2-core by dhis2.
the class JsonPatchManagerTest method testAddAndReplaceSharingUser.
@Test
void testAddAndReplaceSharingUser() throws JsonProcessingException, JsonPatchException {
User userA = createUser('A');
manager.save(userA);
DataElement dataElementA = createDataElement('A');
manager.save(dataElementA);
assertEquals(0, dataElementA.getSharing().getUsers().size());
JsonPatch patch = jsonMapper.readValue("[" + "{\"op\": \"add\", \"path\": \"/sharing/users\", \"value\": " + "{" + "\"" + userA.getUid() + "\": { \"access\":\"rw------\",\"id\": \"" + userA.getUid() + "\" }" + "}" + "}" + "]", JsonPatch.class);
assertNotNull(patch);
DataElement patchedDE = jsonPatchManager.apply(patch, dataElementA);
assertEquals(1, patchedDE.getSharing().getUsers().size());
assertEquals("rw------", patchedDE.getSharing().getUsers().get(userA.getUid()).getAccess());
JsonPatch replacedPatch = jsonMapper.readValue("[" + "{\"op\": \"replace\", \"path\": \"/sharing/users\", \"value\": " + "{" + "\"" + userA.getUid() + "\": { \"access\":\"r-------\",\"id\": \"" + userA.getUid() + "\" }" + "}" + "}" + "]", JsonPatch.class);
DataElement replacePatchedDE = jsonPatchManager.apply(replacedPatch, patchedDE);
assertEquals(1, replacePatchedDE.getSharing().getUsers().size());
assertEquals("r-------", replacePatchedDE.getSharing().getUsers().get(userA.getUid()).getAccess());
}
Aggregations