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");
}
}
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));
}
}
}
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");
}
}
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");
}
}
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());
}
}
Aggregations