Search in sources :

Example 61 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestRestLiValidationWithProjection method testProjectionWithInvalidFields.

@Test
public void testProjectionWithInvalidFields() throws RemoteInvocationException {
    RootBuilderWrapper<Integer, ValidationDemo> wrapper = new RootBuilderWrapper<>(new AutoValidationWithProjectionBuilders());
    Request<CollectionResponse<ValidationDemo>> request = wrapper.findBy("searchWithProjection").fields(// invalid
    ValidationDemo.fields().stringA(), ValidationDemo.fields().stringB(), // invalid
    ValidationDemo.fields().includedA(), // invalid
    ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo1(), ValidationDemo.fields().UnionFieldWithInlineRecord().MyRecord().foo2(), ValidationDemo.fields().ArrayWithInlineRecord().items().bar1(), // invalid
    ValidationDemo.fields().ArrayWithInlineRecord().items().bar2(), ValidationDemo.fields().MapWithTyperefs().values().id(), // invalid
    ValidationDemo.fields().MapWithTyperefs().values().tone(), // invalid
    ValidationDemo.fields().validationDemoNext().stringA()).build();
    try {
        _restClientAuto.sendRequest(request).getResponse();
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), "ERROR :: /validationDemoNext/stringA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /includedA :: length of \"invalid, length is larger than the max\" is out of range 1...10\n" + "ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 :: field is required but not found and has no default value\n" + "ERROR :: /ArrayWithInlineRecord/0/bar2 :: field is required but not found and has no default value\n" + "ERROR :: /MapWithTyperefs/foo/tone :: field is required but not found and has no default value\n" + "ERROR :: /stringA :: field is required but not found and has no default value\n");
    }
}
Also used : AutoValidationWithProjectionBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders) CollectionResponse(com.linkedin.restli.common.CollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 62 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestRestLiValidation method testBatchGetAuto.

@Test
public void testBatchGetAuto() throws RemoteInvocationException {
    final List<Integer> ids = Arrays.asList(11, 22, 33);
    final String errorMessage = ", ERROR :: /UnionFieldWithInlineRecord/com.linkedin.restli.examples.greetings.api.myRecord/foo1 " + ":: field is required but not found and has no default value\n";
    try {
        BatchGetRequest<ValidationDemo> request = new AutoValidationDemosBuilders().batchGet().ids(ids).build();
        _restClientAuto.sendRequest(request).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        for (Integer id : ids) {
            Assert.assertTrue(e.getServiceErrorMessage().contains("Key: " + id.toString() + errorMessage));
        }
    }
    try {
        BatchGetEntityRequest<Integer, ValidationDemo> request2 = new AutoValidationDemosRequestBuilders().batchGet().ids(ids).build();
        _restClientAuto.sendRequest(request2).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        for (Integer id : ids) {
            Assert.assertTrue(e.getServiceErrorMessage().contains("Key: " + id.toString() + errorMessage));
        }
    }
}
Also used : AutoValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders) AutoValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 63 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestRestLiValidation method testBatchFinderAutoWithMultipleErrorFields.

@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithMultipleErrorFields(Object builder) throws RemoteInvocationException {
    try {
        ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(3333).setStringB("hello");
        ValidationDemoCriteria c2 = new ValidationDemoCriteria().setIntA(4444).setStringB("world");
        Request<BatchCollectionResponse<ValidationDemo>> request = new RootBuilderWrapper<Integer, ValidationDemo>(builder).batchFindBy("searchValidationDemos").setQueryParam("criteria", Arrays.asList(c1, c2)).build();
        _restClientAuto.sendRequest(request).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), "BatchCriteria: 0 Element: 0 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n");
    }
}
Also used : BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) ValidationDemoCriteria(com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 64 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestReturnEntityWithBatchPartialUpdate method testInvalidReturnEntityParameter.

/**
 * Ensures that using an invalid value for the {@link RestConstants#RETURN_ENTITY_PARAM} query parameter results
 * in a 400 bad request error response for BATCH_PARTIAL_UPDATE.
 */
@Test
@SuppressWarnings({ "Duplicates" })
public void testInvalidReturnEntityParameter() throws RemoteInvocationException {
    final long expectedId = 8L;
    Greeting expectedGreeting = new Greeting();
    expectedGreeting.setMessage("Message " + expectedId);
    expectedGreeting.setTone(Tone.FRIENDLY);
    final String invalidParamValue = "NOTaBoolean";
    BatchPartialUpdateEntityRequest<Long, Greeting> request = new PartialUpdateGreetingRequestBuilders().batchPartialUpdateAndGet().input(expectedId, PatchRequest.createFromEmptyPatchDocument()).setParam(RestConstants.RETURN_ENTITY_PARAM, invalidParamValue).build();
    try {
        getClient().sendRequest(request).getResponse();
        Assert.fail(String.format("Query parameter should cause an exception: %s=%s", RestConstants.RETURN_ENTITY_PARAM, invalidParamValue));
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode(), "Invalid response status.");
        Assert.assertTrue(e.getServiceErrorMessage().contains(String.format("Invalid \"%s\" parameter: %s", RestConstants.RETURN_ENTITY_PARAM, invalidParamValue)), "Invalid error response message");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ByteString(com.linkedin.data.ByteString) Test(org.testng.annotations.Test)

Example 65 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestReturnEntityWithBatchPartialUpdate method testBatchPartialUpdateError.

/**
 * Ensures that uncaught errors and handled correctly by the server resource and sent back as error responses.
 * This test coerces the server resource to throw an uncaught 500 error.
 */
@Test
public void testBatchPartialUpdateError() throws RemoteInvocationException, MimeTypeParseException, IOException {
    BatchPartialUpdateEntityRequest<Long, Greeting> request = new PartialUpdateGreetingRequestBuilders().batchPartialUpdateAndGet().input(3L, makeGreetingMessagePatch(";DROP TABLE")).build();
    try {
        getClient().sendRequest(request).getResponse();
        Assert.fail("Expected error response.");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreetingRequestBuilders(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingRequestBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Aggregations

RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)85 Test (org.testng.annotations.Test)75 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)30 StringMap (com.linkedin.data.template.StringMap)15 FlowId (org.apache.gobblin.service.FlowId)11 EmptyRecord (com.linkedin.restli.common.EmptyRecord)10 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)10 ExecutionException (java.util.concurrent.ExecutionException)9 RestResponse (com.linkedin.r2.message.rest.RestResponse)7 FlowConfig (org.apache.gobblin.service.FlowConfig)7 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)6 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 HashMap (java.util.HashMap)5 Schedule (org.apache.gobblin.service.Schedule)5 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)4 MockRestliResponseExceptionBuilder (com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)4 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)4 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)4