use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestComplexKeysResource method doPartialUpdate.
private ComplexResourceKey<TwoPartKey, TwoPartKey> doPartialUpdate(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, EmptyRecord> updateRequestBuilder, ComplexResourceKey<TwoPartKey, TwoPartKey> key, String newMessage) throws RemoteInvocationException {
Message message = new Message();
message.setMessage(newMessage);
PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
Request<EmptyRecord> request = updateRequestBuilder.id(key).input(patch).build();
ResponseFuture<EmptyRecord> future = getClient().sendRequest(request);
Response<EmptyRecord> response = future.getResponse();
Assert.assertEquals(response.getStatus(), 204);
return key;
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestCompressionServer method testPartialUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsNoCompressedResponsesDataProvider")
public void testPartialUpdate(RestClient client, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException, URISyntaxException {
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = client.sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
Greeting original = greetingResponse.getEntity();
checkContentEncodingHeaderIsAbsent(greetingResponse);
// POST
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 = client.sendRequest(writeRequest).getResponse().getStatus();
Assert.assertEquals(status, HttpStatus.S_204_NO_CONTENT.getCode());
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = client.sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, greeting.getMessage());
checkContentEncodingHeaderIsAbsent(future2.getResponse());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestCompressionServer method testCookbook.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsNoCompressedResponsesDataProvider")
public //test cookbook example from quickstart wiki
void testCookbook(RestClient restClient, RootBuilderWrapper<Long, Greeting> builders) throws Exception {
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = restClient.sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
Assert.assertNotNull(greetingResponse.getEntity().getMessage());
checkContentEncodingHeaderIsAbsent(greetingResponse);
// POST
Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
final String NEW_MESSAGE = "This is a new message!";
greeting.setMessage(NEW_MESSAGE);
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
restClient.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = restClient.sendRequest(request2);
greetingResponse = future2.get();
Assert.assertEquals(greetingResponse.getEntity().getMessage(), NEW_MESSAGE);
checkContentEncodingHeaderIsAbsent(greetingResponse);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestCompressionServer method testUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsNoCompressedResponsesDataProvider")
public //test update on retrieved entity
void testUpdate(RestClient client, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException, CloneNotSupportedException, URISyntaxException {
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = client.sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
String response1 = greetingResponse.getEntity().getMessage();
Assert.assertNotNull(response1);
checkContentEncodingHeaderIsAbsent(future.getResponse());
// POST
Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
greeting.setMessage(response1 + "Again");
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
client.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = client.sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, response1 + "Again");
checkContentEncodingHeaderIsAbsent(future2.getResponse());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestAssociationsResource method testCreate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider", expectedExceptions = UnsupportedOperationException.class)
@SuppressWarnings("deprecation")
public void testCreate(RootBuilderWrapper<CompoundKey, Message> builders) throws Exception {
// Associations should never support create operations. This is a bug in Rest.li that will be fixed. For now we want
// to make sure that creating and then calling getId() on the response throws an exception.
Request<EmptyRecord> request = builders.create().input(new Message().setMessage("foo")).build();
getClient().sendRequest(request).getResponse().getId();
}
Aggregations