use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestPatchArgumentBuilder method testArgumentBuilderSuccess.
@Test(dataProvider = "argumentData")
public void testArgumentBuilderSuccess(List<Parameter<?>> params, Key key, String keyName, Object keyValue) throws Exception {
RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, "{\"patch\":{\"$set\":{\"a\":\"someString\"}}}");
ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(null, key, true);
ResourceMethodDescriptor descriptor;
if (key != null) {
descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 2, params, CollectionResourceAsyncTemplate.class.getMethod("update", Object.class, PatchRequest.class, Callback.class));
} else {
descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, params, CollectionResourceAsyncTemplate.class.getMethod("update", Object.class, PatchRequest.class, Callback.class));
}
ServerResourceContext 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 PatchArgumentBuilder();
RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, DataMapUtils.readMapWithExceptions(request));
Object[] args = argumentBuilder.buildArguments(requestData, routingResult);
if (keyValue != null) {
Assert.assertEquals(args.length, 2);
Assert.assertEquals(args[0], keyValue);
}
Assert.assertTrue(args[args.length - 1] instanceof PatchRequest);
Map<String, Object> aMap = new HashMap<>();
aMap.put("a", "someString");
Map<String, Object> setMap = new HashMap<>();
setMap.put("$set", new DataMap(aMap));
Map<String, Object> data = new HashMap<>();
data.put("patch", new DataMap(setMap));
PatchRequest<MyComplexKey> patch = new PatchRequest<>(new DataMap(data));
Assert.assertEquals(args[args.length - 1], patch);
verify(request, model, descriptor, context, routingResult);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestRestLiScatterGather method testSendScatterGatherPartialUpdateEntityRequest.
@Test(dataProvider = "scatterGatherPartialUpdateEntityDataProvider")
public static void testSendScatterGatherPartialUpdateEntityRequest(URIMapper mapper) throws RemoteInvocationException {
RestLiClientConfig config = new RestLiClientConfig();
config.setScatterGatherStrategy(new DefaultScatterGatherStrategy(mapper));
RestClient restClient = new AlwaysD2RestClient(CLIENT, URI_PREFIX, config);
// Note that PartialUpdateGreeting resource only supports ids up to 20.
Long[] requestIds = new Long[] { 0L, 1L, 2L, 3L, 4L, 5L };
Map<Long, PatchRequest<Greeting>> patch = generatePartialUpdates(requestIds);
testSendSGPartialUpdateEntityRequests(restClient, patch);
}
Aggregations