Search in sources :

Example 1 with MockFailedResponseFutureBuilder

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

the class TestMockFailedResponseFutureBuilder method buildWithErrorResponse.

private ResponseFuture<Greeting> buildWithErrorResponse(ErrorHandlingBehavior errorHandlingBehavior) {
    MockFailedResponseFutureBuilder<Long, Greeting> builder = new MockFailedResponseFutureBuilder<Long, Greeting>();
    ErrorResponse errorResponse = new ErrorResponse().setStatus(404).setMessage("foo");
    builder.setErrorResponse(errorResponse).setErrorHandlingBehavior(errorHandlingBehavior);
    return builder.build();
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) MockFailedResponseFutureBuilder(com.linkedin.restli.client.testutils.MockFailedResponseFutureBuilder) ErrorResponse(com.linkedin.restli.common.ErrorResponse)

Example 2 with MockFailedResponseFutureBuilder

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

the class TestMockFailedResponseFutureBuilder method testOnlyOneOfErrorResponseOrEntityIsSet.

@Test
public void testOnlyOneOfErrorResponseOrEntityIsSet() {
    MockFailedResponseFutureBuilder<Long, Greeting> builder = new MockFailedResponseFutureBuilder<Long, Greeting>();
    builder.setEntity(new Greeting());
    try {
        builder.setErrorResponse(new ErrorResponse());
        Assert.fail();
    } catch (IllegalStateException e) {
    // expected
    }
    builder = new MockFailedResponseFutureBuilder<Long, Greeting>();
    builder.setErrorResponse(new ErrorResponse());
    try {
        builder.setEntity(new Greeting());
        Assert.fail();
    } catch (IllegalStateException e) {
    // expected
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) MockFailedResponseFutureBuilder(com.linkedin.restli.client.testutils.MockFailedResponseFutureBuilder) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 3 with MockFailedResponseFutureBuilder

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

the class TestMockFailedResponseFutureBuilder method testBuildIllegalStatus.

@Test
@SuppressWarnings("rawtypes")
public void testBuildIllegalStatus() {
    MockFailedResponseFutureBuilder builder = new MockFailedResponseFutureBuilder();
    try {
        builder.setStatus(200);
        Assert.fail("Setting a 2xx status should have failed!");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : MockFailedResponseFutureBuilder(com.linkedin.restli.client.testutils.MockFailedResponseFutureBuilder) Test(org.testng.annotations.Test)

Example 4 with MockFailedResponseFutureBuilder

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

the class TestMockFailedResponseFutureBuilder method buildWithEntity.

private ResponseFuture<Greeting> buildWithEntity(ErrorHandlingBehavior errorHandlingBehavior) {
    MockFailedResponseFutureBuilder<Long, Greeting> builder = new MockFailedResponseFutureBuilder<Long, Greeting>();
    Greeting greeting = new Greeting().setId(1L).setMessage("foo");
    builder.setEntity(greeting).setErrorHandlingBehavior(errorHandlingBehavior).setStatus(500);
    return builder.build();
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) MockFailedResponseFutureBuilder(com.linkedin.restli.client.testutils.MockFailedResponseFutureBuilder)

Aggregations

MockFailedResponseFutureBuilder (com.linkedin.restli.client.testutils.MockFailedResponseFutureBuilder)4 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 ErrorResponse (com.linkedin.restli.common.ErrorResponse)2 Test (org.testng.annotations.Test)2