use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchPatchArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(ProtocolVersion version, Key primaryKey, Key[] associationKeys, String requestEntity, Object[] keys, PatchRequest<MyComplexKey>[] patches) throws Exception {
Set<Object> batchKeys = new HashSet<>(Arrays.asList(keys));
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(requestEntity, version);
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, primaryKey, associationKeys, batchKeys);
@SuppressWarnings("rawtypes") Parameter<BatchPatchRequest> param = new Parameter<>("", BatchPatchRequest.class, null, false, null, Parameter.ParamType.BATCH, false, new AnnotationSet(new Annotation[] {}));
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, Collections.singletonList(param), CollectionResourceAsyncTemplate.class.getMethod("batchUpdate", BatchPatchRequest.class, Callback.class));
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(batchKeys, version, true, false);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, context);
RestLiArgumentBuilder argumentBuilder = new BatchPatchArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args.length, 1);
assertTrue(args[0] instanceof BatchPatchRequest);
Map<?, ?> data = ((BatchPatchRequest) args[0]).getData();
assertEquals(data.size(), keys.length);
for (int i = 0; i < keys.length; i++) {
assertEquals(data.get(keys[i]), patches[i]);
}
verify(request, descriptor, context, routingResult);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testProjectionParams.
@Test
public void testProjectionParams() throws IOException {
List<Parameter<?>> finderWithProjectionParams = new ArrayList<>();
finderWithProjectionParams.add(new Parameter<>("key", String.class, new StringDataSchema(), false, null, Parameter.ParamType.QUERY, true, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", PagingContext.class, null, false, new PagingContext(0, 10), Parameter.ParamType.PAGING_CONTEXT_PARAM, false, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", MaskTree.class, null, false, null, Parameter.ParamType.PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", MaskTree.class, null, false, null, Parameter.ParamType.METADATA_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
finderWithProjectionParams.add(new Parameter<>("", MaskTree.class, null, false, null, Parameter.ParamType.PAGING_PROJECTION_PARAM, false, new AnnotationSet(new Annotation[] {})));
Map<String, String> finderWithProjectionContextParams = new HashMap<>();
finderWithProjectionContextParams.put("start", "100");
finderWithProjectionContextParams.put("count", "15");
finderWithProjectionContextParams.put("key", "keyString");
Map<String, Integer> projectionMap = new HashMap<>();
projectionMap.put("a", 1);
Map<String, Integer> metadataMap = new HashMap<>();
metadataMap.put("intField", 1);
metadataMap.put("booleanField", 1);
Map<String, Integer> pagingMap = new HashMap<>();
pagingMap.put("total", 1);
MaskTree projectionMask = new MaskTree(new DataMap(projectionMap));
MaskTree metadataMask = new MaskTree(new DataMap(metadataMap));
MaskTree pagingMask = new MaskTree(new DataMap(pagingMap));
Object[] expectedArgs = new Object[] { "keyString", new PagingContext(100, 15), projectionMask, metadataMask, pagingMask };
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, 1, finderWithProjectionParams);
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(finderWithProjectionContextParams, projectionMask, metadataMask, pagingMask, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(List<Parameter<?>> params, Map<String, String> contextParams, MutablePathKeys pathKeys, Object[] expectedArgs) throws IOException {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, 1, params);
ServerResourceContext context;
if (contextParams != null) {
context = RestLiArgumentBuilderTestHelper.getMockResourceContext(contextParams, true);
} else {
context = RestLiArgumentBuilderTestHelper.getMockResourceContext(pathKeys, false, true);
}
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
assertEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestCollectionArgumentBuilder method testArrayArgument.
@Test(dataProvider = "arrayArgument")
public void testArrayArgument(Parameter<?> param, String parameterKey, List<String> parameterValues, Object[] expectedArgs) throws IOException {
ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(null, param);
ServerResourceContext context = RestLiArgumentBuilderTestHelper.getMockResourceContext(parameterKey, parameterValues, true);
RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, context, 1);
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, null);
RestLiArgumentBuilder argumentBuilder = new CollectionArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, null);
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
ArrayAsserts.assertArrayEquals(args, expectedArgs);
verify(descriptor, context, routingResult, request);
}
use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.
the class TestBatchCreateResponseBuilder method testCreateKVResultBuilder.
@Test(dataProvider = "createKVResultBuilderTestData")
public void testCreateKVResultBuilder(String altKeyName, Map<String, AlternativeKey<?, ?>> alternativeKeyMap, List<CreateIdEntityStatus<?, Foo>> expectedResponses) throws URISyntaxException {
List<CreateKVResponse<Long, Foo>> createKVResponses = new ArrayList<>(2);
Foo foo1 = new Foo();
foo1.setStringField("foo1");
Foo foo2 = new Foo();
foo2.setStringField("foo2");
createKVResponses.add(new CreateKVResponse<>(1L, foo1));
createKVResponses.add(new CreateKVResponse<>(2L, foo2));
BatchCreateKVResult<Long, Foo> results = new BatchCreateKVResult<>(createKVResponses);
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(alternativeKeyMap);
ServerResourceContext mockContext = getMockKVResourceContext(altKeyName);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
BatchCreateResponseBuilder responseBuilder = new BatchCreateResponseBuilder(null);
RestRequest request = new RestRequestBuilder(new URI("/foo")).build();
RestLiResponseData<BatchCreateResponseEnvelope> responseData = responseBuilder.buildRestLiResponseData(request, routingResult, results, headers, Collections.emptyList());
RestLiResponse restResponse = responseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
Assert.assertTrue(responseData.getResponseEnvelope().isGetAfterCreate());
List<CreateIdEntityStatus<Object, Foo>> items = new ArrayList<>();
for (BatchCreateResponseEnvelope.CollectionCreateResponseItem item : responseData.getResponseEnvelope().getCreateResponses()) {
@SuppressWarnings("unchecked") CreateIdEntityStatus<Object, Foo> record = (CreateIdEntityStatus<Object, Foo>) item.getRecord();
items.add(record);
}
Assert.assertEquals(items, expectedResponses);
Assert.assertEquals(restResponse.getStatus(), HttpStatus.S_200_OK);
}
Aggregations