use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestExceptionsResource method testCreateError.
@SuppressWarnings("deprecation")
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testCreateError(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws Exception {
Response<EmptyRecord> response = null;
RestLiResponseException exception = null;
try {
Request<EmptyRecord> createRequest = builders.create().input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING)).build();
ResponseFuture<EmptyRecord> future;
if (explicit) {
future = getClient().sendRequest(createRequest, errorHandlingBehavior);
} else {
future = getClient().sendRequest(createRequest);
}
response = future.getResponse();
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
Assert.fail("expected exception");
}
} catch (RestLiResponseException e) {
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
exception = e;
} else {
Assert.fail("not expected exception");
}
}
if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) {
Assert.assertNotNull(response);
Assert.assertTrue(response.hasError());
exception = response.getError();
Assert.assertEquals(response.getStatus(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
Assert.assertNull(response.getEntity());
}
Assert.assertNotNull(exception);
Assert.assertFalse(exception.hasDecodedResponse());
Assert.assertEquals(exception.getStatus(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
Assert.assertEquals(exception.getServiceErrorMessage(), "I will not tolerate your insolence!");
Assert.assertEquals(exception.getServiceErrorCode(), 999);
Assert.assertEquals(exception.getErrorSource(), RestConstants.HEADER_VALUE_ERROR);
Assert.assertEquals(exception.getErrorDetails().getString("reason"), "insultingGreeting");
Assert.assertTrue(exception.getServiceErrorStackTrace().startsWith("com.linkedin.restli.server.RestLiServiceException [HTTP Status:406, serviceErrorCode:999]: I will not tolerate your insolence!"), "stacktrace mismatch:" + exception.getStackTrace());
Assert.assertFalse(exception.hasCode());
Assert.assertFalse(exception.hasDocUrl());
Assert.assertFalse(exception.hasRequestId());
Assert.assertEquals(exception.getErrorDetailType(), EmptyRecord.class.getCanonicalName());
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestExceptionsResource3 method testUpdate.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testUpdate(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws Exception {
Response<EmptyRecord> response = null;
RestLiResponseException exception = null;
try {
Request<EmptyRecord> request = builders.update().id(11L).input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING)).build();
ResponseFuture<EmptyRecord> future;
if (explicit) {
future = getClient().sendRequest(request, errorHandlingBehavior);
} else {
future = getClient().sendRequest(request);
}
response = future.getResponse();
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
Assert.fail("expected exception");
}
} catch (RestLiResponseException e) {
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
exception = e;
} else {
Assert.fail("not expected exception");
}
}
if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) {
Assert.assertNotNull(response);
Assert.assertTrue(response.hasError());
exception = response.getError();
Assert.assertEquals(response.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
Assert.assertNull(response.getEntity());
}
Assert.assertNotNull(exception);
Assert.assertTrue(exception.hasDecodedResponse());
Assert.assertEquals(exception.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestExceptionsResource3 method testGet404.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testGet404(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Response<Greeting> response = null;
RestLiResponseException exception = null;
try {
Request<Greeting> readRequest = builders.get().id(1L).build();
ResponseFuture<Greeting> future;
if (explicit) {
future = getClient().sendRequest(readRequest, errorHandlingBehavior);
} else {
future = getClient().sendRequest(readRequest);
}
response = future.getResponse();
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
Assert.fail("expected exception");
}
} catch (RestLiResponseException e) {
if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR) {
exception = e;
} else {
Assert.fail("not expected exception");
}
}
if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS) {
Assert.assertNotNull(response);
Assert.assertTrue(response.hasError());
exception = response.getError();
Assert.assertEquals(response.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
Assert.assertNull(response.getEntity());
}
Assert.assertNotNull(exception);
Assert.assertFalse(exception.hasDecodedResponse());
Assert.assertEquals(exception.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestAsyncExceptions method testPromise.
@Test(dataProvider = "exceptionProvider")
public void testPromise(String key, int expectedStatus) throws RemoteInvocationException {
AsyncErrorsBuilders builder = new AsyncErrorsBuilders();
Request<Greeting> request = builder.actionPromise().paramId(key).build();
try {
getClient().sendRequest(request).getResponse();
Assert.fail("This request should have failed.");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), expectedStatus);
}
}
use of com.linkedin.restli.client.RestLiResponseException in project incubator-gobblin by apache.
the class GobblinServiceHATest method testBadGet.
@Test(dependsOnMethods = "testDelete")
public void testBadGet() throws Exception {
logger.info("+++++++++++++++++++ testBadGet START");
FlowId flowId = new FlowId().setFlowGroup(TEST_DUMMY_GROUP_NAME_1).setFlowName(TEST_DUMMY_FLOW_NAME_1);
try {
this.node1FlowConfigClient.getFlowConfig(flowId);
Assert.fail("Get should have raised a 404 error");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.NOT_FOUND_404);
}
try {
this.node2FlowConfigClient.getFlowConfig(flowId);
Assert.fail("Get should have raised a 404 error");
} catch (RestLiResponseException e) {
Assert.assertEquals(e.getStatus(), HttpStatus.NOT_FOUND_404);
}
logger.info("+++++++++++++++++++ testBadGet END");
}
Aggregations