use of com.linkedin.restli.internal.server.RoutingResult 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.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestGetResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
public void testBuilder(Object record, HttpStatus expectedHttpStatus, MaskTree maskTree, ProjectionMode projectionMode) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceContext mockContext = getMockResourceContext(maskTree, projectionMode);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
GetResponseBuilder getResponseBuilder = new GetResponseBuilder();
RestLiResponseData responseData = getResponseBuilder.buildRestLiResponseData(null, routingResult, record, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse partialRestResponse = getResponseBuilder.buildResponse(null, responseData);
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(partialRestResponse, headers);
Assert.assertEquals(partialRestResponse.getStatus(), expectedHttpStatus);
if (maskTree == null || projectionMode == ProjectionMode.MANUAL) {
Assert.assertEquals(partialRestResponse.getEntity(), getRecord());
} else {
Assert.assertEquals(partialRestResponse.getEntity(), getProjectedRecord());
}
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestUpdateArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(List<Parameter<?>> params, Key key, String keyName, Object keyValue) {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"a\":\"xyz\",\"b\":123}", 1);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, key, true);
ResourceMethodDescriptor descriptor;
if (key != null) {
descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 3, params);
} else {
descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, params);
}
ResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(keyName, keyValue, null, true);
RoutingResult routingResult;
if (key != null) {
routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 4, context, 2);
} else {
routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 3, context, 1);
}
RestLiArgumentBuilder argumentBuilder = new UpdateArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, request);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
if (keyValue != null) {
assertEquals(args.length, 2);
assertEquals(args[0], keyValue);
}
assertTrue(args[args.length - 1] instanceof MyComplexKey);
assertEquals(((MyComplexKey) args[args.length - 1]).getA(), "xyz");
assertEquals((long) ((MyComplexKey) args[args.length - 1]).getB(), 123L);
verify(request, model, descriptor, context, routingResult);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestUpdateArgumentBuilder method testFailure.
@Test(dataProvider = "failureEntityData", dataProviderClass = RestLiArgumentBuilderTestHelper.class)
public void testFailure(String entity) {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity, 1);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, null);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, null, 0);
RestLiArgumentBuilder argumentBuilder = new UpdateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains("Error parsing entity body"));
}
verify(request, model, descriptor, routingResult);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestActionResponseBuilder method testBuilder.
@Test(dataProvider = "testData")
public void testBuilder(Object result, HttpStatus httpStatus, long returnValue) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
RoutingResult routingResult = new RoutingResult(null, mockDescriptor);
ActionResponseBuilder actionResponseBuilder = new ActionResponseBuilder();
RestLiResponseData responseData = actionResponseBuilder.buildRestLiResponseData(null, routingResult, result, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = actionResponseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
Assert.assertEquals(restResponse.getStatus(), httpStatus);
Assert.assertEquals((restResponse.getEntity()), getActionResponse(returnValue));
}
Aggregations