Search in sources :

Example 21 with RootBuilderWrapper

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

the class TestRestLiValidationWithProjection method provideProjectionWithNonexistentFieldsData.

@DataProvider
private Object[][] provideProjectionWithNonexistentFieldsData() {
    RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<>(new AutoValidationWithProjectionBuilders());
    Request<ValidationDemo> getRequest = wrapper.get().id(1).fields(new PathSpec("nonexistentFieldFooBar")).build();
    Request<CollectionResponse<ValidationDemo>> getAllRequest = wrapper.getAll().fields(new PathSpec("nonexistentFieldFooBar")).build();
    Request<CollectionResponse<ValidationDemo>> findRequest = wrapper.findBy("searchWithProjection").fields(new PathSpec("nonexistentFieldFooBar")).build();
    return new Object[][] { { getRequest }, { getAllRequest }, { findRequest } };
}
Also used : AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) PathSpec(com.linkedin.data.schema.PathSpec) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) DataProvider(org.testng.annotations.DataProvider)

Example 22 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)

Example 23 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 24 with RootBuilderWrapper

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

the class TestRestLiValidationFromClient method testPartialUpdateFailure.

@Test(dataProvider = "providePartialUpdateFailureData")
public void testPartialUpdateFailure(Object builder, String patch, String errorMessage) {
    PatchRequest<ValidationDemo> patchRequest = PatchBuilder.buildPatchFromString(patch);
    ValidationResult result = new RootBuilderWrapper<Integer, ValidationDemo>(builder, ValidationDemo.class).partialUpdate().validateInput(patchRequest);
    Assert.assertEquals(result.isValid(), false);
    Assert.assertEquals(result.getMessages().toString(), errorMessage);
}
Also used : RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) ValidationResult(com.linkedin.data.schema.validation.ValidationResult) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 25 with RootBuilderWrapper

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

the class TestStreamingGreetings method resourceMethodDoesNotAcceptAttachments.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void resourceMethodDoesNotAcceptAttachments(final RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    // Resource method does not desire request attachments. Assert that all the attachments are drained and that a 400
    // bad request is observed.
    final RestLiTestAttachmentDataSource greetingAttachment = new RestLiTestAttachmentDataSource("1", ByteString.copyString("clientData", Charset.defaultCharset()));
    RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, Object> methodBuilderWrapper = builders.action("actionNoAttachmentsAllowed");
    methodBuilderWrapper.appendSingleAttachment(greetingAttachment);
    final Request<Object> request = methodBuilderWrapper.build();
    try {
        getClient().sendRequest(request).getResponse().getEntity();
        Assert.fail();
    } catch (final RestLiResponseException responseException) {
        Assert.assertEquals(responseException.getStatus(), 400);
        Assert.assertEquals(responseException.getServiceErrorMessage(), "Resource method endpoint invoked does not accept any request attachments.");
    }
    // Then verify the response and request attachments were fully absorbed.
    Assert.assertTrue(greetingAttachment.finished());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RestLiTestAttachmentDataSource(com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource) Test(org.testng.annotations.Test)

Aggregations

RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)25 Test (org.testng.annotations.Test)20 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)11 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)9 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)8 CollectionResponse (com.linkedin.restli.common.CollectionResponse)8 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)7 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)6 EmptyRecord (com.linkedin.restli.common.EmptyRecord)6 PathSpec (com.linkedin.data.schema.PathSpec)3 CreateIdRequestBuilder (com.linkedin.restli.client.CreateIdRequestBuilder)2 CreateResponse (com.linkedin.restli.client.response.CreateResponse)2 BatchCreateIdEntityResponse (com.linkedin.restli.common.BatchCreateIdEntityResponse)2 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)2 IdResponse (com.linkedin.restli.common.IdResponse)2 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)2 RestLiTestAttachmentDataSource (com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource)2 DataProvider (org.testng.annotations.DataProvider)2 FutureCallback (com.linkedin.common.callback.FutureCallback)1