use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchCreation method testDiffPatchCreationMixed.
@Test
public void testDiffPatchCreationMixed() throws Exception {
DataMap map = new DataMap(asMap("qux", 42, "bar", new DataMap(asMap("baz", "The quick brown fox"))));
DataMap map2 = map.copy();
map2.remove("foo");
((DataMap) map2.get("bar")).remove("baz");
map2.put("foo", 42);
map2.remove("qux");
PatchTree patch = new PatchTree();
patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
//"{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}"
final DataMap fooMap = new DataMap();
fooMap.put("foo", 42);
final DataMap deleteMap = new DataMap();
deleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("baz")));
final DataMap setBarDeleteMap = new DataMap();
setBarDeleteMap.put(PatchConstants.SET_COMMAND, fooMap);
setBarDeleteMap.put("bar", deleteMap);
setBarDeleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("qux")));
assertEquals(patch.getDataMap(), setBarDeleteMap, "PatchTree DataMap must be correct");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchCreation method testDiffPatchCreationRemove.
@Test
public void testDiffPatchCreationRemove() throws Exception {
DataMap map = new DataMap(asMap("foo", 42, "bar", new DataMap(asMap("baz", "The quick brown fox"))));
DataMap map2 = map.copy();
map2.remove("foo");
((DataMap) map2.get("bar")).remove("baz");
PatchTree patch = PatchCreator.diff(map, map2);
Assert.assertEquals(patch.toString(), "{bar={$delete=[baz]}, $delete=[foo]}");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchCreation method testDiffPatchCreationSet.
@Test
public void testDiffPatchCreationSet() throws Exception {
DataMap map = new DataMap();
DataMap map2 = map.copy();
map2.put("foo", 42);
map2.put("bar", new DataMap());
((DataMap) map2.get("bar")).put("baz", "The quick brown fox");
PatchTree patch = PatchCreator.diff(map, map2);
//"{$set={foo=42, bar={baz=The quick brown fox}}}"
final DataMap bazMap = new DataMap();
bazMap.put("baz", "The quick brown fox");
final DataMap fooBarMap = new DataMap();
fooBarMap.put("foo", 42);
fooBarMap.put("bar", bazMap);
final DataMap setMap = new DataMap();
setMap.put(PatchConstants.SET_COMMAND, fooBarMap);
assertEquals(patch.getDataMap(), setMap, "PatchTree DataMap must be correct");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchCreation method testExplicitPatchCreationMixed.
@Test
public void testExplicitPatchCreationMixed() {
PatchTree patch = new PatchTree();
patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
patch.addOperation(new PathSpec("qux"), PatchOpFactory.REMOVE_FIELD_OP);
//"{$set={foo=42}, bar={$delete=[baz]}, $delete=[qux]}"
final DataMap fooMap = new DataMap();
fooMap.put("foo", 42);
final DataMap deleteMap = new DataMap();
deleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("baz")));
final DataMap setBarDeleteMap = new DataMap();
setBarDeleteMap.put(PatchConstants.SET_COMMAND, fooMap);
setBarDeleteMap.put("bar", deleteMap);
setBarDeleteMap.put(PatchConstants.DELETE_COMMAND, new DataList(Arrays.asList("qux")));
assertEquals(patch.getDataMap(), setBarDeleteMap, "PatchTree DataMap must be correct");
}
use of com.linkedin.data.transform.patch.request.PatchTree in project rest.li by linkedin.
the class TestPatchTreeRecorder method testSimpleSetRemoveIfNullSetMode.
@Test
public void testSimpleSetRemoveIfNullSetMode() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
PatchTreeTestModel testModel = pc.getRecordingProxy();
testModel.setFooOptional(null, SetMode.REMOVE_IF_NULL);
// Augment the patch request with the removes
PatchTree ptExpect = new PatchTree();
ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());
Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
}
Aggregations