Search in sources :

Example 1 with MaskOperation

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

the class TestResourceContextImpl method testOverrideMask.

@Test(dataProvider = "overrideMaskData")
public void testOverrideMask(ProjectionType projectionType, String stringUri, List<String> projectedFields) throws Exception {
    URI uri = URI.create(stringUri);
    ServerResourceContext resourceContext = new ResourceContextImpl(new PathKeysImpl(), new TestResourceContext.MockRequest(uri), new RequestContext());
    // Assert the current projections before we set the override mask
    MaskTree projectionMask = getProjectionMask(resourceContext, projectionType);
    if (projectedFields.isEmpty()) {
        Assert.assertNull(projectionMask);
    } else {
        Assert.assertNotNull(projectionMask);
        Map<PathSpec, MaskOperation> maskOperations = projectionMask.getOperations();
        Assert.assertNotNull(maskOperations);
        Assert.assertEquals(maskOperations.size(), projectedFields.size());
        for (String projectedField : projectedFields) {
            Assert.assertTrue(maskOperations.containsKey(new PathSpec(projectedField)));
            Assert.assertEquals(maskOperations.get(new PathSpec(projectedField)), MaskOperation.POSITIVE_MASK_OP);
        }
    }
    final DataMap overrideDataMap = new DataMap();
    overrideDataMap.put("state", 1);
    setProjectionMask(resourceContext, projectionType, new MaskTree(overrideDataMap));
    // Assert the projections after the projection mask is overridden
    projectionMask = getProjectionMask(resourceContext, projectionType);
    Assert.assertNotNull(projectionMask);
    Map<PathSpec, MaskOperation> maskOperations = projectionMask.getOperations();
    Assert.assertNotNull(maskOperations);
    Assert.assertEquals(maskOperations.size(), 1);
    Assert.assertTrue(maskOperations.containsKey(new PathSpec("state")));
    Assert.assertEquals(maskOperations.get(new PathSpec("state")), MaskOperation.POSITIVE_MASK_OP);
}
Also used : URI(java.net.URI) PathSpec(com.linkedin.data.schema.PathSpec) TestResourceContext(com.linkedin.restli.server.test.TestResourceContext) MaskOperation(com.linkedin.data.transform.filter.request.MaskOperation) DataMap(com.linkedin.data.DataMap) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Aggregations

DataMap (com.linkedin.data.DataMap)1 PathSpec (com.linkedin.data.schema.PathSpec)1 MaskOperation (com.linkedin.data.transform.filter.request.MaskOperation)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 RequestContext (com.linkedin.r2.message.RequestContext)1 TestResourceContext (com.linkedin.restli.server.test.TestResourceContext)1 URI (java.net.URI)1 Test (org.testng.annotations.Test)1