use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testGetRequest.
@Test
public void testGetRequest() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Greeting> result = greetings.get(1L);
CompletableFuture<Greeting> future = result.toCompletableFuture();
Greeting greeting = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(greeting.hasId());
Assert.assertEquals((Long) 1L, greeting.getId());
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testGetRequestFailure.
@Test
public void testGetRequestFailure() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Greeting> result = greetings.get(-1L);
CompletableFuture<Greeting> 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 testCollectionEntityActionWithReturn.
// ----- Tests with actions ------
@Test
public void testCollectionEntityActionWithReturn() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Greeting newGreeting;
newGreeting = greetings.updateTone(1L, param -> param.setNewTone(Tone.SINCERE).setDelOld(false)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertNotNull(newGreeting);
Assert.assertEquals(newGreeting.getId().longValue(), 1L);
Assert.assertEquals(newGreeting.getTone(), Tone.SINCERE);
newGreeting = greetings.updateTone(1L, param -> param.setNewTone(Tone.INSULTING)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertNotNull(newGreeting);
Assert.assertEquals(newGreeting.getId().longValue(), 1L);
Assert.assertEquals(newGreeting.getTone(), Tone.INSULTING);
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testGetAllWithPagingProjection.
@Test
public void testGetAllWithPagingProjection() throws Exception {
PagingMetadataProjections greetings = new PagingMetadataProjectionsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<CollectionResponse<Greeting>> result = greetings.getAll(params -> params.withPagingMask(pageMask -> pageMask.withTotal().withStart()));
CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
CollectionResponse<Greeting> greetingResult = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(greetingResult.hasPaging());
Assert.assertFalse(greetingResult.getPaging().hasCount());
Assert.assertTrue(greetingResult.getPaging().hasStart());
Assert.assertEquals((int) greetingResult.getPaging().getStart(), 0);
Assert.assertFalse(greetingResult.getPaging().hasLinks());
Assert.assertTrue(greetingResult.getPaging().getTotal() > 0);
// Same request without projection.
result = greetings.getAll();
future = result.toCompletableFuture();
greetingResult = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(greetingResult.hasPaging());
Assert.assertTrue(greetingResult.getPaging().hasCount());
Assert.assertTrue(greetingResult.getPaging().hasStart());
Assert.assertTrue(greetingResult.getPaging().hasLinks());
// The resource applies manual projection and returns total only when it is explicitly projected. So no total field here.
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testPartialUpdateAndGetWithProjection.
@Test
public void testPartialUpdateAndGetWithProjection() throws Exception {
PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Greeting original = getGreeting();
String message = "Edited message: fluent api test partialUpdateAndGet";
Greeting update = getGreeting(message);
CompletionStage<Greeting> result = greetings.partialUpdateAndGet(21L, PatchGenerator.diff(original, update), optionalParams -> optionalParams.withMask(mask -> mask.withId()));
CompletableFuture<Greeting> future = result.toCompletableFuture();
Greeting greeting = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertFalse(greeting.hasMessage());
Assert.assertTrue(greeting.hasId());
}
Aggregations