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();
}
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
}
}
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!");
}
}
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);
}
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));
}
}
Aggregations