use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestActionsResource method testArrayTypesOnActions.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testArrayTypesOnActions(RootBuilderWrapper<?, ?> builders) throws RemoteInvocationException {
//Record template array
MessageArray inputMessageArray = new MessageArray();
inputMessageArray.add(new Message().setId("My Message Id").setMessage("My Message"));
inputMessageArray.add(new Message().setId("My Message Id 2").setMessage("My Message 2"));
Request<MessageArray> messageArrayRequest = builders.<MessageArray>action("EchoMessageArray").setActionParam("Messages", inputMessageArray).build();
MessageArray messageArray = getClient().sendRequest(messageArrayRequest).getResponse().getEntity();
Assert.assertEquals(messageArray.get(0).getId(), "My Message Id");
Assert.assertEquals(messageArray.get(0).getMessage(), "My Message");
Assert.assertEquals(messageArray.get(1).getId(), "My Message Id 2");
Assert.assertEquals(messageArray.get(1).getMessage(), "My Message 2");
//Primitive type array
StringArray inputStringArray = new StringArray();
inputStringArray.add("message1");
inputStringArray.add("message2");
Request<StringArray> stringArrayRequest = builders.<StringArray>action("EchoStringArray").setActionParam("Strings", inputStringArray).build();
StringArray stringArray = getClient().sendRequest(stringArrayRequest).getResponse().getEntity();
Assert.assertEquals(stringArray.get(0), "message1");
Assert.assertEquals(stringArray.get(1), "message2");
//Enum array
ToneArray inputTonesArray = new ToneArray();
inputTonesArray.add(Tone.SINCERE);
inputTonesArray.add(Tone.FRIENDLY);
Request<ToneArray> toneArrayRequest = builders.<ToneArray>action("EchoToneArray").setActionParam("Tones", inputTonesArray).build();
ToneArray tones = getClient().sendRequest(toneArrayRequest).getResponse().getEntity();
Assert.assertEquals(tones.get(0), Tone.SINCERE);
Assert.assertEquals(tones.get(1), Tone.FRIENDLY);
}
use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.
the class TestAssociationsResource method testSubresourceFinder.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubresourceFinder(RootBuilderWrapper<String, Message> builders) throws RemoteInvocationException {
Request<CollectionResponse<Message>> request = builders.findBy("Tone").setPathKey("dest", "dest").setPathKey("src", "src").setQueryParam("tone", Tone.FRIENDLY).build();
List<Message> messages = getClient().sendRequest(request).getResponse().getEntity().getElements();
for (Message message : messages) {
Assert.assertEquals(message.getTone(), Tone.FRIENDLY);
}
}
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);
}
Aggregations