use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestRestLiRouting method testActionNestedSimpleRouting.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "actionNestedSimpleRouting")
public void testActionNestedSimpleRouting(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request = createRequest(uri, "POST", version);
RoutingResult result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
assertEquals(result.getResourceMethod().getActionName(), "new_status_from_location");
assertEquals(result.getResourceMethod().getType(), ResourceMethod.ACTION);
assertEquals(result.getResourceMethod().getMethod().getParameterTypes(), new Class<?>[] { String.class });
assertEquals(result.getContext().getPathKeys().get("statusID"), Long.valueOf(1));
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestRestLiRouting method checkBatchKeys.
private void checkBatchKeys(String uri, ProtocolVersion version, String httpMethod, Set<?> expectedBatchKeys) throws URISyntaxException {
RestRequest request = createRequest(uri, httpMethod, version);
RoutingResult result = _router.process(request, new RequestContext(), null);
Set<?> batchKeys = result.getContext().getPathKeys().getBatchIds();
assertEquals(batchKeys, expectedBatchKeys);
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsCollectionGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsCollectionEntity")
public void testRoutingDetailsCollectionGet(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap);
// #1 simple GET
RestRequest request = createRequest(uri, "GET", version);
RoutingResult result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
ResourceMethodDescriptor resourceMethodDescriptor = result.getResourceMethod();
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.GET);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), StatusCollectionResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "get");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Long.class });
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "statuses");
assertNotNull(result.getContext());
PathKeys keys = result.getContext().getPathKeys();
assertEquals(keys.getAsLong("statusID"), new Long(1));
assertNull(keys.getAsString("foo"));
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResult.
private final RoutingResult buildRoutingResult(ResourceMethod resourceMethod, RestRequest request, Map<String, String> acceptHeaders) 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, context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.r2.message.Request in project rest.li by linkedin.
the class TestRestLiResponseHandler method invokeResponseHandler.
private RestResponse invokeResponseHandler(String uri, ResourceMethodDescriptor methodDescriptor, Object result, Map<String, String> headers, ProtocolVersion protocolVersion) throws IOException, URISyntaxException, RestLiSyntaxException {
RestRequest request = buildRequest(uri, headers, protocolVersion);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, context);
RoutingResult routingResult = new RoutingResult(context, methodDescriptor);
RestResponse response;
response = _responseHandler.buildResponse(request, routingResult, result);
return response;
}
Aggregations