use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubCollectionUpdate(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);
// PUT
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 TestSimpleResourceHierarchy method testSubsubsimpleResourceDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubSubBuilderDataProvider")
public void testSubsubsimpleResourceDelete(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
// DELETE
Request<EmptyRecord> writeRequest = builders.delete().setPathKey("subgreetingsId", 1L).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our DELETE worked.
try {
Request<Greeting> request = builders.get().setPathKey("subgreetingsId", 1L).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
testSubsubsimpleResourceUpdate(builders);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestStreamingGreetings method testUpdateReturnAttachments.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testUpdateReturnAttachments(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
try {
//This will be echoed back in the form of an attachment.
final String headerAndAttachment = "someValue";
final Request<EmptyRecord> updateRequest = builders.update().id(1l).input(new Greeting()).setHeader("getHeader", headerAndAttachment).build();
sendNonTypicalRequestAndVerifyAttachments(updateRequest, headerAndAttachment);
} catch (Exception exception) {
Assert.fail();
}
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestStreamingGreetings method sendNonTypicalRequestAndVerifyAttachments.
private void sendNonTypicalRequestAndVerifyAttachments(final Request<EmptyRecord> emptyRecordRequest, final String headerAndAttachment) throws Exception {
final Response<EmptyRecord> getResponse = getClient().sendRequest(emptyRecordRequest).getResponse();
Assert.assertEquals(getResponse.getStatus(), 200);
Assert.assertTrue(getResponse.hasAttachments(), "We must have some response attachments");
RestLiAttachmentReader attachmentReader = getResponse.getAttachmentReader();
final CountDownLatch latch = new CountDownLatch(1);
final GreetingBlobReaderCallback greetingBlobReaderCallback = new GreetingBlobReaderCallback(latch);
attachmentReader.registerAttachmentReaderCallback(greetingBlobReaderCallback);
latch.await(3000, TimeUnit.SECONDS);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().size(), 1);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().get(0), ByteString.copy(headerAndAttachment.getBytes()));
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestTyperefKeysResource method testCreate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
@SuppressWarnings("deprecation")
public void testCreate(RestliRequestOptions requestOptions) throws RemoteInvocationException {
Greeting greeting = new Greeting().setId(1L).setMessage("Foo").setTone(Tone.FRIENDLY);
CreateRequest<Greeting> req = new TyperefKeysBuilders(requestOptions).create().input(greeting).build();
Response<EmptyRecord> resp = getClient().sendRequest(req).getResponse();
Assert.assertEquals(resp.getId(), "1");
}
Aggregations