Search in sources :

Example 31 with PatchRequest

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);
}
Also used : MyComplexKey(com.linkedin.restli.common.test.MyComplexKey) HashMap(java.util.HashMap) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test)

Example 32 with PatchRequest

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);
}
Also used : RestLiClientConfig(com.linkedin.restli.client.util.RestLiClientConfig) PatchRequest(com.linkedin.restli.common.PatchRequest) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

PatchRequest (com.linkedin.restli.common.PatchRequest)32 HashMap (java.util.HashMap)26 Test (org.testng.annotations.Test)22 Map (java.util.Map)14 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)11 DataMap (com.linkedin.data.DataMap)9 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)8 UpdateStatus (com.linkedin.restli.common.UpdateStatus)6 BatchPatchRequest (com.linkedin.restli.server.BatchPatchRequest)6 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)5 CompoundKey (com.linkedin.restli.common.CompoundKey)5 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)5 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)5 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)5 PartialUpdateGreetingFluentClient (com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient)5 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)4 StringMap (com.linkedin.data.template.StringMap)4 KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)4 BatchUpdateResult (com.linkedin.restli.server.BatchUpdateResult)4 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)4