use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchGetWithProjection.
@Test
public void testBatchGetWithProjection() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Set<Long> ids = Sets.newHashSet(Arrays.asList(1L, 2L, 3L));
CompletionStage<Map<Long, EntityResponse<Greeting>>> result = greetings.batchGet(ids, optionalParams -> optionalParams.withMask(mask -> mask.withTone()));
CompletableFuture<Map<Long, EntityResponse<Greeting>>> future = result.toCompletableFuture();
Map<Long, EntityResponse<Greeting>> resultMap = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(resultMap.size(), ids.size());
for (Long id : ids) {
EntityResponse<Greeting> g = resultMap.get(id);
Assert.assertNotNull(g);
Assert.assertTrue(g.hasEntry());
Assert.assertFalse(g.getEntity().hasId());
Assert.assertFalse(g.getEntity().hasMessage());
Assert.assertTrue(g.getEntity().hasTone());
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchPartialUpdateAndGetWithProjection.
@Test
public void testBatchPartialUpdateAndGetWithProjection() throws Exception {
PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Map<Long, PatchRequest<Greeting>> inputs = new HashMap<>();
Greeting original = getGreeting();
String message = "Edited message: fluent api test partialUpdateAndGet";
Greeting update = getGreeting(message);
inputs.put(21L, PatchGenerator.diff(original, update));
inputs.put(22L, PatchGenerator.diff(original, update));
CompletionStage<Map<Long, UpdateEntityStatus<Greeting>>> result = greetings.batchPartialUpdateAndGet(inputs, optionalParams -> optionalParams.withMask(mask -> mask.withId().withMessage().withTone()));
CompletableFuture<Map<Long, UpdateEntityStatus<Greeting>>> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
Assert.assertEquals(future.get().get(21L).getEntity().getId().longValue(), 21L);
Assert.assertEquals(future.get().get(21L).getEntity().getMessage(), message);
Assert.assertEquals(future.get().get(22L).getEntity().getId().longValue(), 22L);
Assert.assertEquals(future.get().get(22L).getEntity().getMessage(), message);
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testCreateAndGetWithProjection.
@Test
public void testCreateAndGetWithProjection() throws Exception {
CreateGreeting greetings = new CreateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
String msg = Double.toString(Math.random());
CompletionStage<IdEntityResponse<Long, Greeting>> result = greetings.createAndGet(getGreeting(msg), optionalParams -> optionalParams.withMask(mask -> mask.withMessage()));
CompletableFuture<IdEntityResponse<Long, Greeting>> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
Assert.assertFalse(future.get().getEntity().hasId());
Assert.assertFalse(future.get().getEntity().hasTone());
Assert.assertEquals(msg, future.get().getEntity().getMessage());
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testGetAllWithFieldProjection.
@Test
public void testGetAllWithFieldProjection() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create some greetings with "GetAll" in message so they will be returned by getAll test method..
CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting("GetAll").setId(200L), getGreeting("GetAll").setId(201L)));
CompletionStage<CollectionResponse<Greeting>> result = createResult.thenCompose(ids -> greetings.getAll(optionalParams -> optionalParams.withMask(mask -> mask.withMessage())));
CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
List<Greeting> greetingList = future.get(5000, TimeUnit.MILLISECONDS).getElements();
Assert.assertTrue(greetingList.size() >= 2);
for (Greeting greeting : greetingList) {
Assert.assertFalse(greeting.hasId());
Assert.assertTrue(greeting.getMessage().contains("GetAll"));
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testFinderWithProjection.
@Test
public void testFinderWithProjection() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<CollectionResponse<Greeting>> result = greetings.findBySearch(params -> params.setTone(Tone.FRIENDLY).withMask(fieldsMask -> fieldsMask.withTone().withMessage()));
CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
List<Greeting> greetingList = future.get(5000, TimeUnit.MILLISECONDS).getElements();
Assert.assertTrue(greetingList.size() > 0);
for (Greeting greeting : greetingList) {
Assert.assertEquals(greeting.getTone(), Tone.FRIENDLY);
Assert.assertFalse(greeting.hasId());
Assert.assertTrue(greeting.hasMessage());
}
}
Aggregations