use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestFilter method testErrorMessagesForArraysFastFail.
@Test
public void testErrorMessagesForArraysFastFail() throws JsonParseException, IOException, DataProcessingException {
DataMap data = dataMapFromString("{ 'a': [1, 2, 3, 4, 5]}".replace('\'', '"'));
DataMap filter = dataMapFromString("{ 'a': { '$*': { 'y': 1}}}".replace('\'', '"'));
DataComplexProcessor processor = new DataComplexProcessor(new Filter(), filter, data);
boolean thrown = false;
try {
processor.run(true);
} catch (DataProcessingException e) {
assertEquals(e.getMessages().size(), 1, "expected exactly 1 error in non fast fail mode");
thrown = true;
}
assertEquals(thrown, true, "exception should have been thrown");
}
use of com.linkedin.data.DataMap 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.DataMap 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.DataMap 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.DataMap 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");
}
Aggregations