Search in sources :

Example 6 with PathSpec

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));
    }
}
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 7 with PathSpec

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));
    }
}
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 8 with PathSpec

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

Example 9 with PathSpec

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

Example 10 with PathSpec

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

Aggregations

PathSpec (com.linkedin.data.schema.PathSpec)101 Test (org.testng.annotations.Test)74 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)40 DataMap (com.linkedin.data.DataMap)31 HashSet (java.util.HashSet)16 RecordTemplate (com.linkedin.data.template.RecordTemplate)11 Map (java.util.Map)10 Set (java.util.Set)10 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 HashMap (java.util.HashMap)8 DataList (com.linkedin.data.DataList)7 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)7 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)7 List (java.util.List)7 ByteString (com.linkedin.data.ByteString)6 DataSchema (com.linkedin.data.schema.DataSchema)5 MaskOperation (com.linkedin.data.transform.filter.request.MaskOperation)5 Foo (com.linkedin.pegasus.generator.examples.Foo)5 RequestContext (com.linkedin.r2.message.RequestContext)5 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)5