use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateAndThenDelete.
@Test
public void testCreateAndThenDelete() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create entities first so we don't delete those used by other tests.
CompletionStage<Long> createResult = greetings.create(getGreeting());
CompletionStage<Void> result = createResult.thenCompose(greetings::delete);
CompletableFuture<Void> future = result.toCompletableFuture();
future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertFalse(future.isCompletedExceptionally());
}
use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateNullId.
@Test
public void testCreateNullId() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Long> result = greetings.create(getGreeting(), params -> params.setIsNullId(true));
CompletableFuture<Long> future = result.toCompletableFuture();
Assert.assertNull(future.get(5000, TimeUnit.MILLISECONDS));
}
use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient 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.GreetingsFluentClient 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.GreetingsFluentClient 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