use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestCompressionServer method testNewCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCookbookDataProvider")
public void testNewCookbookInBatch(RestClient client, RestliRequestOptions requestOptions) throws Exception {
final GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
// GET
Greeting greetingResult = getNewCookbookBatchGetResult(client, requestOptions);
// POST
Greeting greeting = new Greeting(greetingResult.data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
client.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
getNewCookbookBatchGetResult(client, requestOptions);
// batch Create
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
Request<BatchCreateIdResponse<Long>> batchCreateRequest = builders.batchCreate().inputs(entities).build();
List<CreateIdStatus<Long>> statuses = client.sendRequest(batchCreateRequest).getResponse().getEntity().getElements();
for (CreateIdStatus<Long> status : statuses) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertEquals(status.getKey().longValue(), Long.parseLong(id));
Assert.assertNotNull(status.getKey());
}
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchCreateIdMain.
private void testBatchCreateIdMain(BatchCreateIdRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchCreateRequestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
final String messageText1 = "firstMessage";
Message message1 = new Message();
message1.setMessage(messageText1);
final String messageText2 = "secondMessage";
Message message2 = new Message();
message2.setMessage(messageText2);
List<Message> messages = new ArrayList<Message>(2);
messages.add(message1);
messages.add(message2);
ComplexResourceKey<TwoPartKey, TwoPartKey> expectedComplexKey1 = getComplexKey(messageText1, messageText1);
ComplexResourceKey<TwoPartKey, TwoPartKey> expectedComplexKey2 = getComplexKey(messageText2, messageText2);
// test build
BatchCreateIdRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> request = batchCreateRequestBuilder.inputs(messages).build();
Response<BatchCreateIdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> response = getClient().sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), 200);
Set<ComplexResourceKey<TwoPartKey, TwoPartKey>> expectedComplexKeys = new HashSet<ComplexResourceKey<TwoPartKey, TwoPartKey>>(2);
expectedComplexKeys.add(expectedComplexKey1);
expectedComplexKeys.add(expectedComplexKey2);
for (CreateIdStatus<ComplexResourceKey<TwoPartKey, TwoPartKey>> status : response.getEntity().getElements()) {
Assert.assertEquals(status.getStatus(), new Integer(201));
Assert.assertTrue(expectedComplexKeys.contains(status.getKey()));
try {
@SuppressWarnings("deprecation") String id = status.getId();
Assert.fail("buildReadOnlyId should throw an exception for ComplexKeys");
} catch (UnsupportedOperationException e) {
// expected
}
expectedComplexKeys.remove(status.getKey());
}
Assert.assertTrue(expectedComplexKeys.isEmpty());
// attempt to batch get created records
List<ComplexResourceKey<TwoPartKey, TwoPartKey>> createdKeys = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>(2);
createdKeys.add(expectedComplexKey1);
createdKeys.add(expectedComplexKey2);
Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> getRequest = batchGetRequestBuilder.ids(createdKeys).build();
ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> getFuture = getClient().sendRequest(getRequest);
Response<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> getResponse = getFuture.getResponse();
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResults = getResponse.getEntity().getResults();
Assert.assertEquals(getResults.get(expectedComplexKey1).getEntity(), message1);
Assert.assertEquals(getResults.get(expectedComplexKey2).getEntity(), message2);
Assert.assertEquals(getResults.size(), 2);
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestGreetingsClient method testNewCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testNewCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
final GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
// GET
final BatchGetEntityRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = batchGetBuilder.ids(1L).build();
ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future = getClient().sendRequest(request);
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> greetingResponse = future.getResponse();
// PUT
Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get(1L).getEntity().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<BatchKVResponse<Long, EntityResponse<Greeting>>> request2 = builders.batchGet().ids(1L).build();
ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
Request<BatchCreateIdResponse<Long>> request3 = builders.batchCreate().inputs(entities).build();
BatchCreateIdResponse<Long> statuses = getClient().sendRequest(request3).getResponse().getEntity();
for (CreateIdStatus<Long> status : statuses.getElements()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertEquals(status.getKey().longValue(), Long.parseLong(id));
Assert.assertNotNull(status.getKey());
}
}
use of com.linkedin.restli.common.BatchCreateIdResponse in project rest.li by linkedin.
the class TestExceptionsResource method testBatchCreateIdErrors.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchCreateIdErrors(RestliRequestOptions requestOptions) throws Exception {
ExceptionsRequestBuilders builders = new ExceptionsRequestBuilders(requestOptions);
BatchCreateIdRequest<Long, Greeting> batchCreateRequest = builders.batchCreate().input(new Greeting().setId(10L).setMessage("Greetings.").setTone(Tone.SINCERE)).input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING)).build();
Response<BatchCreateIdResponse<Long>> response = getClient().sendRequest(batchCreateRequest).getResponse();
List<CreateIdStatus<Long>> createStatuses = response.getEntity().getElements();
Assert.assertEquals(createStatuses.size(), 2);
@SuppressWarnings("unchecked") CreateIdStatus<Long> status0 = createStatuses.get(0);
Assert.assertEquals(status0.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(status0.getKey(), new Long(10));
@SuppressWarnings("deprecation") String id = status0.getId();
Assert.assertEquals(BatchResponse.keyToString(status0.getKey(), ProtocolVersionUtil.extractProtocolVersion(response.getHeaders())), id);
Assert.assertFalse(status0.hasError());
CreateIdStatus<Long> status1 = createStatuses.get(1);
Assert.assertEquals(status1.getStatus().intValue(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
Assert.assertTrue(status1.hasError());
ErrorResponse error = status1.getError();
Assert.assertEquals(error.getStatus().intValue(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
Assert.assertEquals(error.getMessage(), "I will not tolerate your insolence!");
Assert.assertEquals(error.getServiceErrorCode().intValue(), 999);
Assert.assertEquals(error.getExceptionClass(), "com.linkedin.restli.server.RestLiServiceException");
Assert.assertEquals(error.getErrorDetails().data().getString("reason"), "insultingGreeting");
Assert.assertTrue(error.getStackTrace().startsWith("com.linkedin.restli.server.RestLiServiceException [HTTP Status:406, serviceErrorCode:999]: I will not tolerate your insolence!"), "stacktrace mismatch:" + error.getStackTrace());
}
Aggregations