use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResultFinder.
private final 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, context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class TestRestLiResponseHandler method testFieldProjection_batch.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicDataWithBatchUri")
public void testFieldProjection_batch(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String uri, String errorResponseHeaderName) throws Exception {
RestResponse response;
Map<Integer, Status> statusBatch = buildStatusBatchResponse(10, "f1", "f2", "f3");
RestRequest request = buildRequest(uri, acceptTypeData.acceptHeaders, protocolVersion);
response = _responseHandler.buildResponse(request, buildRoutingResult(ResourceMethod.BATCH_GET, request, acceptTypeData.acceptHeaders), statusBatch);
checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), Status.class.getName(), true, errorResponseHeaderName);
DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());
BatchResponse<Status> batchResponse = new BatchResponse<Status>(dataMap, Status.class);
assertEquals(batchResponse.getResults().size(), 10);
for (Status status : batchResponse.getResults().values()) {
assertTrue(status.data().containsKey("f1"));
assertTrue(status.data().containsKey("f2"));
assertFalse(status.data().containsKey("f3"));
}
// ensure that output map was not modified by rest.li!
Status status1 = statusBatch.get(1);
assertNotNull(status1);
assertTrue(status1.data().containsKey("f3"));
}
use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class TestRestLiResponseHandler method testRestLiResponseData.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testRestLiResponseData(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
RestLiResponseData responseData;
RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
// #1 simple record template
responseData = _responseHandler.buildRestLiResponseData(request, routingResult1, buildStatusRecord());
checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
assertEquals(responseData.getRecordResponseEnvelope().getRecord().toString(), response1);
// #2 DataTemplate response
StringMap map = new StringMap();
map.put("key1", "value1");
map.put("key2", "value2");
RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
responseData = _responseHandler.buildRestLiResponseData(request, routingResult2, map);
checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
//Obtain the maps necessary for comparison
final DataMap actualMap;
final DataMap expectedMap;
actualMap = responseData.getRecordResponseEnvelope().getRecord().data();
expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
assertEquals(actualMap, expectedMap);
RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
// #3 empty response
responseData = _responseHandler.buildRestLiResponseData(request, routingResult3, null);
checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
assertEquals(responseData.getRecordResponseEnvelope().getRecord(), null);
}
use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class TestRestLiRouting method testDefaultPathKeyUniqueness.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "uniqueness")
public void testDefaultPathKeyUniqueness(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(CombinedResources.CombinedCollectionWithSubresources.class, CombinedResources.SubCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap);
RestRequest request;
RoutingResult result;
// #1 simple GET
request = createRequest(uri, "GET", version);
result = _router.process(request, new RequestContext(), null);
assertNotNull(result);
PathKeys keys = result.getContext().getPathKeys();
assertEquals(keys.getAsString("testId"), "foo");
assertEquals(keys.getAsString("subId"), "bar");
}
use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class TestRestLiRouting method testActionNestedRouting.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "actionNestedRouting")
public void testActionNestedRouting(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class, RepliesCollectionResource.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(), "replyToAll");
assertEquals(result.getResourceMethod().getType(), ResourceMethod.ACTION);
assertEquals(result.getContext().getPathKeys().get("statusID"), Long.valueOf(1));
}
Aggregations