use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestResponseDecoder method testNonRestliServerErrorHandling.
/**
* This test tests 2 things in combo here:
* 1) BatchEntityResponseDecoder could be invoked in some cases to try to decode a empty response dataMap when
* non-rest.li server error returns, in this test, we simulate that by passing a over-size URL param
* {@link com.linkedin.restli.internal.client.ExceptionUtil#exceptionForThrowable(java.lang.Throwable, com.linkedin.restli.internal.client.RestResponseDecoder)}
*
* 2) CallbackAdapter and its subclasses could have error while its dealing with error itself, this test make sure it
* pass the 'new' error to its inner callback's onError method.
* {@link CallbackAdapter#onError(java.lang.Throwable)}
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "dataProvider")
public void testNonRestliServerErrorHandling(RestliRequestOptions requestOptions) throws Exception {
Set<String> keys = new HashSet<String>();
keys.add(createDataSize(SERVER_HEADER_OVERLOAD_SIZE));
BatchGetEntityRequest<String, Message> req = new StringKeysRequestBuilders(requestOptions).batchGet().ids(keys).build();
ResponseFuture<BatchKVResponse<String, EntityResponse<Message>>> batchKVResponseResponseFuture = getClient().sendRequest(req);
try {
batchKVResponseResponseFuture.getResponse();
Assert.fail("Exception should have thrown before this point!");
} catch (Throwable e) {
Assert.assertTrue(e instanceof RestLiResponseException);
Assert.assertEquals(((RestLiResponseException) e).getStatus(), 414);
}
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class StringKeysResource method update.
@RestMethod.Update
public UpdateResponse update(String key, Message entity) {
Message g = _db.get(key);
if (g == null) {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
_db.put(key, entity);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class StringKeysResource method update.
@RestMethod.PartialUpdate
public UpdateResponse update(String key, PatchRequest<Message> patch) {
Message g = _db.get(key);
if (g == null) {
return new UpdateResponse(HttpStatus.S_404_NOT_FOUND);
}
try {
PatchApplier.applyPatch(g, patch);
} catch (DataProcessingException e) {
return new UpdateResponse(HttpStatus.S_400_BAD_REQUEST);
}
_db.put(key, g);
return new UpdateResponse(HttpStatus.S_204_NO_CONTENT);
}
use of com.linkedin.restli.examples.greetings.api.Message 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.examples.greetings.api.Message in project rest.li by linkedin.
the class TestComplexKeysResource method doPartialUpdate.
private ComplexResourceKey<TwoPartKey, TwoPartKey> doPartialUpdate(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, EmptyRecord> updateRequestBuilder, ComplexResourceKey<TwoPartKey, TwoPartKey> key, String newMessage) throws RemoteInvocationException {
Message message = new Message();
message.setMessage(newMessage);
PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
Request<EmptyRecord> request = updateRequestBuilder.id(key).input(patch).build();
ResponseFuture<EmptyRecord> future = getClient().sendRequest(request);
Response<EmptyRecord> response = future.getResponse();
Assert.assertEquals(response.getStatus(), 204);
return key;
}
Aggregations