Search in sources :

Example 11 with PathSpec

use of com.linkedin.data.schema.PathSpec 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");
}
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)

Example 12 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestMaskCreation method testComposingNegativeMaskWithPositiveSubmasks.

/**
 * When negative mask for a PathSpec is composed with positive mask, which is sub-PathSpec, then
 * the result is a negative mask with PathSpec only for the parent, because negative mask has a
 * higher priority then a positive mask.
 * @throws IOException
 */
@Test
public void testComposingNegativeMaskWithPositiveSubmasks() throws IOException {
    MaskTree mask = new MaskTree();
    mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.POSITIVE_MASK_OP);
    mask.addOperation(new PathSpec("a"), MaskOperation.NEGATIVE_MASK_OP);
    Assert.assertEquals(mask.toString(), "{a=0}");
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 13 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestMaskCreation method testPositiveMaskWithArrayWildcardAndRange.

@Test
public void testPositiveMaskWithArrayWildcardAndRange() {
    PathSpec parentPath = new PathSpec("parent");
    PathSpec childPath = new PathSpec(parentPath.getPathComponents(), "child");
    childPath.setAttribute(PathSpec.ATTR_ARRAY_START, 10);
    childPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
    PathSpec grandChildrenPath = new PathSpec(childPath.getPathComponents(), PathSpec.WILDCARD);
    PathSpec specificGrandChildPath = new PathSpec(childPath.getPathComponents(), "TheKid");
    // The pathspec 'specificGrandChildPath' should show up in the mask as we have the wildcard specified for grand children
    MaskTree mask = MaskCreator.createPositiveMask(childPath, grandChildrenPath, specificGrandChildPath);
    // {parent={child={$*=1, $start=10, $count=5}}}
    DataMap childMap = new DataMap();
    childMap.put(FilterConstants.START, 10);
    childMap.put(FilterConstants.COUNT, 5);
    childMap.put(FilterConstants.WILDCARD, MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    DataMap parentMap = new DataMap();
    parentMap.put("child", childMap);
    DataMap expectedMaskMap = new DataMap();
    expectedMaskMap.put("parent", parentMap);
    Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
    Map<PathSpec, MaskOperation> operations = mask.getOperations();
    Assert.assertEquals(operations.size(), 2);
    Assert.assertEquals(operations.get(childPath), MaskOperation.POSITIVE_MASK_OP);
    Assert.assertEquals(operations.get(grandChildrenPath), MaskOperation.POSITIVE_MASK_OP);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) MaskOperation(com.linkedin.data.transform.filter.request.MaskOperation) Test(org.testng.annotations.Test)

Example 14 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestMaskCreation method testPositiveMaskWithRandomAttributes.

@Test
public void testPositiveMaskWithRandomAttributes() {
    PathSpec parentPath = new PathSpec("parent");
    PathSpec childPath = new PathSpec(parentPath.getPathComponents(), "child");
    // This shouldn't be in the generated MaskTree
    childPath.setAttribute("random", 10);
    childPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
    MaskTree mask = MaskCreator.createPositiveMask(childPath);
    // {parent={child={$count=5}}}
    DataMap childMap = new DataMap();
    childMap.put(FilterConstants.COUNT, 5);
    DataMap parentMap = new DataMap();
    parentMap.put("child", childMap);
    DataMap expectedMaskMap = new DataMap();
    expectedMaskMap.put("parent", parentMap);
    Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
    // Create a copy of the childPath without the random attribute as the generated mask won't include those attributes
    PathSpec childPathCopy = new PathSpec(childPath.getPathComponents().toArray(new String[0]));
    childPathCopy.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
    Map<PathSpec, MaskOperation> operations = mask.getOperations();
    Assert.assertEquals(operations.size(), 1);
    Assert.assertEquals(operations.get(childPathCopy), MaskOperation.POSITIVE_MASK_OP);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) TestUtil.dataMapFromString(com.linkedin.data.TestUtil.dataMapFromString) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) MaskOperation(com.linkedin.data.transform.filter.request.MaskOperation) Test(org.testng.annotations.Test)

Example 15 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestMaskCreation method testNegativeMaskSingleField.

@Test
public void testNegativeMaskSingleField() {
    MaskTree mask = MaskCreator.createNegativeMask(new PathSpec("foo"));
    Assert.assertEquals(mask.toString(), "{foo=0}");
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) 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