use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchPartialUpdateAndGetWithProjection.
@Test
public void testBatchPartialUpdateAndGetWithProjection() throws Exception {
PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Map<Long, PatchRequest<Greeting>> inputs = new HashMap<>();
Greeting original = getGreeting();
String message = "Edited message: fluent api test partialUpdateAndGet";
Greeting update = getGreeting(message);
inputs.put(21L, PatchGenerator.diff(original, update));
inputs.put(22L, PatchGenerator.diff(original, update));
CompletionStage<Map<Long, UpdateEntityStatus<Greeting>>> result = greetings.batchPartialUpdateAndGet(inputs, optionalParams -> optionalParams.withMask(mask -> mask.withId().withMessage().withTone()));
CompletableFuture<Map<Long, UpdateEntityStatus<Greeting>>> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
Assert.assertEquals(future.get().get(21L).getEntity().getId().longValue(), 21L);
Assert.assertEquals(future.get().get(21L).getEntity().getMessage(), message);
Assert.assertEquals(future.get().get(22L).getEntity().getId().longValue(), 22L);
Assert.assertEquals(future.get().get(22L).getEntity().getMessage(), message);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchPartialUpdate.
@Test
public void testBatchPartialUpdate() throws Exception {
PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Map<Long, PatchRequest<Greeting>> inputs = new HashMap<>();
Greeting original = getGreeting();
String message = "Edited message: fluent api test partialUpdateAndGet";
Greeting update = getGreeting(message);
inputs.put(21L, PatchGenerator.diff(original, update));
inputs.put(22L, PatchGenerator.diff(original, update));
CompletionStage<Map<Long, UpdateStatus>> result = greetings.batchPartialUpdate(inputs);
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
Assert.assertEquals(future.get().get(21L).getStatus().intValue(), 200);
Assert.assertEquals(future.get().get(22L).getStatus().intValue(), 200);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestClientBuilders method testBatchPartialUpdateCompoundKeyRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchCompoundKey")
public void testBatchPartialUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) throws CloneNotSupportedException {
BatchPartialUpdateRequestBuilder<CompoundKey, TestRecord> builder = new BatchPartialUpdateRequestBuilder<>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
Map<CompoundKey, PatchRequest<TestRecord>> inputs = new HashMap<>();
CompoundKey key1 = new CompoundKey().append("part1", 1L).append("part2", "2");
CompoundKey key2 = new CompoundKey().append("part1", 11L).append("part2", "22");
TestRecord t1 = new TestRecord().setId(1L).setMessage("1");
TestRecord t2 = new TestRecord().setId(2L);
TestRecord t3 = new TestRecord().setMessage("3");
PatchRequest<TestRecord> patch1 = PatchGenerator.diff(t1, t2);
PatchRequest<TestRecord> patch2 = PatchGenerator.diff(t2, t3);
inputs.put(key1, patch1);
inputs.put(key2, patch2);
BatchPartialUpdateRequest<CompoundKey, TestRecord> request = builder.inputs(inputs).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
Assert.assertNotNull(request.getPartialUpdateInputMap());
Assert.assertEquals(request.getPartialUpdateInputMap(), inputs);
@SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> expectedRequest = new BatchRequest(new DataMap(), PatchRequest.class);
expectedRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), patch1);
expectedRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), patch2);
@SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<CompoundKey, PatchRequest> factory = new KeyValueRecordFactory<>(CompoundKey.class, null, null, getCompoundKeyFieldTypes(), PatchRequest.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new CompoundKey[] { key1, key2 }, new PatchRequest[] { patch1, patch2 });
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyBatchPartialUpdateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKey")
public void testComplexKeyBatchPartialUpdateRequestBuilder(URIDetails expectedURIDetails) {
BatchPartialUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchPartialUpdateRequestBuilder<>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
Map<ComplexResourceKey<TestRecord, TestRecord>, PatchRequest<TestRecord>> inputs = new HashMap<>();
ComplexResourceKey<TestRecord, TestRecord> key1 = buildComplexKey(1L, "keyMessage1", 2L, "paramMessage1");
ComplexResourceKey<TestRecord, TestRecord> key2 = buildComplexKey(3L, "keyMessage2", 4L, "paramMessage2");
TestRecord t1 = new TestRecord().setId(1L);
TestRecord t2 = new TestRecord().setId(2L).setMessage("foo");
TestRecord t3 = new TestRecord().setMessage("bar");
PatchRequest<TestRecord> patch1 = PatchGenerator.diff(t1, t2);
PatchRequest<TestRecord> patch2 = PatchGenerator.diff(t2, t3);
inputs.put(key1, patch1);
inputs.put(key2, patch2);
BatchPartialUpdateRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.inputs(inputs).build();
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
// using .toStringFull (which is deprecated) because this is only used for checking v1
@SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> batchRequest = new BatchRequest(new DataMap(), PatchRequest.class);
batchRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), patch1);
batchRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), patch2);
@SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<ComplexResourceKey, PatchRequest> factory = new KeyValueRecordFactory<>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, PatchRequest.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new ComplexResourceKey[] { key1, key2 }, new PatchRequest[] { patch1, patch2 });
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, batchRequest, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.common.PatchRequest in project rest.li by linkedin.
the class TestGroupsRequestBuilders method testEntityUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderEntity")
public void testEntityUpdate(RootBuilderWrapper<Integer, Group> builders, URIDetails expectedURIDetails) throws IOException, RestException {
Request<EmptyRecord> request = builders.partialUpdate().id(1).input(new PatchRequest<>()).build();
checkRequestBuilder(request, ResourceMethod.PARTIAL_UPDATE, EmptyResponseDecoder.class, expectedURIDetails, new Group());
}
Aggregations