Search in sources :

Example 76 with RestLiResponseException

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());
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 77 with RestLiResponseException

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());
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 78 with RestLiResponseException

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());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 79 with RestLiResponseException

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);
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) AsyncErrorsBuilders(com.linkedin.restli.examples.greetings.client.AsyncErrorsBuilders) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 80 with RestLiResponseException

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");
}
Also used : FlowId(org.apache.gobblin.service.FlowId) 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