use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testUpdate.
@Test
public void testUpdate() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Long> createResult = greetings.create(getGreeting());
final String message = "Update test";
CompletionStage<Void> updateResult = createResult.thenCompose(id -> greetings.update(id, getGreeting(message)));
CompletionStage<Greeting> getResult = createResult.thenCombine(updateResult, (id, v) -> id).thenCompose(greetings::get);
CompletableFuture<Greeting> future = getResult.toCompletableFuture();
future.get(5000, TimeUnit.MILLISECONDS);
// Get the greeting to test updated value
Assert.assertEquals(future.get().getMessage(), message);
}
use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testFinder.
@Test
public void testFinder() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<CollectionResponse<Greeting>> result = greetings.findBySearch(params -> params.setTone(Tone.FRIENDLY));
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);
}
}
use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCollectionActionWithReturn.
@Test
public void testCollectionActionWithReturn() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Assert.assertTrue(greetings.purge().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS) == 100);
}
use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreate.
@Test
public void testCreate() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Long> result = greetings.create(getGreeting());
CompletableFuture<Long> future = result.toCompletableFuture();
Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
}
use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateAndThenBatchDeleteWithFailures.
@Test
public void testCreateAndThenBatchDeleteWithFailures() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create entities first so we don't delete those used by other tests.
CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(ids -> {
Set<Long> deleteIds = Sets.newHashSet(ids.stream().map(CreateIdStatus::getKey).collect(Collectors.toList()));
deleteIds.add(-1L);
return greetings.batchDelete(deleteIds);
});
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 3);
Assert.assertEquals(ids.remove(-1L).getStatus().intValue(), 404);
for (UpdateStatus status : ids.values()) {
Assert.assertEquals(status.getStatus().intValue(), 204);
}
}
Aggregations