use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionBatchGetEntity.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionBatchGetEntity(RestliRequestOptions requestOptions) throws RemoteInvocationException {
List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new SubgreetingsRequestBuilders(requestOptions).batchGet().ids(ids).build();
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = getClient().sendRequest(request).getResponse();
BatchKVResponse<Long, EntityResponse<Greeting>> batchResponse = response.getEntity();
Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestNullGreetingsClient method testBatchUpdateUnsupportedNullKeyMap.
/*
* This test is one of the few areas in this test suite where we don't expect an exception.
* The purpose of this test is to make sure Rest.li can handle java.util.concurrent.ConcurrentHashMap(s) sent
* back by resource methods.
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchUpdateUnsupportedNullKeyMap(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(7l, someGreeting).build();
Response<BatchKVResponse<Long, UpdateStatus>> response = getClient().sendRequest(writeRequest).getResponse();
Map<Long, ErrorResponse> actualErrors = response.getEntity().getErrors();
Assert.assertEquals(actualErrors.size(), 0, "Errors map should be empty");
Map<Long, UpdateStatus> actualResults = response.getEntity().getResults();
Map<Long, UpdateStatus> expectedResults = new HashMap<Long, UpdateStatus>();
UpdateStatus updateStatus = new UpdateStatus().setStatus(201);
expectedResults.put(3l, updateStatus);
Assert.assertEquals(actualResults, expectedResults, "The results map should be correct");
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestNullGreetingsClient method testBatchGetUnsupportedNullKeyMap.
/*
* This test is one of the few areas in this test suite where we don't expect an exception.
* The purpose of this test is to make sure Rest.li can handle java.util.concurrent.ConcurrentHashMap(s) sent
* back by resource methods.
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchGetRequestBuilderDataProvider")
public void testBatchGetUnsupportedNullKeyMap(final BatchGetEntityRequestBuilder<Long, Greeting> builder) throws RemoteInvocationException, CloneNotSupportedException {
BatchGetEntityRequest<Long, Greeting> request = builder.ids(ImmutableSet.of(5l)).fields(Greeting.fields().id(), Greeting.fields().message()).build();
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = getClient().sendRequest(request).getResponse();
final Greeting actualGreeting = response.getEntity().getResults().get(0l).getEntity();
Assert.assertEquals(actualGreeting.getMessage(), "Good morning!", "We should get the correct Greeting back");
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestNullGreetingsClient method sendBatchUpdateAndAssert.
private void sendBatchUpdateAndAssert(final RootBuilderWrapper<Long, Greeting> builders, Long id) throws RemoteInvocationException {
try {
final Greeting someGreeting = new Greeting().setMessage("Hello").setTone(Tone.INSULTING);
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(id, someGreeting).build();
getClient().sendRequest(writeRequest).getResponse();
} catch (final RestLiResponseException responseException) {
assertCorrectInternalServerMessageForNull(responseException, "batch_update");
}
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestGreetingsClient method testBatchPartialUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchPartialUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
List<Greeting> greetings = generateBatchTestData(3, "BatchPatch", Tone.FRIENDLY);
@SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
addIdsToGeneratedGreetings(createdIds, greetings);
// Patch the created Greetings
Map<Long, PatchRequest<Greeting>> patchedGreetingsDiffs = new HashMap<Long, PatchRequest<Greeting>>();
List<Greeting> patchedGreetings = new ArrayList<Greeting>();
for (Greeting greeting : greetings) {
Greeting patchedGreeting = new Greeting(greeting.data().copy());
patchedGreeting.setMessage(patchedGreeting.getMessage().toUpperCase());
PatchRequest<Greeting> patchRequest = PatchGenerator.diff(greeting, patchedGreeting);
patchedGreetingsDiffs.put(patchedGreeting.getId(), patchRequest);
patchedGreetings.add(patchedGreeting);
}
// Batch patch
Request<BatchKVResponse<Long, UpdateStatus>> batchUpdateRequest = builders.batchPartialUpdate().patchInputs(patchedGreetingsDiffs).build();
Map<Long, UpdateStatus> results = getClient().sendRequest(batchUpdateRequest).getResponse().getEntity().getResults();
Assert.assertEquals(results.size(), patchedGreetingsDiffs.size());
for (UpdateStatus status : results.values()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
}
getAndVerifyBatchTestDataSerially(builders, createdIds, patchedGreetings, null);
deleteAndVerifyBatchTestDataSerially(builders, createdIds);
}
Aggregations