use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestGreetingsClient method testOldCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testOldCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
// GET
final BatchGetRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
Request<BatchResponse<Greeting>> request = batchGetBuilder.ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future = getClient().sendRequest(request);
Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
// PUT
Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get("1").data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<BatchResponse<Greeting>> request2 = builders.batchGet().ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
Request<CollectionResponse<CreateStatus>> request3 = builders.batchCreate().inputs(Arrays.asList(repeatedGreeting, repeatedGreeting)).build();
CollectionResponse<CreateStatus> statuses = getClient().sendRequest(request3).getResponse().getEntity();
for (CreateStatus status : statuses.getElements()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertNotNull(id);
}
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestGreetingsClient method testBatchUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException {
List<Greeting> greetings = generateBatchTestData(3, "BatchUpdate", Tone.FRIENDLY);
@SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
addIdsToGeneratedGreetings(createdIds, greetings);
// Update the created greetings
List<Greeting> updatedGreetings = new ArrayList<Greeting>();
Map<Long, Greeting> updateGreetingsRequestMap = new HashMap<Long, Greeting>();
for (Greeting greeting : greetings) {
Greeting updatedGreeting = new Greeting(greeting.data().copy());
updatedGreeting.setMessage(updatedGreeting.getMessage().toUpperCase());
updatedGreeting.setTone(Tone.SINCERE);
updatedGreetings.add(updatedGreeting);
updateGreetingsRequestMap.put(updatedGreeting.getId(), updatedGreeting);
}
// Batch update
Request<BatchKVResponse<Long, UpdateStatus>> batchUpdateRequest = builders.batchUpdate().inputs(updateGreetingsRequestMap).build();
Map<Long, UpdateStatus> results = getClient().sendRequest(batchUpdateRequest).getResponse().getEntity().getResults();
Assert.assertEquals(results.size(), updatedGreetings.size());
for (UpdateStatus status : results.values()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
}
getAndVerifyBatchTestDataSerially(builders, createdIds, updatedGreetings, null);
deleteAndVerifyBatchTestDataSerially(builders, createdIds);
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestGreetingsClient method testBatchDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchDelete(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
List<Greeting> greetings = generateBatchTestData(3, "BatchDelete", Tone.FRIENDLY);
@SuppressWarnings("unchecked") List<Long> createdIds = createBatchTestDataSerially(builders, greetings);
// Batch delete the created Greetings
Request<BatchKVResponse<Long, UpdateStatus>> deleteRequest = builders.batchDelete().ids(createdIds).build();
BatchKVResponse<Long, UpdateStatus> responses = getClient().sendRequest(deleteRequest).getResponse().getEntity();
// we deleted the Messages we created
Assert.assertEquals(responses.getResults().size(), createdIds.size());
for (UpdateStatus status : responses.getResults().values()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_204_NO_CONTENT.getCode());
}
List<Greeting> deletedGreetings = getBatchTestDataSerially(builders, createdIds);
Assert.assertEquals(deletedGreetings.size(), createdIds.size());
for (Greeting greeting : deletedGreetings) {
Assert.assertNull(greeting);
}
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestGroupsClient method testComplexKeyBatchCreateGetUpdateDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestComplexBuilderDataProvider")
public void testComplexKeyBatchCreateGetUpdateDelete(ProtocolVersion version, RootBuilderWrapper<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership> builders) throws RemoteInvocationException {
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey1 = buildComplexKey(1, 1, 10, "String1");
ComplexKeyGroupMembership groupMembership1 = buildComplexKeyGroupMembership(complexKey1.getKey(), "alfred@test.linkedin.com", "alfred", "hitchcock");
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey2 = buildComplexKey(2, 1, 20, "String2");
ComplexKeyGroupMembership groupMembership2 = buildComplexKeyGroupMembership(complexKey2.getKey(), "bruce@test.linkedin.com", "bruce", "willis");
ComplexResourceKey<GroupMembershipKey, GroupMembershipParam> complexKey3 = buildComplexKey(3, 1, 30, "String3");
ComplexKeyGroupMembership groupMembership3 = buildComplexKeyGroupMembership(complexKey3.getKey(), "carole@test.linkedin.com", "carole", "bouquet");
Request<CollectionResponse<CreateStatus>> createRequest = builders.batchCreate().input(groupMembership1).input(groupMembership2).input(groupMembership3).build();
Response<CollectionResponse<CreateStatus>> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertEquals(createResponse.getStatus(), 200);
final RestliRequestOptions requestOptions = builders.getRequestOptions();
@SuppressWarnings("unchecked") Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>>> request = new GroupMembershipsComplexRequestBuilders(requestOptions).batchGet().ids(complexKey1, complexKey2, complexKey3).fields(GroupMembership.fields().contactEmail()).build();
BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> groupMemberships = getClient().sendRequest(request).getResponse().getEntity();
Map<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, EntityResponse<ComplexKeyGroupMembership>> results = groupMemberships.getResults();
ComplexKeyGroupMembership groupMembership1_ = results.get(complexKey1).getEntity();
ComplexKeyGroupMembership groupMembership2_ = results.get(complexKey2).getEntity();
ComplexKeyGroupMembership groupMembership3_ = results.get(complexKey3).getEntity();
Assert.assertNotNull(groupMembership1_);
Assert.assertEquals(groupMembership1_.getContactEmail(), "alfred@test.linkedin.com");
Assert.assertNotNull(groupMembership2_);
Assert.assertEquals(groupMembership2_.getContactEmail(), "bruce@test.linkedin.com");
Assert.assertNotNull(groupMembership3_);
Assert.assertEquals(groupMembership3_.getContactEmail(), "carole@test.linkedin.com");
// Update and verify
groupMembership1.setContactEmail("alfred+@test.linkedin.com");
groupMembership2.setContactEmail("bruce+@test.linkedin.com");
groupMembership3.setContactEmail("carole+@test.linkedin.com");
Request<BatchKVResponse<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, UpdateStatus>> updateRequest = builders.batchUpdate().input(complexKey1, groupMembership1).input(complexKey2, groupMembership2).input(complexKey3, groupMembership3).build();
int status = getClient().sendRequest(updateRequest).getResponse().getStatus();
Assert.assertEquals(status, 200);
}
use of com.linkedin.restli.client.response.BatchKVResponse in project rest.li by linkedin.
the class TestRestLiValidation method testBatchGetAutoWithException.
@Test
public void testBatchGetAutoWithException() throws RemoteInvocationException {
// The resource returns an error for id=0 but a normal result for id=1
ValidationDemo.UnionFieldWithInlineRecord union = new ValidationDemo.UnionFieldWithInlineRecord();
union.setMyRecord(new myRecord().setFoo1(100).setFoo2(200));
ValidationDemo expectedResult = new ValidationDemo().setStringA("a").setStringB("b").setUnionFieldWithInlineRecord(union);
BatchGetRequest<ValidationDemo> request = new AutoValidationDemosBuilders().batchGet().ids(0, 1).build();
Response<BatchResponse<ValidationDemo>> response = _restClientAuto.sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals((int) response.getEntity().getErrors().get("0").getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
Assert.assertEquals(response.getEntity().getResults().get("1"), expectedResult);
BatchGetEntityRequest<Integer, ValidationDemo> request2 = new AutoValidationDemosRequestBuilders().batchGet().ids(0, 1).build();
Response<BatchKVResponse<Integer, EntityResponse<ValidationDemo>>> response2 = _restClientAuto.sendRequest(request2).getResponse();
Assert.assertEquals(response2.getStatus(), HttpStatus.S_200_OK.getCode());
Assert.assertEquals((int) response2.getEntity().getErrors().get(0).getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
Assert.assertEquals(response2.getEntity().getResults().get(1).getEntity(), expectedResult);
}
Aggregations