Search in sources :

Example 1 with SubgreetingsBuilders

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

the class TestSimpleResourceHierarchy method testSubCollectionCreate.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testSubCollectionCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("Hello there!");
    greeting.setTone(Tone.FRIENDLY);
    final SubgreetingsBuilders builders = new SubgreetingsBuilders(requestOptions);
    //POST
    Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
    Response<EmptyRecord> response = getClient().sendRequest(createRequest).getResponse();
    Assert.assertNull(response.getHeader(RestConstants.HEADER_CONTENT_TYPE));
    @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
    long id = createResponse.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) EmptyRecord(com.linkedin.restli.common.EmptyRecord) CreateResponse(com.linkedin.restli.client.response.CreateResponse) SubgreetingsBuilders(com.linkedin.restli.examples.greetings.client.SubgreetingsBuilders) Test(org.testng.annotations.Test)

Example 2 with SubgreetingsBuilders

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

the class TestSimpleResourceHierarchy method testSubCollectionBatchGet.

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

Example 3 with SubgreetingsBuilders

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

the class TestSimpleResourceHierarchy method testSubCollectionBatchGetKV.

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

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 SubgreetingsBuilders (com.linkedin.restli.examples.greetings.client.SubgreetingsBuilders)3 Test (org.testng.annotations.Test)3 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)1 CreateResponse (com.linkedin.restli.client.response.CreateResponse)1 BatchResponse (com.linkedin.restli.common.BatchResponse)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1