Search in sources :

Example 11 with GreetingsRequestBuilders

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());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) IdResponse(com.linkedin.restli.common.IdResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) RestLiIntegrationTest(com.linkedin.restli.examples.RestLiIntegrationTest) Test(org.testng.annotations.Test)

Example 12 with GreetingsRequestBuilders

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());
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) Test(org.testng.annotations.Test)

Example 13 with GreetingsRequestBuilders

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;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) HashMap(java.util.HashMap) RestClient(com.linkedin.restli.client.RestClient) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) DataProvider(org.testng.annotations.DataProvider)

Example 14 with GreetingsRequestBuilders

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();
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)

Example 15 with GreetingsRequestBuilders

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EntityResponse(com.linkedin.restli.common.EntityResponse) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)

Aggregations

GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)16 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)14 Test (org.testng.annotations.Test)11 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)4 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)4 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)4 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)3 IdResponse (com.linkedin.restli.common.IdResponse)3 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)3 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)2 RestClient (com.linkedin.restli.client.RestClient)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2 OptionsResponse (com.linkedin.restli.common.OptionsResponse)2 HashMap (java.util.HashMap)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 DataMap (com.linkedin.data.DataMap)1 DataSchemaResolver (com.linkedin.data.schema.DataSchemaResolver)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)1