use of com.linkedin.restli.common.IdResponse 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());
}
use of com.linkedin.restli.common.IdResponse in project rest.li by linkedin.
the class TestComplexKeysResource method testCreateMainNewBuilders.
@SuppressWarnings("deprecation")
private void testCreateMainNewBuilders(CreateIdRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> createRequestBuilder, GetRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> getRequestBuilder) throws RemoteInvocationException {
final String messageText = "newMessage";
Message message = new Message();
message.setMessage(messageText);
Request<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> request = createRequestBuilder.input(message).build();
ResponseFuture<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> future = getClient().sendRequest(request);
Response<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> response = future.getResponse();
try {
response.getId();
Assert.fail("getId() for a complex key is not allowed!");
} catch (UnsupportedOperationException e) {
// expected
}
Assert.assertEquals(response.getStatus(), 201);
IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>> entity = response.getEntity();
ComplexResourceKey<TwoPartKey, TwoPartKey> id = entity.getId();
Assert.assertEquals(id, getComplexKey(messageText, messageText));
// attempt to get the record you just created
@SuppressWarnings("unchecked") Request<Message> getRequest = getRequestBuilder.id(id).build();
ResponseFuture<Message> getFuture = getClient().sendRequest(getRequest);
Response<Message> getResponse = getFuture.getResponse();
Assert.assertEquals(getResponse.getEntity().getMessage(), messageText);
}
use of com.linkedin.restli.common.IdResponse 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<Long>();
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.common.IdResponse in project rest.li by linkedin.
the class TestGreetingsClientAcceptTypes method testCreateId.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "newBuildersClientDataDataProvider")
public void testCreateId(RestClient restClient, String expectedContentType, GreetingsRequestBuilders builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Hello there!");
greeting.setTone(Tone.FRIENDLY);
CreateIdRequest<Long, Greeting> createRequest = builders.create().input(greeting).build();
Response<IdResponse<Long>> response = restClient.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));
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.common.IdResponse in project rest.li by linkedin.
the class TestCustomTypesClient method testCollectionCreateId.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCollectionCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
CreateIdRequest<CustomLong, Greeting> request = new CustomTypes2RequestBuilders(requestOptions).create().input(new Greeting().setId(10)).build();
Response<IdResponse<CustomLong>> response = getClient().sendRequest(request).getResponse();
Assert.assertEquals(response.getStatus(), HttpStatus.S_201_CREATED.getCode());
Assert.assertEquals(response.getEntity().getId(), new CustomLong(10L));
}
Aggregations