use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestCustomMethodAdapterProvider method testCreateAndGetOverriddenRecord.
@Test
public void testCreateAndGetOverriddenRecord() throws RemoteInvocationException {
Greeting insulting = new Greeting().setMessage("Insulting").setTone(Tone.INSULTING);
CreateIdRequest<Long, Greeting> createRequest = new GreetingsRequestBuilders().create().input(insulting).build();
Response<IdResponse<Long>> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertFalse(createResponse.hasError());
Long createId = createResponse.getEntity().getId();
GetRequest<Greeting> getRequest = new GreetingsRequestBuilders().get().id(createId).build();
Response<Greeting> getResponse = getClient().sendRequest(getRequest).getResponse();
Assert.assertFalse(getResponse.hasError());
Greeting actualEntity = getResponse.getEntity();
Assert.assertEquals(actualEntity.getMessage(), FRIENDLY.getMessage());
Assert.assertEquals(actualEntity.getTone(), FRIENDLY.getTone());
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders 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.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestCompressionServer method clientsCompressedResponsesBuilderDataProvider.
// Returns a combination of all possible request/response compression combinations
@DataProvider(name = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCompressedResponsesBuilderDataProvider")
public Object[][] clientsCompressedResponsesBuilderDataProvider() {
// sample compression operation config
String[] compressionOperations = { "*", "action:*", "finder:*", "finder:search", "get, batch_get, get_all", "get, batch_get, get_all, batch_create, batch_update, batch_partial_update" };
int entries = compressionOperations.length;
Object[][] result = new Object[entries * 4][];
int index = entries * 4 - 1;
for (String operation : compressionOperations) {
Map<String, String> clientProperties = new HashMap<>();
clientProperties.put(HttpClientFactory.HTTP_RESPONSE_COMPRESSION_OPERATIONS, operation);
RestClient client = new RestClient(newTransportClient(clientProperties), URI_PREFIX, getClientConfig());
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders()), AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion() };
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)), AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion() };
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders()), AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion() };
result[index--] = new Object[] { client, operation, new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)), AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion() };
}
return result;
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestCompressionServer method getNewCookbookBatchGetResult.
private Greeting getNewCookbookBatchGetResult(RestClient client, RestliRequestOptions requestOptions) throws RemoteInvocationException {
Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new GreetingsRequestBuilders(requestOptions).batchGet().ids(1L).build();
ResponseFuture<BatchKVResponse<Long, EntityResponse<Greeting>>> future = client.sendRequest(request);
Response<BatchKVResponse<Long, EntityResponse<Greeting>>> greetingResponse = future.getResponse();
checkContentEncodingHeaderIsAbsent(greetingResponse);
return greetingResponse.getEntity().getResults().get(1L).getEntity();
}
use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.
the class TestRestLiScatterGather method testSendSGGetEntityRequests.
// BatchGetEntityRequest
private static void testSendSGGetEntityRequests(RestClient restClient, Long[] requestIds) throws RemoteInvocationException {
BatchGetEntityRequest<Long, Greeting> request = new GreetingsRequestBuilders().batchGet().ids(requestIds).fields(Greeting.fields().message()).setParam("foo", "bar").build();
BatchKVResponse<Long, EntityResponse<Greeting>> result = restClient.sendRequest(request).getResponse().getEntity();
Assert.assertEquals(result.getResults().size(), requestIds.length);
EntityResponse<Greeting> item = result.getResults().values().iterator().next();
Assert.assertNotNull(item.getEntity());
Assert.assertNotNull(item.getEntity().getMessage());
Assert.assertTrue(result.getResults().values().iterator().next().getEntity() instanceof Greeting);
Assert.assertEquals(result.getErrors().size(), 0);
}
Aggregations