use of com.linkedin.restli.common.CreateStatus in project rest.li by linkedin.
the class TestCompressionServer method testOldCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCookbookDataProvider")
public void testOldCookbookInBatch(RestClient client, RestliRequestOptions requestOptions) throws Exception {
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
// GET
Greeting greetingResult = getOldCookbookBatchGetResult(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.
getOldCookbookBatchGetResult(client, requestOptions);
// batch Create
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
Request<CollectionResponse<CreateStatus>> batchCreateRequest = builders.batchCreate().inputs(entities).build();
List<CreateStatus> statuses = client.sendRequest(batchCreateRequest).getResponse().getEntity().getElements();
for (CreateStatus status : statuses) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertNotNull(id);
}
}
use of com.linkedin.restli.common.CreateStatus in project rest.li by linkedin.
the class TestExceptionsResource method testBatchCreateErrors.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchCreateErrors(RestliRequestOptions requestOptions) throws Exception {
ExceptionsBuilders builders = new ExceptionsBuilders(requestOptions);
Request<CollectionResponse<CreateStatus>> batchCreateRequest = builders.batchCreate().input(new Greeting().setId(10L).setMessage("Greetings.").setTone(Tone.SINCERE)).input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING)).build();
Response<CollectionResponse<CreateStatus>> response = getClient().sendRequest(batchCreateRequest).getResponse();
List<CreateStatus> createStatuses = response.getEntity().getElements();
Assert.assertEquals(createStatuses.size(), 2);
@SuppressWarnings("unchecked") CreateIdStatus<Long> status0 = (CreateIdStatus<Long>) 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());
CreateStatus 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