use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testGetRequestFailure.
@Test
public void testGetRequestFailure() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Greeting> result = greetings.get(-1L);
CompletableFuture<Greeting> future = result.toCompletableFuture();
try {
future.get(5000, TimeUnit.MILLISECONDS);
Assert.fail("Expected failure");
} catch (ExecutionException e) {
Assert.assertEquals(((RestLiResponseException) e.getCause()).getStatus(), 404);
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testRootSimpleResourceDelete.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceDelete(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
// DELETE
Request<EmptyRecord> writeRequest = builders.delete().build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our DELETE worked.
try {
Request<Greeting> request = builders.get().build();
Response<Greeting> response = getClient().sendRequest(request).getResponse();
Greeting greeting = response.getEntity();
Assert.fail("Entity should have been removed.");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
}
// Restore initial state
testRootSimpleResourceUpdate(builders);
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestTyperefCustomDoubleAssociationKeyResource method testGet.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException, URISyntaxException {
HashMap<String, CompoundKey.TypeInfo> keyParts = new HashMap<>();
keyParts.put("src", new CompoundKey.TypeInfo(CustomDouble.class, CustomDoubleRef.class));
keyParts.put("dest", new CompoundKey.TypeInfo(URI.class, UriRef.class));
GetRequestBuilder<CompoundKey, Message> getBuilder = new GetRequestBuilder<>("typerefCustomDoubleAssociationKeyResource", Message.class, new ResourceSpecImpl(EnumSet.of(ResourceMethod.GET), new HashMap<>(), new HashMap<>(), CompoundKey.class, null, null, Message.class, keyParts), requestOptions);
final String[] stringArray = { "foo" };
GetRequest<Message> req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.0)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
Message result = resp.getEntity();
Assert.assertEquals(result.getId(), "100.0->www.linkedin.com");
Assert.assertEquals(result.getMessage(), String.format("I need some $20. Array contents %s.", Arrays.asList(stringArray)));
// key validation failure scenario
try {
req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.02)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
REST_CLIENT.sendRequest(req).getResponse();
} catch (RestLiResponseException ex) {
Assert.assertEquals(ex.getServiceErrorMessage(), "Input field validation failure, reason: ERROR :: :: \"100.02\" does not match [0-9]*\\.[0-9]\n");
Assert.assertEquals(ex.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinderAutoWithOverLengthField.
@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithOverLengthField(Object builder) throws RemoteInvocationException {
try {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(2222).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" + "BatchCriteria: 0 Element: 1 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n");
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestRestLiValidation method testBatchFinderAutoWithMissingField.
@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithMissingField(Object builder) throws RemoteInvocationException {
try {
ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(1111).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 :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringB :: field is required but not found and has no default value\n");
}
}
Aggregations