use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestArgumentBuilder method testProjectionParamType.
@Test(dataProvider = "projectionParameterData")
@SuppressWarnings("deprecation")
public void testProjectionParamType(Parameter.ParamType paramType) {
String testParamKey = "testParam";
ServerResourceContext mockResourceContext = EasyMock.createMock(ServerResourceContext.class);
MaskTree mockMask = EasyMock.createMock(MaskTree.class);
if (paramType == Parameter.ParamType.PROJECTION_PARAM || paramType == Parameter.ParamType.PROJECTION) {
EasyMock.expect(mockResourceContext.getProjectionMask()).andReturn(mockMask);
} else if (paramType == Parameter.ParamType.METADATA_PROJECTION_PARAM) {
EasyMock.expect(mockResourceContext.getMetadataProjectionMask()).andReturn(mockMask);
} else {
EasyMock.expect(mockResourceContext.getPagingProjectionMask()).andReturn(mockMask);
}
EasyMock.expect(mockResourceContext.getRequestAttachmentReader()).andReturn(null);
EasyMock.replay(mockResourceContext);
Parameter<MaskTree> param = new Parameter<MaskTree>(testParamKey, MaskTree.class, null, false, null, paramType, false, AnnotationSet.EMPTY);
List<Parameter<?>> parameters = Collections.<Parameter<?>>singletonList(param);
Object[] results = ArgumentBuilder.buildArgs(new Object[0], getMockResourceMethod(parameters), mockResourceContext, null);
Assert.assertEquals(results[0], mockMask);
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestCollectionResponseBuilder method testProjectionInBuildRestliResponseData.
@Test
public void testProjectionInBuildRestliResponseData() throws URISyntaxException {
for (ResourceMethod resourceMethod : Arrays.asList(ResourceMethod.GET_ALL, ResourceMethod.FINDER)) {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ResourceContext mockContext = getMockResourceContext(maskTree, null, null, ProjectionMode.AUTOMATIC, ProjectionMode.AUTOMATIC);
RoutingResult routingResult = new RoutingResult(mockContext, getMockResourceMethodDescriptor(resourceMethod));
List<RecordTemplate> values = new ArrayList<RecordTemplate>();
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
values.add(value);
CollectionResponseBuilder responseBuilder = new CollectionResponseBuilder();
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, values, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
RecordTemplate record = responseData.getCollectionResponseEnvelope().getCollectionResponse().get(0);
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
}
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestCreateResponseBuilder method testProjectionInBuildRestliResponseData.
@Test
public void testProjectionInBuildRestliResponseData() throws URISyntaxException {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
EasyMock.replay(mockContext);
RoutingResult routingResult = new RoutingResult(mockContext, null);
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
CreateKVResponse<Integer, Foo> values = new CreateKVResponse<Integer, Foo>(null, value);
CreateResponseBuilder responseBuilder = new CreateResponseBuilder();
RestLiResponseData envelope = responseBuilder.buildRestLiResponseData(new RestRequestBuilder(new URI("/foo")).build(), routingResult, values, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
RecordTemplate record = envelope.getRecordResponseEnvelope().getRecord();
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
Assert.assertTrue(envelope.getCreateResponseEnvelope().isGetAfterCreate());
EasyMock.verify(mockContext);
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestGetResponseBuilder method testProjectionInBuildRestliResponseData.
@Test
public void testProjectionInBuildRestliResponseData() {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ResourceContext mockContext = getMockResourceContext(maskTree, ProjectionMode.AUTOMATIC);
RoutingResult routingResult = new RoutingResult(mockContext, getMockResourceMethodDescriptor());
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
GetResponseBuilder responseBuilder = new GetResponseBuilder();
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(null, routingResult, value, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
RecordTemplate record = responseData.getGetResponseEnvelope().getRecord();
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
EasyMock.verify(mockContext);
}
use of com.linkedin.data.transform.filter.request.MaskTree in project rest.li by linkedin.
the class TestMaskCreation method testMixedMask.
@Test
public void testMixedMask() {
MaskTree mask = new MaskTree();
mask.addOperation(new PathSpec("foo", "bar"), MaskOperation.POSITIVE_MASK_OP);
mask.addOperation(new PathSpec("baz", "qux"), MaskOperation.NEGATIVE_MASK_OP);
//"{baz={qux=0}, foo={bar=1}}"
final DataMap bazFooMap = new DataMap();
final DataMap bazMap = new DataMap();
final DataMap fooMap = new DataMap();
bazMap.put("qux", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
fooMap.put("bar", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
bazFooMap.put("baz", bazMap);
bazFooMap.put("foo", fooMap);
Assert.assertEquals(mask.getDataMap(), bazFooMap, "The MaskTree DataMap should match");
}
Aggregations