use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testDeleteFailure.
@Test
public void testDeleteFailure() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Void> result = greetings.delete(-1L);
CompletableFuture<Void> future = result.toCompletableFuture();
try {
future.get(5000, TimeUnit.MILLISECONDS);
Assert.fail("Expected failure");
} catch (ExecutionException e) {
Assert.assertEquals(((RestLiResponseException) e.getCause()).getStatus(), 404);
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCreateAndThenBatchDelete.
@Test
public void testCreateAndThenBatchDelete() 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 -> greetings.batchDelete(Sets.newHashSet(ids.stream().map(CreateIdStatus::getKey).collect(Collectors.toList()))));
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 2);
for (UpdateStatus status : ids.values()) {
Assert.assertEquals(status.getStatus().intValue(), 204);
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testPartialUpdateAfterCreateAndGet.
@Test
public void testPartialUpdateAfterCreateAndGet() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
// Create a new greeting to use for partial update test.
CompletionStage<Long> createResult = greetings.create(getGreeting());
CompletionStage<Void> updateResult = createResult.thenCompose(greetings::get).thenCompose(greeting -> {
try {
Greeting update = greeting.copy();
greeting.setMessage("Partial update message");
return greetings.partialUpdate(1L, PatchGenerator.diff(greeting, update));
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
});
CompletableFuture<Void> future = updateResult.toCompletableFuture();
future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertFalse(future.isCompletedExceptionally());
}
use of com.linkedin.restli.examples.greetings.client.Greetings 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.Greetings 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);
}
}
Aggregations