Search in sources :

Example 1 with SubgreetingsRequestBuilders

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

the class TestSimpleResourceHierarchy method testSubCollectionBatchGetEntity.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionBatchGetEntity(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
    Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new SubgreetingsRequestBuilders(requestOptions).batchGet().ids(ids).build();
    Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = getClient().sendRequest(request).getResponse();
    BatchKVResponse<Long, EntityResponse<Greeting>> batchResponse = response.getEntity();
    Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) SubgreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsRequestBuilders) EntityResponse(com.linkedin.restli.common.EntityResponse) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 2 with SubgreetingsRequestBuilders

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

the class TestSimpleResourceHierarchy method testSubCollectionBatchCreate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubCollectionBatchCreate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Message1");
    greeting.setTone(Tone.FRIENDLY);
    Greeting greeting2 = new Greeting();
    greeting.setMessage("Message2");
    greeting.setTone(Tone.FRIENDLY);
    ArrayList<Greeting> greetings = new ArrayList<Greeting>();
    greetings.add(greeting);
    greetings.add(greeting2);
    //POST
    List<CreateIdStatus<Long>> statuses = BatchCreateHelper.batchCreate(getClient(), builders, greetings);
    ArrayList<Long> ids = new ArrayList<Long>();
    for (CreateIdStatus<Long> status : statuses) {
        @SuppressWarnings("deprecation") String id = status.getId();
        Assert.assertEquals(status.getKey().longValue(), Long.parseLong(id));
        ids.add(status.getKey());
    }
    //GET again to verify that the create has worked.
    final RestliRequestOptions requestOptions = builders.getRequestOptions();
    Request<BatchKVResponse<Long, EntityResponse<Greeting>>> request = new SubgreetingsRequestBuilders(requestOptions).batchGet().ids(ids).build();
    Response<BatchKVResponse<Long, EntityResponse<Greeting>>> response = getClient().sendRequest(request).getResponse();
    BatchKVResponse<Long, EntityResponse<Greeting>> batchResponse = response.getEntity();
    Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestliRequestOptions(com.linkedin.restli.client.RestliRequestOptions) SubgreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsRequestBuilders) ArrayList(java.util.ArrayList) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) Test(org.testng.annotations.Test)

Example 3 with SubgreetingsRequestBuilders

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

the class TestSimpleResourceHierarchy method testSubCollectionCreateId.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    final SubgreetingsRequestBuilders builders = new SubgreetingsRequestBuilders(requestOptions);
    //POST
    CreateIdRequest<Long, Greeting> createRequest = builders.create().input(greeting).build();
    Response<IdResponse<Long>> response = getClient().sendRequest(createRequest).getResponse();
    Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    long id = response.getEntity().getId();
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(id, Long.parseLong(stringId));
    //GET again to verify that the create has worked.
    Request<Greeting> getRequest = builders.get().id(id).build();
    Response<Greeting> getResponse = getClient().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) SubgreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsRequestBuilders) Test(org.testng.annotations.Test)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 SubgreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.SubgreetingsRequestBuilders)3 Test (org.testng.annotations.Test)3 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2 RestliRequestOptions (com.linkedin.restli.client.RestliRequestOptions)1 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)1 IdResponse (com.linkedin.restli.common.IdResponse)1 ArrayList (java.util.ArrayList)1