Search in sources :

Example 1 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 2 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)

Example 3 with Greeting

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

the class TestMockFailedResponseFutureBuilder method testBuildWithErrorResponseTreatServerErrorAsSuccess.

@Test
public void testBuildWithErrorResponseTreatServerErrorAsSuccess() {
    ResponseFuture<Greeting> future = buildWithErrorResponse(ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS);
    try {
        Response<Greeting> response = future.getResponse();
        Assert.assertNull(response.getEntity());
        Assert.assertEquals(response.getStatus(), 404);
        RestLiResponseException restLiResponseException = response.getError();
        Assert.assertEquals(restLiResponseException.getStatus(), 404);
        Assert.assertEquals(restLiResponseException.getServiceErrorMessage(), "foo");
    } catch (Exception e) {
        Assert.fail("No exception should have been thrown!");
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 4 with Greeting

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

the class TestDataAssert method testEqualRecordTemplates.

@Test
public void testEqualRecordTemplates() {
    String message = "foo";
    Long id = 1L;
    Greeting actual = new Greeting().setMessage(message).setId(id);
    Greeting expected = new Greeting().setMessage(message).setId(id);
    DataAssert.assertRecordTemplateDataEqual(actual, expected, null);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) Test(org.testng.annotations.Test)

Example 5 with Greeting

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

the class TestDataAssert method testUnequalCollections.

@Test
public void testUnequalCollections() {
    Greeting g1 = new Greeting().setMessage("foo").setId(1L);
    Greeting g2 = new Greeting().setMessage("foo").setId(2L);
    List<Greeting> actual = Arrays.asList(g1, g2);
    List<Greeting> expected = Arrays.asList(g1, new Greeting().setId(3L).setMessage("foo"));
    String indexErrorMessage = "are not equal at index 1";
    String propertyErrorMessage = "Mismatch on property \"id\", expected:<3> but was:<2>";
    try {
        DataAssert.assertRecordTemplateCollectionsEqual(actual, expected, null);
    } catch (Throwable t) {
        Assert.assertTrue(t.getMessage().contains(indexErrorMessage));
        Assert.assertTrue(t.getMessage().contains(propertyErrorMessage));
    }
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) 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