use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestReturnEntityWithCreate method testBatchCreateId.
/**
* Test for backward compatibility of batch create id request.
* @param restClient
* @param expectedContentType
* @param builders
* @throws RemoteInvocationException
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testBatchCreateId(RestClient restClient, String expectedContentType, CreateGreetingRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("first time!");
greeting.setTone(Tone.FRIENDLY);
BatchCreateIdRequest<Long, Greeting> batchCreateIdRequest = builders.batchCreate().inputs(Arrays.asList(greeting, greeting)).build();
Response<BatchCreateIdResponse<Long>> response = restClient.sendRequest(batchCreateIdRequest).getResponse();
Assert.assertEquals(response.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
List<CreateIdStatus<Long>> elems = response.getEntity().getElements();
Assert.assertEquals(elems.get(0).getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(elems.get(1).getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionPartialUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubCollectionPartialUpdate(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException, URISyntaxException {
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = getClient().sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
Greeting original = greetingResponse.getEntity();
// PUT
Greeting greeting = new Greeting(original.data().copy());
greeting.setMessage(original.getMessage() + " Again");
PatchRequest<Greeting> patch = PatchGenerator.diff(original, greeting);
Request<EmptyRecord> writeRequest = builders.partialUpdate().id(1L).input(patch).build();
int status = getClient().sendRequest(writeRequest).getResponse().getStatus();
Assert.assertEquals(status, HttpStatus.S_204_NO_CONTENT.getCode());
// GET again, to verify that our PUT worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, greeting.getMessage());
}
use of com.linkedin.restli.examples.greetings.api.Greeting 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());
}
use of com.linkedin.restli.examples.greetings.api.Greeting 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());
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestManualProjections method testGetWithProjection.
/**
* Test that a simple projection is applied correctly.
* @throws RemoteInvocationException
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testGetWithProjection(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Request<Greeting> request = builders.get().id(1L).fields(Greeting.fields().message()).build();
Greeting greeting = getClient().sendRequest(request).getResponseEntity();
Assert.assertFalse(greeting.hasId());
Assert.assertFalse(greeting.hasTone());
Assert.assertEquals(greeting.getMessage(), "Projected message!");
}
Aggregations