use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.
the class TestGreetingsClient method testOldCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testOldCookbookInBatch(RestliRequestOptions requestOptions) throws Exception {
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
// GET
final BatchGetRequestBuilder<Long, Greeting> batchGetBuilder = builders.batchGet();
Request<BatchResponse<Greeting>> request = batchGetBuilder.ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future = getClient().sendRequest(request);
Response<BatchResponse<Greeting>> greetingResponse = future.getResponse();
// PUT
Greeting greeting = new Greeting(greetingResponse.getEntity().getResults().get("1").data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
getClient().sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
Request<BatchResponse<Greeting>> request2 = builders.batchGet().ids(1L).build();
ResponseFuture<BatchResponse<Greeting>> future2 = getClient().sendRequest(request2);
greetingResponse = future2.get();
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
Request<CollectionResponse<CreateStatus>> request3 = builders.batchCreate().inputs(Arrays.asList(repeatedGreeting, repeatedGreeting)).build();
CollectionResponse<CreateStatus> statuses = getClient().sendRequest(request3).getResponse().getEntity();
for (CreateStatus status : statuses.getElements()) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertNotNull(id);
}
}
use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.
the class TestGreetingClientContentTypes method testBatchGet.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
public void testBatchGet(RestClient restClient, RestliRequestOptions requestOptions) throws RemoteInvocationException {
List<Long> ids = Arrays.asList(1L, 2L, 3L, 4L);
Request<BatchResponse<Greeting>> request = new GreetingsBuilders(requestOptions).batchGet().ids(ids).build();
Response<BatchResponse<Greeting>> response = restClient.sendRequest(request).getResponse();
BatchResponse<Greeting> batchResponse = response.getEntity();
Assert.assertEquals(batchResponse.getResults().size(), ids.size());
}
use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders in project rest.li by linkedin.
the class TestCompressionServer method testOldCookbookInBatch.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCookbookDataProvider")
public void testOldCookbookInBatch(RestClient client, RestliRequestOptions requestOptions) throws Exception {
final GreetingsBuilders builders = new GreetingsBuilders(requestOptions);
// GET
Greeting greetingResult = getOldCookbookBatchGetResult(client, requestOptions);
// POST
Greeting greeting = new Greeting(greetingResult.data().copy());
greeting.setMessage("This is a new message!");
Request<BatchKVResponse<Long, UpdateStatus>> writeRequest = builders.batchUpdate().input(1L, greeting).build();
client.sendRequest(writeRequest).getResponse();
// GET again, to verify that our POST worked.
getOldCookbookBatchGetResult(client, requestOptions);
// batch Create
Greeting repeatedGreeting = new Greeting();
repeatedGreeting.setMessage("Hello Hello");
repeatedGreeting.setTone(Tone.SINCERE);
List<Greeting> entities = Arrays.asList(repeatedGreeting, repeatedGreeting);
Request<CollectionResponse<CreateStatus>> batchCreateRequest = builders.batchCreate().inputs(entities).build();
List<CreateStatus> statuses = client.sendRequest(batchCreateRequest).getResponse().getEntity().getElements();
for (CreateStatus status : statuses) {
Assert.assertEquals(status.getStatus().intValue(), HttpStatus.S_201_CREATED.getCode());
@SuppressWarnings("deprecation") String id = status.getId();
Assert.assertNotNull(id);
}
}
use of com.linkedin.restli.examples.greetings.client.GreetingsBuilders 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.client.GreetingsBuilders in project rest.li by linkedin.
the class TestRootBuilderWrapper method testWrapperMethodNameGeneration.
@Test
public void testWrapperMethodNameGeneration() {
RootBuilderWrapper<Long, Greeting> rootBuilderWrapper1 = new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders());
RootBuilderWrapper<Long, Greeting> rootBuilderWrapper2 = new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders());
rootBuilderWrapper1.findBy("searchWithTones").addQueryParam("tones", Tone.FRIENDLY);
rootBuilderWrapper1.findBy("searchWithTones").setParam("Tones", new Tone[3]);
rootBuilderWrapper1.findBy("SearchWithTones").addQueryParam("Tones", Tone.FRIENDLY);
rootBuilderWrapper1.findBy("SearchWithTones").setParam("tones", new Tone[3]);
rootBuilderWrapper1.action("someAction").setParam("a", 5);
rootBuilderWrapper2.action("someAction").setParam("a", 5);
rootBuilderWrapper1.action("SomeAction").setParam("A", 5);
rootBuilderWrapper2.action("SomeAction").setParam("A", 5);
}
Aggregations