Search in sources :

Example 41 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestExceptionsResource2 method testGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testGet(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    Response<Greeting> response = null;
    RestLiResponseException exception = null;
    try {
        final Request<Greeting> req = builders.get().id(1L).build();
        ResponseFuture<Greeting> future;
        if (explicit) {
            future = getClient().sendRequest(req, errorHandlingBehavior);
        } else {
            future = getClient().sendRequest(req);
        }
        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_500_INTERNAL_SERVER_ERROR.getCode());
        Assert.assertNotNull(response.getEntity());
        Assert.assertEquals(response.getEntity(), new Greeting().setMessage("Hello, sorry for the mess"));
    }
    Assert.assertNotNull(exception);
    Assert.assertTrue(exception.hasDecodedResponse());
    Assert.assertEquals(exception.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
    final DataMap respEntityMap = DataMapUtils.readMap(exception.getResponse());
    Assert.assertEquals(respEntityMap, new Greeting().setMessage("Hello, sorry for the mess").data());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 42 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestRootBuilderWrapper method testBuilderVersion.

@Test
public void testBuilderVersion() {
    RootBuilderWrapper<Long, Greeting> rootBuilderWrapper1 = new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders());
    RootBuilderWrapper<Long, Greeting> rootBuilderWrapper2 = new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders());
    Assert.assertFalse(rootBuilderWrapper1.areRestLi2Builders());
    Assert.assertTrue(rootBuilderWrapper2.areRestLi2Builders());
    Assert.assertFalse(rootBuilderWrapper1.get().isRestLi2Builder());
    Assert.assertTrue(rootBuilderWrapper2.get().isRestLi2Builder());
    RootBuilderWrapper<Long, Greeting> dummyBuilder = new RootBuilderWrapper<Long, Greeting>(new MyRequestBuilders());
    Assert.assertFalse(dummyBuilder.areRestLi2Builders());
}
Also used : GreetingsBuilders(com.linkedin.restli.examples.greetings.client.GreetingsBuilders) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) GreetingsRequestBuilders(com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders) Test(org.testng.annotations.Test)

Example 43 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.

the class TestTyperefKeysResource method testCreateId.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testCreateId(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Greeting greeting = new Greeting().setId(1L).setMessage("Foo").setTone(Tone.FRIENDLY);
    CreateIdRequest<Long, Greeting> req = new TyperefKeysRequestBuilders(requestOptions).create().input(greeting).build();
    Response<IdResponse<Long>> resp = getClient().sendRequest(req).getResponse();
    Assert.assertEquals(resp.getEntity().getId(), new Long(1L));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) IdResponse(com.linkedin.restli.common.IdResponse) TyperefKeysRequestBuilders(com.linkedin.restli.examples.greetings.client.TyperefKeysRequestBuilders) Test(org.testng.annotations.Test)

Example 44 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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 45 with Greeting

use of com.linkedin.restli.examples.greetings.api.Greeting 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)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)250 Test (org.testng.annotations.Test)195 CollectionResponse (com.linkedin.restli.common.CollectionResponse)59 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)33 EmptyRecord (com.linkedin.restli.common.EmptyRecord)33 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)20 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)18 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)12 EntityResponse (com.linkedin.restli.common.EntityResponse)12 BatchResponse (com.linkedin.restli.common.BatchResponse)11 RestLiIntegrationTest (com.linkedin.restli.examples.RestLiIntegrationTest)11 IdResponse (com.linkedin.restli.common.IdResponse)10 GreetingsRequestBuilders (com.linkedin.restli.examples.greetings.client.GreetingsRequestBuilders)10 GreetingsBuilders (com.linkedin.restli.examples.greetings.client.GreetingsBuilders)9 ConsistentHashKeyMapper (com.linkedin.d2.balancer.util.hashing.ConsistentHashKeyMapper)8 Response (com.linkedin.restli.client.Response)8 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)8 ErrorResponse (com.linkedin.restli.common.ErrorResponse)8