Search in sources :

Example 6 with MaskTree

use of com.linkedin.data.transform.filter.request.MaskTree 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)

Example 7 with MaskTree

use of com.linkedin.data.transform.filter.request.MaskTree 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 8 with MaskTree

use of com.linkedin.data.transform.filter.request.MaskTree 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)

Example 9 with MaskTree

use of com.linkedin.data.transform.filter.request.MaskTree 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 10 with MaskTree

use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.

the class TestMaskCreation method testPositiveMaskMultipleFields.

@Test
public void testPositiveMaskMultipleFields() {
    MaskTree mask = MaskCreator.createPositiveMask(new PathSpec("foo"), new PathSpec("bar"));
    //"{foo=1, bar=1}"
    final DataMap fooBarMap = new DataMap();
    fooBarMap.put("foo", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    fooBarMap.put("bar", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    Assert.assertEquals(mask.getDataMap(), fooBarMap, "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)

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