use of com.linkedin.data.transform.filter.request.MaskTree 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.transform.filter.request.MaskTree 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<PathSpec>(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<PathSpec>(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<PathSpec>(positivePaths));
Assert.assertEquals(positiveResult, positivePaths);
// test false negative
final Set<PathSpec> negativeResult = ProjectionUtil.getPresentPaths(filter, new HashSet<PathSpec>(negativePaths));
Assert.assertTrue(negativeResult.isEmpty());
final Set<PathSpec> combinedPaths = new HashSet<PathSpec>(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<PathSpec>(positivePaths));
for (PathSpec p : negativePaths) {
Assert.assertFalse(combinedResult.contains(p));
}
}
use of com.linkedin.data.transform.filter.request.MaskTree 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.transform.filter.request.MaskTree 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<PathSpec>(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<PathSpec>(Arrays.asList(new PathSpec("foo", "bar", "xyz")));
final Set<PathSpec> positiveResult = ProjectionUtil.getPresentPaths(filter, new HashSet<PathSpec>(positivePaths));
Assert.assertEquals(positiveResult, positivePaths);
final Set<PathSpec> negativeResult = ProjectionUtil.getPresentPaths(filter, new HashSet<PathSpec>(negativePaths));
Assert.assertTrue(negativeResult.isEmpty());
final Set<PathSpec> combinedPaths = new HashSet<PathSpec>(positivePaths);
combinedPaths.addAll(negativePaths);
final Set<PathSpec> combinedResult = ProjectionUtil.getPresentPaths(filter, combinedPaths);
Assert.assertEquals(combinedResult, new HashSet<PathSpec>(positivePaths));
for (PathSpec p : negativePaths) {
Assert.assertFalse(combinedResult.contains(p));
}
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestMaskCreation method testMaskWithWildcard.
@Test
public void testMaskWithWildcard() {
MaskTree mask = new MaskTree();
PathSpec wildcardSpec = new PathSpec("foo", PathSpec.WILDCARD, "bar");
PathSpec asterixSpec = new PathSpec("foo", "*", "bar");
Assert.assertFalse(wildcardSpec.equals(asterixSpec));
mask.addOperation(wildcardSpec, MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.toString(), "{foo={$*={bar=1}}}");
Assert.assertEquals(mask.getOperations().get(wildcardSpec), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(asterixSpec), null);
mask = new MaskTree();
mask.addOperation(asterixSpec, MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.toString(), "{foo={*={bar=1}}}");
Assert.assertEquals(mask.getOperations().get(asterixSpec), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(wildcardSpec), null);
mask = new MaskTree();
mask.addOperation(asterixSpec, MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(wildcardSpec, MaskOperation.NEGATIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(wildcardSpec), MaskOperation.NEGATIVE_MASK_OP);
Assert.assertEquals(mask.getOperations().get(asterixSpec), MaskOperation.POSITIVE_MASK_OP);
}
Aggregations