use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubsubsimpleResourceUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubSubBuilderDataProvider")
public void testSubsubsimpleResourceUpdate(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Message1");
greeting.setTone(Tone.INSULTING);
greeting.setId(1L);
// PUT
Request<EmptyRecord> writeRequest = builders.update().setPathKey("subgreetingsId", 1L).input(greeting).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.INSULTING);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testRootSimpleResourcePartialUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourcePartialUpdate(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Message1");
greeting.setTone(Tone.SINCERE);
greeting.setId(12345L);
PatchRequest<Greeting> patch = PatchGenerator.diffEmpty(greeting);
// PUT
Request<EmptyRecord> writeRequest = builders.partialUpdate().input(patch).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our PUT worked.
Request<Greeting> request = builders.get().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 testRootSimpleResourceUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceUpdate(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
Greeting greeting = new Greeting();
greeting.setMessage("Message1");
greeting.setTone(Tone.INSULTING);
greeting.setId(12345L);
// PUT
Request<EmptyRecord> writeRequest = builders.update().input(greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our PUT worked.
Request<Greeting> request = builders.get().build();
Response<Greeting> response = getClient().sendRequest(request).getResponse();
greeting = response.getEntity();
Assert.assertEquals(greeting.getTone(), Tone.INSULTING);
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestStreamingGreetings method fullStreamTest.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void fullStreamTest(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
//Perform a create to the server to store some bytes via an attachment.
final byte[] clientSuppliedBytes = "ClientSupplied".getBytes();
final RestLiTestAttachmentDataSource greetingAttachment = new RestLiTestAttachmentDataSource("1", ByteString.copy(clientSuppliedBytes));
final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
methodBuilderWrapper.appendSingleAttachment(greetingAttachment);
//Provide a header to verify the server's ability to transform the first part into the RestRequest.
methodBuilderWrapper.setHeader("createHeader", "createHeaderValue");
final Greeting greeting = new Greeting().setMessage("A greeting with an attachment");
final Request<EmptyRecord> createRequest = methodBuilderWrapper.input(greeting).build();
try {
final Response<EmptyRecord> createResponse = getClient().sendRequest(createRequest).getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
//Verify that headers propagate properly.
Assert.assertEquals(createResponse.getHeader("createHeader"), "createHeaderValue");
} catch (final RestLiResponseException responseException) {
Assert.fail("We should not reach here!", responseException);
}
//Then perform a GET and verify the bytes are present
try {
final Request<Greeting> getRequest = builders.get().id(1l).setHeader("getHeader", "getHeaderValue").build();
final Response<Greeting> getResponse = getClient().sendRequest(getRequest).getResponse();
Assert.assertEquals(getResponse.getStatus(), 200);
//Verify that headers propagate properly.
Assert.assertEquals(getResponse.getHeader("getHeader"), "getHeaderValue");
Assert.assertEquals(getResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE), RestConstants.HEADER_VALUE_APPLICATION_JSON);
Assert.assertEquals(getResponse.getEntity().getMessage(), "Your greeting has an attachment since you were kind and decided you wanted to read it!");
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);
try {
latch.await(3000, TimeUnit.SECONDS);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().size(), 1);
Assert.assertEquals(greetingBlobReaderCallback.getAttachmentList().get(0), ByteString.copy(clientSuppliedBytes));
} catch (Exception exception) {
Assert.fail();
}
} catch (final RestLiResponseException responseException) {
Assert.fail("We should not reach here!", responseException);
}
}
use of com.linkedin.restli.common.EmptyRecord in project rest.li by linkedin.
the class TestRestLiResponseData method testCollectionResponseEnvelopeUpdates.
@Test(dataProvider = "collectionResponseEnvelopesProvider")
@SuppressWarnings("unchecked")
public void testCollectionResponseEnvelopeUpdates(RestLiResponseDataImpl responseData) {
CollectionResponseEnvelope responseEnvelope = responseData.getCollectionResponseEnvelope();
Assert.assertFalse(responseData.isErrorResponse());
Assert.assertEquals(responseEnvelope.getCollectionResponse(), Collections.<EmptyRecord>emptyList());
Assert.assertEquals(responseEnvelope.getCollectionResponsePaging(), new CollectionMetadata());
Assert.assertEquals(responseEnvelope.getCollectionResponseCustomMetadata(), new EmptyRecord());
// Swap to exception
responseData.setException(exception500);
Assert.assertNull(responseEnvelope.getCollectionResponse());
Assert.assertNull(responseEnvelope.getCollectionResponseCustomMetadata());
Assert.assertNull(responseEnvelope.getCollectionResponsePaging());
Assert.assertEquals(responseData.getServiceException(), exception500);
Assert.assertEquals(responseData.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR);
// Swap back
responseEnvelope.setCollectionResponse(new ArrayList<RecordTemplate>(), new CollectionMetadata(), new EmptyRecord(), HttpStatus.S_200_OK);
Assert.assertFalse(responseData.isErrorResponse());
Assert.assertEquals(responseEnvelope.getCollectionResponse(), Collections.<EmptyRecord>emptyList());
Assert.assertEquals(responseEnvelope.getCollectionResponsePaging(), new CollectionMetadata());
Assert.assertEquals(responseEnvelope.getCollectionResponseCustomMetadata(), new EmptyRecord());
// Check mutability when available
List<EmptyRecord> temp = (List<EmptyRecord>) responseEnvelope.getCollectionResponse();
temp.add(new EmptyRecord());
Assert.assertEquals(responseEnvelope.getCollectionResponse().size(), 1);
}
Aggregations