use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestDebugRequestHandlers method createNewGreetingOnTheServer.
private Long createNewGreetingOnTheServer(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Greeting newGreeting = new Greeting().setMessage("New Greeting!").setTone(Tone.FRIENDLY);
RootBuilderWrapper.MethodBuilderWrapper<Long, Greeting, EmptyRecord> createBuilderWrapper = builders.create();
Long createdId;
if (createBuilderWrapper.isRestLi2Builder()) {
Object objBuilder = createBuilderWrapper.getBuilder();
@SuppressWarnings("unchecked") CreateIdRequestBuilder<Long, Greeting> createIdRequestBuilder = (CreateIdRequestBuilder<Long, Greeting>) objBuilder;
CreateIdRequest<Long, Greeting> request = createIdRequestBuilder.input(newGreeting).build();
Response<IdResponse<Long>> response = getClient().sendRequest(request).getResponse();
createdId = response.getEntity().getId();
} else {
Request<EmptyRecord> request = createBuilderWrapper.input(newGreeting).build();
Response<EmptyRecord> response = getClient().sendRequest(request).getResponse();
@SuppressWarnings("unchecked") CreateResponse<Long> createResponse = (CreateResponse<Long>) response.getEntity();
createdId = createResponse.getId();
}
return createdId;
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestComplexArrayResource method testBatchGetEntity.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versionWithRequestOptionsDataProvider")
public void testBatchGetEntity(ProtocolVersion version, RestliRequestOptions options) throws RemoteInvocationException {
List<ComplexResourceKey<ComplexArray, ComplexArray>> complexKeys = getBatchCompleKeys();
ComplexArrayRequestBuilders builders = new ComplexArrayRequestBuilders(options);
Request<BatchKVResponse<ComplexResourceKey<ComplexArray, ComplexArray>, EntityResponse<Greeting>>> request2 = builders.batchGet().ids(complexKeys).build();
Response<BatchKVResponse<ComplexResourceKey<ComplexArray, ComplexArray>, EntityResponse<Greeting>>> response2 = getClient().sendRequest(request2).getResponse();
EntityResponse<Greeting> greeting1 = response2.getEntity().getResults().get(complexKeys.get(0));
Assert.assertNotNull(greeting1);
EntityResponse<Greeting> greeting2 = response2.getEntity().getResults().get(complexKeys.get(1));
Assert.assertNotNull(greeting2);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestComplexArrayResource method testBatchGetKV.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "versionWithRequestOptionsDataProvider")
public void testBatchGetKV(ProtocolVersion version, RestliRequestOptions options) throws RemoteInvocationException {
List<ComplexResourceKey<ComplexArray, ComplexArray>> complexKeys = getBatchCompleKeys();
ComplexArrayBuilders builders = new ComplexArrayBuilders(options);
Request<BatchKVResponse<ComplexResourceKey<ComplexArray, ComplexArray>, Greeting>> request2 = builders.batchGet().ids(complexKeys).buildKV();
Response<BatchKVResponse<ComplexResourceKey<ComplexArray, ComplexArray>, Greeting>> response2 = getClient().sendRequest(request2).getResponse();
Greeting greeting1 = response2.getEntity().getResults().get(complexKeys.get(0));
Assert.assertNotNull(greeting1);
Greeting greeting2 = response2.getEntity().getResults().get(complexKeys.get(1));
Assert.assertNotNull(greeting2);
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestExceptionsResource method testException.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
public void testException(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Response<Greeting> response = null;
RestLiResponseException exception = null;
try {
Request<Greeting> readRequest = builders.get().id(1L).build();
ResponseFuture<Greeting> future;
if (explicit) {
future = getClient().sendRequest(readRequest, errorHandlingBehavior);
} else {
future = getClient().sendRequest(readRequest);
}
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.assertNull(response.getEntity());
}
Assert.assertNotNull(exception);
Assert.assertFalse(exception.hasDecodedResponse());
Assert.assertEquals(exception.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
Assert.assertEquals(exception.getServiceErrorCode(), 42);
Assert.assertEquals(exception.getServiceErrorMessage(), "error processing request");
Assert.assertTrue(exception.getServiceErrorStackTrace().contains("at com.linkedin.restli.examples.greetings.server.ExceptionsResource.get("));
}
use of com.linkedin.restli.examples.greetings.api.Greeting in project rest.li by linkedin.
the class TestCookieResource method testAddCookies.
/**
* Test the add cookie functionality
*
* @throws RemoteInvocationException
*/
@Test
public void testAddCookies() throws RemoteInvocationException {
CookieGetBuilder builderTmp = new CookieBuilders().get().id(1L);
builderTmp.addCookie(new HttpCookie("C", "3"));
builderTmp.addCookie(new HttpCookie("B", "2"));
builderTmp.addCookie(new HttpCookie("A", "1"));
GetRequest<Greeting> req = builderTmp.build();
Response<Greeting> resp = REST_CLIENT.sendRequest(req).getResponse();
List<HttpCookie> expectedCookies = Arrays.asList(new HttpCookie("3", "C"), new HttpCookie("2", "B"), new HttpCookie("1", "A"));
Assert.assertEquals(resp.getCookies(), expectedCookies);
}
Aggregations