use of com.linkedin.data.template.RecordTemplate in project rest.li by linkedin.
the class TestBatchGetResponseBuilder method testProjectionInBuildRestliResponseData.
@Test
public void testProjectionInBuildRestliResponseData() {
MaskTree maskTree = new MaskTree();
maskTree.addOperation(new PathSpec("fruitsField"), MaskOperation.POSITIVE_MASK_OP);
ServerResourceContext mockContext = EasyMock.createMock(ServerResourceContext.class);
EasyMock.expect(mockContext.hasParameter(RestConstants.ALT_KEY_PARAM)).andReturn(false);
EasyMock.expect(mockContext.getProjectionMode()).andReturn(ProjectionMode.AUTOMATIC);
EasyMock.expect(mockContext.getProjectionMask()).andReturn(maskTree);
EasyMock.expect(mockContext.getBatchKeyErrors()).andReturn(Collections.<Object, RestLiServiceException>emptyMap()).once();
EasyMock.replay(mockContext);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(null);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
Map<Integer, Foo> results = new HashMap<Integer, Foo>();
Foo value = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
results.put(1, value);
BatchGetResponseBuilder responseBuilder = new BatchGetResponseBuilder(new ErrorResponseBuilder());
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(null, routingResult, results, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList());
RecordTemplate record = responseData.getBatchResponseEnvelope().getBatchResponseMap().get(1).getRecord();
Assert.assertEquals(record.data().size(), 1);
Assert.assertEquals(record.data().get("fruitsField"), Fruits.APPLE.toString());
EasyMock.verify(mockContext);
}
use of com.linkedin.data.template.RecordTemplate 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.template.RecordTemplate 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.template.RecordTemplate 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.template.RecordTemplate in project rest.li by linkedin.
the class TestPartialRestResponse method testEntity.
@Test
public void testEntity() {
DataMap data = new DataMap();
RecordTemplate record = new Foo(data);
PartialRestResponse response = new PartialRestResponse.Builder().entity(record).build();
assertEquals(response.getEntity(), record);
assertTrue(response.hasData());
assertEquals(response.getDataMap(), data);
}
Aggregations