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);
}
Aggregations