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