use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildUnstructuredDataRoutingResult.
private RoutingResult buildUnstructuredDataRoutingResult(RestRequest request) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
Method method = FeedDownloadResource.class.getMethod("get", Long.class, UnstructuredDataWriter.class);
ResourceModel model = RestLiTestHelper.buildResourceModel(FeedDownloadResource.class);
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(ResourceMethod.GET, method, InterfaceType.SYNC);
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResultFinder.
private RoutingResult buildRoutingResultFinder(RestRequest request, Map<String, String> acceptHeaders) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
Method method = ProjectionTestFixture.class.getMethod("find");
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(ResourceMethod.FINDER, method, InterfaceType.SYNC);
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, Collections.emptySet(), context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestRestLiResponseHandler method testBuildRestException.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
@SuppressWarnings("deprecation")
void testBuildRestException(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
final RoutingResult routingResult = buildRoutingResult(request, acceptTypeData.acceptHeaders);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
RestLiServiceException ex = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "freeway not found").setServiceErrorCode(237);
RestLiResponseData<?> responseData = _responseHandler.buildExceptionResponseData(routingResult, ex, requestHeaders, Collections.emptyList());
RestLiResponse response = _responseHandler.buildPartialResponse(routingResult, responseData);
checkResponse(response, 404, 2, // The response Content-Type should always be 'application/json'
true, true, errorResponseHeaderName);
DataMap dataMap = response.getDataMap();
assertEquals(dataMap.getInteger("status"), Integer.valueOf(404));
assertEquals(dataMap.getString("message"), "freeway not found");
assertEquals(dataMap.getInteger("serviceErrorCode"), Integer.valueOf(237));
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResult.
private RoutingResult buildRoutingResult(ResourceMethod resourceMethod, RestRequest request, Map<String, String> acceptHeaders, Set<String> customTypes) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
Method method = ProjectionTestFixture.class.getMethod("batchGet", Set.class);
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(resourceMethod, method, InterfaceType.SYNC);
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, customTypes, context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestCreateArgumentBuilder 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 CreateArgumentBuilder();
try {
argumentBuilder.extractRequestData(routingResult, request);
fail("Expected RoutingException");
} catch (RoutingException e) {
assertTrue(e.getMessage().contains("Error parsing entity body"));
}
verify(request, model, descriptor, routingResult);
}
Aggregations