Search in sources :

Example 11 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestNullGreetingsClient method testNullHttpStatusCreateResponse.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testNullHttpStatusCreateResponse(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    //Forces the server to return a valid CreateResponse but with a null HttpStatus inside of it
    final RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> methodBuilderWrapper = builders.create();
    final Greeting illGreeting = new Greeting().setMessage("nullHttpStatus").setTone(Tone.INSULTING);
    createAndAssertNullMessages(methodBuilderWrapper, illGreeting);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) Test(org.testng.annotations.Test)

Example 12 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper 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 13 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestDebugRequestHandlers method createNewGreetingOnTheServer.

private Long createNewGreetingOnTheServer(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Greeting newGreeting = new Greeting().setMessage("New Greeting!").setTone(Tone.FRIENDLY);
    RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilderWrapper = builders.create();
    Long createdId;
    if (createBuilderWrapper.isRestLi2Builder()) {
        Object objBuilder = createBuilderWrapper.getBuilder();
        @SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
        CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(newGreeting).build();
        Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
        createdId = response.getEntity().getId();
    } else {
        Request<EmptyRecord> request = createBuilderWrapper.input(newGreeting).build();
        Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
        @SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
        createdId = createResponse.getId();
    }
    return createdId;
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) EmptyRecord(com.linkedin.restli.common.EmptyRecord) IdResponse(com.linkedin.restli.common.IdResponse) CreateResponse(com.linkedin.restli.client.response.CreateResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) CreateIdRequestBuilder(com.linkedin.restli.client.CreateIdRequestBuilder)

Example 14 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestRestLiValidationFromClient method testUpdateFailure.

@Test(dataProvider = "provideUpdateFailureData")
public void testUpdateFailure(Object builder, ValidationDemo validationDemo, String errorMessage) {
    ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).update().validateInput(validationDemo);
    Assert.assertEquals(result.isValid(), false);
    Assert.assertTrue(result.getMessages().toString().contains(errorMessage));
}
Also used : RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) Test(org.testng.annotations.Test)

Example 15 with RootBuilderWrapper

use of com.linkedin.restli.test.util.RootBuilderWrapper in project rest.li by linkedin.

the class TestRestLiValidationFromClient method testCreateFailure.

@Test(dataProvider = "provideCreateFailureData")
public void testCreateFailure(Object builder, ValidationDemo validationDemo, String errorMessage) {
    ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).create().validateInput(validationDemo);
    Assert.assertEquals(result.isValid(), false);
    Assert.assertTrue(result.getMessages().toString().contains(errorMessage));
}
Also used : RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) Test(org.testng.annotations.Test)

Aggregations

RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)19 Test (org.testng.annotations.Test)16 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)8 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)7 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)7 EmptyRecord (com.linkedin.restli.common.EmptyRecord)6 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)3 CreateIdRequestBuilder (com.linkedin.restli.client.CreateIdRequestBuilder)2 CreateResponse (com.linkedin.restli.client.response.CreateResponse)2 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 IdResponse (com.linkedin.restli.common.IdResponse)2 RestLiTestAttachmentDataSource (com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1 None (com.linkedin.common.util.None)1 DataMap (com.linkedin.data.DataMap)1 PathSpec (com.linkedin.data.schema.PathSpec)1 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)1 CompressionConfig (com.linkedin.r2.filter.CompressionConfig)1