Search in sources :

Example 1 with CreateGreetingCreateAndGetRequestBuilder

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

the class TestReturnEntityWithCreate method testReturnEntityOnDemand.

/**
 * Ensures that different usages of {@link com.linkedin.restli.client.CreateIdEntityRequestBuilder#returnEntity(boolean)} are handled
 * correctly and that the response appropriately contains the entity or nothing depending on how and if the provided
 * method is used.
 */
@Test(dataProvider = "returnEntityOnDemandData")
public void testReturnEntityOnDemand(Boolean returnEntity, boolean expectReturnEntity) throws RemoteInvocationException {
    Greeting greeting = new Greeting();
    greeting.setMessage("second time!");
    greeting.setTone(Tone.FRIENDLY);
    CreateGreetingRequestBuilders builders = new CreateGreetingRequestBuilders();
    CreateGreetingCreateAndGetRequestBuilder builder = builders.createAndGet().input(greeting);
    if (returnEntity != null) {
        builder.returnEntity(returnEntity);
    }
    CreateIdEntityRequest<Long, Greeting> createIdEntityRequest = builder.build();
    Response<IdEntityResponse<Long, Greeting>> response = getClient().sendRequest(createIdEntityRequest).getResponse();
    long id = response.getEntity().getId();
    @SuppressWarnings("deprecation") String stringId = response.getId();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
    Assert.assertEquals(response.getHeader(RestConstants.HEADER_LOCATION), "/" + CreateGreetingRequestBuilders.getPrimaryResource() + "/" + id);
    Assert.assertEquals(id, Long.parseLong(stringId));
    if (expectReturnEntity) {
        Greeting returnedEntity = response.getEntity().getEntity();
        Assert.assertNotNull(returnedEntity, "RecordTemplate entity in response should not be null.");
        Assert.assertEquals(returnedEntity.getMessage(), greeting.getMessage(), "Expect returned entity message to match original.");
        Assert.assertEquals(returnedEntity.getTone(), greeting.getTone(), "Expect returned entity tone to match original.");
    } else {
        Assert.assertNull(response.getEntity().getEntity(), "RecordTemplate entity in response should be null.");
    }
}
Also used : BatchCreateIdEntityResponse(com.linkedin.restli.common.BatchCreateIdEntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CreateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.CreateGreetingRequestBuilders) CreateGreetingCreateAndGetRequestBuilder(com.linkedin.restli.examples.greetings.client.CreateGreetingCreateAndGetRequestBuilder) Test(org.testng.annotations.Test)

Aggregations

BatchCreateIdEntityResponse (com.linkedin.restli.common.BatchCreateIdEntityResponse)1 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)1 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)1 CreateGreetingCreateAndGetRequestBuilder (com.linkedin.restli.examples.greetings.client.CreateGreetingCreateAndGetRequestBuilder)1 CreateGreetingRequestBuilders (com.linkedin.restli.examples.greetings.client.CreateGreetingRequestBuilders)1 Test (org.testng.annotations.Test)1