use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestProjectionUtil method testPositiveWithWildcardMultiPaths.
@Test
public void testPositiveWithWildcardMultiPaths() {
final MaskTree filter = new MaskTree();
filter.addOperation(new PathSpec("foo", PathSpec.WILDCARD, "baz"), MaskOperation.POSITIVE_MASK_OP);
final Collection<PathSpec> positivePaths = new HashSet<>(Arrays.asList(new PathSpec("foo"), new PathSpec("foo", "bar"), new PathSpec("foo", "bar", "baz"), new PathSpec("foo", "bar", "baz", "xyz"), new PathSpec("foo", "bar", "baz", "abc", "xyz")));
final Collection<PathSpec> negativePaths = new HashSet<>(Arrays.asList(new PathSpec("foo", "bar", "xyz")));
final Set<PathSpec> positiveResult = ProjectionUtil.getPresentPaths(filter, new HashSet<>(positivePaths));
Assert.assertEquals(positiveResult, positivePaths);
final Set<PathSpec> negativeResult = ProjectionUtil.getPresentPaths(filter, new HashSet<>(negativePaths));
Assert.assertTrue(negativeResult.isEmpty());
final Set<PathSpec> combinedPaths = new HashSet<>(positivePaths);
combinedPaths.addAll(negativePaths);
final Set<PathSpec> combinedResult = ProjectionUtil.getPresentPaths(filter, combinedPaths);
Assert.assertEquals(combinedResult, new HashSet<>(positivePaths));
for (PathSpec p : negativePaths) {
Assert.assertFalse(combinedResult.contains(p));
}
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestProjectionUtil method testPositiveMultiPaths.
@Test
public void testPositiveMultiPaths() {
final MaskTree filter = new MaskTree();
filter.addOperation(new PathSpec("foo", "bar", "baz"), MaskOperation.POSITIVE_MASK_OP);
final Collection<PathSpec> positivePaths = new HashSet<>(Arrays.asList(new PathSpec("foo"), new PathSpec("foo", "bar"), new PathSpec("foo", "bar", "baz"), new PathSpec("foo", "bar", "baz", "xyz"), new PathSpec("foo", "bar", "baz", "abc", "xyz")));
final Collection<PathSpec> negativePaths = new HashSet<>(Arrays.asList(new PathSpec("xyz"), new PathSpec("foo", "baz"), new PathSpec("foo", "xyz"), new PathSpec("foo", "bar", "xyz")));
// test false positive
final Set<PathSpec> positiveResult = ProjectionUtil.getPresentPaths(filter, new HashSet<>(positivePaths));
Assert.assertEquals(positiveResult, positivePaths);
// test false negative
final Set<PathSpec> negativeResult = ProjectionUtil.getPresentPaths(filter, new HashSet<>(negativePaths));
Assert.assertTrue(negativeResult.isEmpty());
final Set<PathSpec> combinedPaths = new HashSet<>(positivePaths);
combinedPaths.addAll(negativePaths);
// combine both to test internal ordering, overwrites, etc.
final Set<PathSpec> combinedResult = ProjectionUtil.getPresentPaths(filter, combinedPaths);
Assert.assertEquals(combinedResult, new HashSet<>(positivePaths));
for (PathSpec p : negativePaths) {
Assert.assertFalse(combinedResult.contains(p));
}
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestProjectionUtil method testPositiveWithWildcardSinglePath.
@Test
public void testPositiveWithWildcardSinglePath() {
final MaskTree filter = new MaskTree();
filter.addOperation(new PathSpec("foo", PathSpec.WILDCARD, "baz"), MaskOperation.POSITIVE_MASK_OP);
Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo")));
Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar")));
Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "baz")));
Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "baz", "xyz")));
Assert.assertTrue(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "baz", "abc", "xyz")));
Assert.assertFalse(ProjectionUtil.isPathPresent(filter, new PathSpec("foo", "bar", "xyz")));
}
use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.
the class TestProjectionUtil method testEmptyFilter.
@Test
public void testEmptyFilter() {
final MaskTree filter = new MaskTree();
Assert.assertFalse(ProjectionUtil.isPathPresent(filter, new PathSpec("foo")));
}
use of com.linkedin.data.schema.PathSpec 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");
}
Aggregations