Search in sources :

Example 66 with EmptyRecord

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

Example 67 with EmptyRecord

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

Example 68 with EmptyRecord

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();
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) ByteString(com.linkedin.data.ByteString) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) Test(org.testng.annotations.Test)

Example 69 with EmptyRecord

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()));
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) CountDownLatch(java.util.concurrent.CountDownLatch) RestLiAttachmentReader(com.linkedin.restli.common.attachments.RestLiAttachmentReader)

Example 70 with EmptyRecord

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");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) TyperefKeysBuilders(com.linkedin.restli.examples.greetings.client.TyperefKeysBuilders) 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