Search in sources :

Example 6 with GreetingsRequestBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.

the class TestGreetingClientContentTypes method testCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "buildersClientDataDataProvider")
public void testCreateId(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    final GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
    CreateIdRequest<Long, Greeting> createRequest = builders.create().input(greeting).build();
    Response<IdResponse<Long>> response = restClient.sendRequest(createRequest).getResponse();
    Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    @SuppressWarnings("unchecked") long id = response.getEntity().getId();
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(id, Long.parseLong(stringId));
    Request<Greeting> getRequest = builders.get().id(id).build();
    Response<Greeting> getResponse = restClient.sendRequest(getRequest).getResponse();
    Greeting responseGreeting = getResponse.getEntity();
    Assert.assertEquals(responseGreeting.getMessage(), greeting.getMessage());
    Assert.assertEquals(responseGreeting.getTone(), greeting.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) Test(org.testng.annotations.Test)

Example 7 with GreetingsRequestBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.

the class TestScatterGather method prepareData.

private static Long[] prepareData(List<Greeting> entities, RestliRequestOptions requestOptions) throws RemoteInvocationException {
    GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
    BatchCreateIdRequest<Long, Greeting> request = builders.batchCreate().inputs(entities).build();
    Response<BatchCreateIdResponse<Long>> response = REST_CLIENT.sendRequest(request).getResponse();
    List<CreateIdStatus<Long>> statuses = response.getEntity().getElements();
    final Long[] requestIds = new Long[entities.size()];
    for (int i = 0; i < statuses.size(); ++i) {
        CreateIdStatus<Long> status = statuses.get(i);
        Assert.assertFalse(status.hasError());
        requestIds[i] = status.getKey();
    }
    return requestIds;
}
Also used : BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)

Example 8 with GreetingsRequestBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.

the class TestCompressionServer method testNewCookbookInBatch.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCookbookDataProvider")
public void testNewCookbookInBatch(RestClient client, RestliRequestOptions requestOptions) throws Exception {
    final GreetingsRequestBuilders builders = new GreetingsRequestBuilders(requestOptions);
    // GET
    Greeting greetingResult = getNewCookbookBatchGetResult(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.
    getNewCookbookBatchGetResult(client, requestOptions);
    // batch Create
    Greeting repeatedGreeting = new Greeting();
    repeatedGreeting.setMessage("Hello Hello");
    repeatedGreeting.setTone(Tone.SINCERE);
    List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
    Request<BatchCreateIdResponse<Long>> batchCreateRequest = builders.batchCreate().inputs(entities).build();
    List<CreateIdStatus<Long>> statuses = client.sendRequest(batchCreateRequest).getResponse().getEntity().getElements();
    for (CreateIdStatus<Long> status : statuses) {
        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) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) 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 9 with GreetingsRequestBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.

the class TestRestLiScatterGather method prepareData.

private static Long[] prepareData(RestClient restClient, List<Greeting> entities) throws RemoteInvocationException {
    GreetingsRequestBuilders builders = new GreetingsRequestBuilders();
    BatchCreateIdRequest<Long, Greeting> request = builders.batchCreate().inputs(entities).build();
    Response<BatchCreateIdResponse<Long>> response = restClient.sendRequest(request).getResponse();
    List<CreateIdStatus<Long>> statuses = response.getEntity().getElements();
    final Long[] requestIds = new Long[entities.size()];
    for (int i = 0; i < statuses.size(); ++i) {
        CreateIdStatus<Long> status = statuses.get(i);
        Assert.assertFalse(status.hasError());
        requestIds[i] = status.getKey();
    }
    return requestIds;
}
Also used : BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)

Example 10 with GreetingsRequestBuilders

use of com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders in project rest.li by linkedin.

the class TestDefaultMethodAdapterProvider method testCreateAndGetTheSameRecord.

@Test
public void testCreateAndGetTheSameRecord() 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(), insulting.getMessage());
    Assert.assertEquals(actualEntity.getTone(), insulting.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)

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