Search in sources :

Example 6 with FilterResourceModelImpl

use of com.linkedin.restli.internal.server.filter.FilterResourceModelImpl in project rest.li by linkedin.

the class TestRestLiValidationFilter method testSkipRequestValidation.

/**
 * Ensures that the validation filter skips request validation by feeding it with invalid data, and ensuring that it
 * never throws an error.
 */
@Test(dataProvider = "invalidRequests")
@SuppressWarnings({ "unchecked" })
public void testSkipRequestValidation(ResourceModel resourceModel, ResourceMethod resourceMethod, RestLiRequestData restLiRequestData) {
    when(filterRequestContext.getRequestData()).thenReturn(restLiRequestData);
    when(filterRequestContext.getMethodType()).thenReturn(resourceMethod);
    when(filterRequestContext.getFilterResourceModel()).thenReturn(new FilterResourceModelImpl(resourceModel));
    when(filterRequestContext.getRestliProtocolVersion()).thenReturn(AllProtocolVersions.LATEST_PROTOCOL_VERSION);
    RestLiValidationFilter validationFilter = new RestLiValidationFilter(Collections.emptyList(), new MockValidationErrorHandler()) {

        @Override
        protected boolean shouldValidateOnRequest(FilterRequestContext requestContext) {
            return false;
        }
    };
    try {
        validationFilter.onRequest(filterRequestContext);
    } catch (RestLiServiceException ex) {
        Assert.fail("An unexpected exception was thrown on request in the validation filter.", ex);
    }
}
Also used : FilterResourceModelImpl(com.linkedin.restli.internal.server.filter.FilterResourceModelImpl) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) Test(org.testng.annotations.Test)

Aggregations

FilterResourceModelImpl (com.linkedin.restli.internal.server.filter.FilterResourceModelImpl)6 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)5 Test (org.testng.annotations.Test)5 ResourceMethod (com.linkedin.restli.common.ResourceMethod)2 RestLiRequestDataImpl (com.linkedin.restli.server.RestLiRequestDataImpl)2 DataMap (com.linkedin.data.DataMap)1 MockBadRequest (com.linkedin.restli.server.errors.MockBadRequest)1 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)1 BeforeMethod (org.testng.annotations.BeforeMethod)1