Search in sources :

Example 16 with EmptyRecord

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Test(org.testng.annotations.Test)

Example 17 with EmptyRecord

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Test(org.testng.annotations.Test)

Example 18 with EmptyRecord

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);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Test(org.testng.annotations.Test)

Example 19 with EmptyRecord

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);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) CountDownLatch(java.util.concurrent.CountDownLatch) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RestLiTestAttachmentDataSource(com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource) RestLiAttachmentReader(com.linkedin.restli.common.attachments.RestLiAttachmentReader) Test(org.testng.annotations.Test)

Example 20 with EmptyRecord

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);
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) RecordTemplate(com.linkedin.data.template.RecordTemplate) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.testng.annotations.Test)

Aggregations

EmptyRecord (com.linkedin.restli.common.EmptyRecord)75 Test (org.testng.annotations.Test)62 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)33 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)15 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)12 RestException (com.linkedin.r2.message.rest.RestException)11 BeforeTest (org.testng.annotations.BeforeTest)10 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)9 CompoundKey (com.linkedin.restli.common.CompoundKey)9 RequestExecutionReport (com.linkedin.restli.server.RequestExecutionReport)9 RequestExecutionReportBuilder (com.linkedin.restli.server.RequestExecutionReportBuilder)9 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)9 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)8 CreateResponse (com.linkedin.restli.client.response.CreateResponse)7 HashMap (java.util.HashMap)7 RecordTemplate (com.linkedin.data.template.RecordTemplate)6 MyComplexKey (com.linkedin.restli.common.test.MyComplexKey)6 Key (com.linkedin.restli.server.Key)6 RoutingException (com.linkedin.restli.server.RoutingException)6 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)6