Search in sources :

Example 16 with PathSpec

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

the class TestMaskCreation method testNegativeMaskNestedFields.

@Test
public void testNegativeMaskNestedFields() {
    MaskTree mask = MaskCreator.createNegativeMask(new PathSpec("foo", "bar"), new PathSpec("bar", "baz"), new PathSpec("qux"));
    // "{foo={bar=0}, bar={baz=0}, qux=0}"
    final DataMap fooBarQuxMap = new DataMap();
    fooBarQuxMap.put("qux", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
    final DataMap barMap = new DataMap();
    barMap.put("baz", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
    final DataMap fooMap = new DataMap();
    fooMap.put("bar", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
    fooBarQuxMap.put("foo", fooMap);
    fooBarQuxMap.put("bar", barMap);
    Assert.assertEquals(mask.getDataMap(), fooBarQuxMap, "The MaskTree DataMap should match");
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 17 with PathSpec

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

Example 18 with PathSpec

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

the class TestMaskCreation method testComposingNegativeSubmasks.

/**
 * When negative mask for a PathSpec is composed with another negative mask, which is sub-PathSpec, then
 * the result is a negative mask with PathSpec only for the parent, because negative mask means
 * "remove field and all it's children".
 */
@Test
public void testComposingNegativeSubmasks() {
    MaskTree mask = new MaskTree();
    mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.NEGATIVE_MASK_OP);
    mask.addOperation(new PathSpec("a", "b"), MaskOperation.NEGATIVE_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 19 with PathSpec

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

the class TestMaskCreation method testPositiveMaskWithFullArrayRangeValues.

@Test
public void testPositiveMaskWithFullArrayRangeValues() {
    PathSpec parentPath = new PathSpec("parent");
    // Build the array field's path with range (0 to 999)
    PathSpec arrayFirstHalfPath = new PathSpec(parentPath.getPathComponents(), "arrayField");
    arrayFirstHalfPath.setAttribute(PathSpec.ATTR_ARRAY_START, 0);
    arrayFirstHalfPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 1000);
    // Build the array field's path with range (1000 to Integer.MAX_INT)
    PathSpec arraySecondHalfPath = new PathSpec(parentPath.getPathComponents(), "arrayField");
    arraySecondHalfPath.setAttribute(PathSpec.ATTR_ARRAY_START, 1000);
    arraySecondHalfPath.setAttribute(PathSpec.ATTR_ARRAY_COUNT, Integer.MAX_VALUE);
    MaskTree mask = MaskCreator.createPositiveMask(arrayFirstHalfPath, arraySecondHalfPath);
    // Build the expected map with both start and count filtered out
    // {parent={arrayField={$*=1}}}
    DataMap parentMap = new DataMap();
    DataMap arrayFieldMap = new DataMap();
    arrayFieldMap.put(FilterConstants.WILDCARD, MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    parentMap.put("arrayField", arrayFieldMap);
    DataMap expectedMaskMap = new DataMap();
    expectedMaskMap.put("parent", parentMap);
    Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 20 with PathSpec

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

the class TestMaskCreation method testComposingPositiveSubmasks.

/**
 * When positive mask for a PathSpec is composed with another positive mask, which is sub-PathSpec, then
 * the result is a positive mask with PathSpec only for the parent, because positive mask means
 * "select field and all it's children".
 */
@Test
public void testComposingPositiveSubmasks() {
    MaskTree mask = new MaskTree();
    mask.addOperation(new PathSpec("a", "b", "c"), MaskOperation.POSITIVE_MASK_OP);
    mask.addOperation(new PathSpec("a", "b"), MaskOperation.POSITIVE_MASK_OP);
    mask.addOperation(new PathSpec("a"), MaskOperation.POSITIVE_MASK_OP);
    Assert.assertEquals(mask.toString(), "{a=1}");
}
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