use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingsClient method testCookbook.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public //test cookbook example from quickstart wiki
void testCookbook(RootBuilderWrapper<Long, Greeting> builders) throws Exception {
// GET
Request<Greeting> request = builders.get().id(1L).build();
ResponseFuture<Greeting> future = getClient().sendRequest(request);
Response<Greeting> greetingResponse = future.getResponse();
Assert.assertNotNull(greetingResponse.getEntity().getMessage());
// 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();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Assert.assertEquals(greetingResponse.getEntity().getMessage(), NEW_MESSAGE);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingsClient method testUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public //test update on retrieved entity
void testUpdate(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();
String response1 = greetingResponse.getEntity().getMessage();
Assert.assertNotNull(response1);
// POST
Greeting greeting = new Greeting(greetingResponse.getEntity().data().copy());
greeting.setMessage(response1 + "Again");
Request<EmptyRecord> writeRequest = builders.update().id(1L).input(greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request2 = builders.get().id(1L).build();
ResponseFuture<Greeting> future2 = getClient().sendRequest(request2);
String response2 = future2.getResponse().getEntity().getMessage();
Assert.assertEquals(response2, response1 + "Again");
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestGreetingsClient method testCreateWithNullId.
@SuppressWarnings("deprecation")
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testCreateWithNullId(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Request<EmptyRecord> request = builders.create().input(new Greeting().setId(1L).setMessage("foo")).setQueryParam("isNullId", true).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
Assert.assertNull(response.getId());
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubsubsimpleResourcePartialUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubSubBuilderDataProvider")
public void testSubsubsimpleResourcePartialUpdate(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Message1");
greeting.setTone(Tone.SINCERE);
greeting.setId(1L);
PatchRequest<Greeting> patch = PatchGenerator.diffEmpty(greeting);
// PUT
Request<EmptyRecord> writeRequest = builders.partialUpdate().setPathKey("subgreetingsId", 1L).input(patch).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<Greeting> request = builders.get().setPathKey("subgreetingsId", 1L).build();
Response<Greeting> response = getClient().sendRequest(request).getResponse();
greeting = response.getEntity();
Assert.assertEquals(greeting.getTone(), Tone.SINCERE);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testRootSimpleResourceDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceDelete(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
// DELETE
Request<EmptyRecord> writeRequest = builders.delete().build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our DELETE worked.
try {
Request<Greeting> request = builders.get().build();
Response<Greeting> response = getClient().sendRequest(request).getResponse();
Greeting greeting = response.getEntity();
Assert.fail("Entity should have been removed.");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
}
//Restore initial state
testRootSimpleResourceUpdate(builders);
}
Aggregations