Search in sources :

Example 46 with MaskTree

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

the class TestRestUtils method testOverrideMask.

@Test
public void testOverrideMask() throws CloneNotSupportedException {
    RecordBar bar = new RecordBar();
    bar.setLocation("mountain view");
    bar.data().put("SF", "CA");
    RecordBar expected = bar.clone();
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("SF"), MaskOperation.POSITIVE_MASK_OP);
    RestUtils.trimRecordTemplate(bar, maskTree, false);
    Assert.assertEquals(bar, expected);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) PathSpec(com.linkedin.data.schema.PathSpec) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 47 with MaskTree

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

the class TestGetResponseBuilder method dataProvider.

@DataProvider(name = "testData")
public Object[][] dataProvider() {
    DataMap projectionDataMap = new DataMap();
    projectionDataMap.put("stringField", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    MaskTree maskTree = new MaskTree(projectionDataMap);
    ProjectionMode manual = ProjectionMode.MANUAL;
    ProjectionMode auto = ProjectionMode.AUTOMATIC;
    return new Object[][] { // no projections with null projection masks and auto projection mode
    { getRecord(), HttpStatus.S_200_OK, null, auto }, { new GetResult<Foo>(getRecord(), HttpStatus.S_207_MULTI_STATUS), HttpStatus.S_207_MULTI_STATUS, null, auto }, // no projections with null projection masks and manual projection mode
    { getRecord(), HttpStatus.S_200_OK, null, manual }, { new GetResult<Foo>(getRecord(), HttpStatus.S_207_MULTI_STATUS), HttpStatus.S_207_MULTI_STATUS, null, manual }, // no projections with non-null projection masks and manual projection mode
    { getRecord(), HttpStatus.S_200_OK, maskTree, manual }, { new GetResult<Foo>(getRecord(), HttpStatus.S_207_MULTI_STATUS), HttpStatus.S_207_MULTI_STATUS, maskTree, manual }, // projections with non-null projection masks and auto projection mode
    { getRecord(), HttpStatus.S_200_OK, maskTree, auto }, { new GetResult<Foo>(getRecord(), HttpStatus.S_207_MULTI_STATUS), HttpStatus.S_207_MULTI_STATUS, maskTree, auto } };
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) ProjectionMode(com.linkedin.restli.server.ProjectionMode) Foo(com.linkedin.pegasus.generator.examples.Foo) DataMap(com.linkedin.data.DataMap) DataProvider(org.testng.annotations.DataProvider)

Example 48 with MaskTree

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

the class TestRestUtils method testOverrideMaskNestedWithMap.

@Test
public void testOverrideMaskNestedWithMap() throws CloneNotSupportedException {
    TyperefTest test = new TyperefTest();
    RecordBar bar = new RecordBar();
    bar.setLocation("foo");
    bar.data().put("bar", "keep me");
    RecordBar expected = bar.clone();
    test.setBarRefMap(new RecordBarMap());
    test.getBarRefMap().put("foo", bar);
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("barRefMap", PathSpec.WILDCARD, "location"), MaskOperation.POSITIVE_MASK_OP);
    maskTree.addOperation(new PathSpec("barRefMap", PathSpec.WILDCARD, "bar"), MaskOperation.POSITIVE_MASK_OP);
    RestUtils.trimRecordTemplate(test, maskTree, false);
    Assert.assertEquals(test.getBarRefMap().get("foo"), expected);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest) RecordBar(com.linkedin.pegasus.generator.test.RecordBar) PathSpec(com.linkedin.data.schema.PathSpec) RecordBarMap(com.linkedin.pegasus.generator.test.RecordBarMap) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Example 49 with MaskTree

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

the class TestRestUtils method testOverrideMaskNestedRecord.

@Test
public void testOverrideMaskNestedRecord() throws CloneNotSupportedException {
    LinkedListNode node1 = new LinkedListNode();
    node1.setIntField(1);
    LinkedListNode node2 = new LinkedListNode();
    node2.setIntField(2);
    node1.setNext(node2);
    node2.data().put("keep me", "foo");
    MaskTree maskTree = new MaskTree();
    maskTree.addOperation(new PathSpec("next", "keep me"), MaskOperation.POSITIVE_MASK_OP);
    maskTree.addOperation(new PathSpec("next", "intField"), MaskOperation.POSITIVE_MASK_OP);
    LinkedListNode expected = node2.clone();
    RestUtils.trimRecordTemplate(node1, maskTree, false);
    Assert.assertEquals(node1.getNext(), expected);
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) LinkedListNode(com.linkedin.restli.server.LinkedListNode) PathSpec(com.linkedin.data.schema.PathSpec) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

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