Search in sources :

Example 1 with MaskTree

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")));
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 2 with MaskTree

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));
    }
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with MaskTree

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")));
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 4 with MaskTree

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));
    }
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 5 with MaskTree

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);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Aggregations

MaskTree (com.linkedin.data.transform.filter.request.MaskTree)49 Test (org.testng.annotations.Test)40 PathSpec (com.linkedin.data.schema.PathSpec)31 DataMap (com.linkedin.data.DataMap)23 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)9 Foo (com.linkedin.pegasus.generator.examples.Foo)8 HashMap (java.util.HashMap)8 ResourceContext (com.linkedin.restli.server.ResourceContext)7 URI (java.net.URI)7 RequestContext (com.linkedin.r2.message.RequestContext)6 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)6 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)6 PathKeysImpl (com.linkedin.restli.internal.server.PathKeysImpl)5 ByteString (com.linkedin.data.ByteString)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)4 ProjectionMode (com.linkedin.restli.server.ProjectionMode)4 HashSet (java.util.HashSet)4 TyperefTest (com.linkedin.pegasus.generator.test.TyperefTest)3 UnionTest (com.linkedin.pegasus.generator.test.UnionTest)3