use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testFinderWithPagingProjection.
@Test
public void testFinderWithPagingProjection() throws Exception {
PagingMetadataProjections greetings = new PagingMetadataProjectionsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<CollectionResponse<Greeting>> result = greetings.findByMetadataAutomaticPagingFullyAutomatic(params -> params.withPagingMask(pageMask -> pageMask.withTotal()));
CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
CollectionResponse<Greeting> greetingResult = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(greetingResult.hasPaging());
Assert.assertFalse(greetingResult.getPaging().hasCount());
Assert.assertFalse(greetingResult.getPaging().hasStart());
Assert.assertFalse(greetingResult.getPaging().hasLinks());
Assert.assertTrue(greetingResult.getPaging().hasTotal());
Assert.assertTrue(greetingResult.getPaging().getTotal() > 0);
// Same request without projection.
result = greetings.findByMetadataAutomaticPagingFullyAutomatic();
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());
Assert.assertTrue(greetingResult.getPaging().hasTotal());
Assert.assertTrue(greetingResult.getPaging().getTotal() > 0);
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testGetAllWithMetadataProjection.
@Test
public void testGetAllWithMetadataProjection() throws Exception {
PagingMetadataProjections greetings = new PagingMetadataProjectionsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<CollectionResponse<Greeting>> result = greetings.getAll(params -> params.withMetadataMask(metadataMask -> metadataMask.withMessage()));
CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
CollectionResponse<Greeting> greetingResult = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertNotNull(greetingResult.getMetadataRaw());
Greeting metadata = new Greeting(greetingResult.getMetadataRaw());
Assert.assertTrue(metadata.hasMessage());
Assert.assertFalse(metadata.hasTone());
// Same request without projection.
result = greetings.findByMetadataAutomaticPagingFullyAutomatic();
future = result.toCompletableFuture();
greetingResult = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertNotNull(greetingResult.getMetadataRaw());
metadata = new Greeting(greetingResult.getMetadataRaw());
Assert.assertTrue(metadata.hasMessage());
Assert.assertTrue(metadata.hasTone());
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testUpdateFailure.
@Test
public void testUpdateFailure() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Void> result = greetings.update(-7L, getGreeting());
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 testBatchGetRequest.
@Test
public void testBatchGetRequest() 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);
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.assertEquals(id, g.getEntity().getId());
}
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testCollectionActionWithNoReturn.
@Test
public void testCollectionActionWithNoReturn() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletableFuture<Void> stage = greetings.anotherAction(param -> param.setBitfield(new BooleanArray()).setRequest(new TransferOwnershipRequest()).setSomeString("").setStringMap(new StringMap())).toCompletableFuture();
Assert.assertNull(stage.get(5000, TimeUnit.MILLISECONDS));
assert (!stage.isCompletedExceptionally());
}
Aggregations