use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.
the class TestCustomTypesClient method testCollectionCreate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException {
CreateRequest<Greeting> request = new CustomTypes2Builders(requestOptions).create().input(new Greeting().setId(10)).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("unchecked") CreateResponse<CustomLong> createResponse = (CreateResponse<CustomLong>) response.getEntity();
Assert.assertEquals(createResponse.getId(), new CustomLong(10L));
}
use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.
the class TestGreetingsClientAcceptTypes method testCreate.
@SuppressWarnings("deprecation")
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "oldBuildersClientDataDataProvider")
public void testCreate(RestClient restClient, String expectedContentType, GreetingsBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Hello there!");
greeting.setTone(Tone.FRIENDLY);
Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
Response<EmptyRecord> response = restClient.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));
Request<Greeting> getRequest = builders.get().id(id).build();
Response<Greeting> getResponse = restClient.sendRequest(getRequest).getResponse();
Assert.assertEquals(getResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE), expectedContentType);
Greeting responseGreeting = getResponse.getEntity();
Assert.assertEquals(responseGreeting.getMessage(), greeting.getMessage());
Assert.assertEquals(responseGreeting.getTone(), greeting.getTone());
}
use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.
the class TestGreetingsClient method createBatchTestDataSerially.
/**
* Creates batch data.
*
* @param greetings the greetings that we want to create
*
* @return the ids of the created Greetings
* @throws RemoteInvocationException
*/
private List<Long> createBatchTestDataSerially(RootBuilderWrapper<Long, Greeting> builders, List<Greeting> greetings) throws RemoteInvocationException {
List<Long> createdIds = new ArrayList<>();
for (Greeting greeting : greetings) {
RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilder = builders.create();
Long createdId;
if (createBuilder.isRestLi2Builder()) {
Object objBuilder = createBuilder.getBuilder();
@SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(greeting).build();
Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
createdId = response.getEntity().getId();
} else {
Request<EmptyRecord> request = createBuilder.input(greeting).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
createdId = createResponse.getId();
}
createdIds.add(createdId);
}
return createdIds;
}
use of com.linkedin.restli.client.response.CreateResponse in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testCreate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "buildersClientDataDataProvider")
public void testCreate(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Hello there!");
greeting.setTone(Tone.FRIENDLY);
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
Request<EmptyRecord> createRequest = builders.create().input(greeting).build();
Response<EmptyRecord> response = restClient.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));
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());
}
Aggregations