use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testBatchCreateAndGetWithProjection.
@Test
public void testBatchCreateAndGetWithProjection() throws Exception {
CreateGreeting greetings = new CreateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
String msg1 = Double.toString(Math.random());
String msg2 = Double.toString(Math.random());
CompletionStage<List<CreateIdEntityStatus<Long, Greeting>>> result = greetings.batchCreateAndGet(Arrays.asList(getGreeting(msg1), getGreeting(msg2)), optionalParams -> optionalParams.withMask(mask -> mask.withId()));
CompletableFuture<List<CreateIdEntityStatus<Long, Greeting>>> future = result.toCompletableFuture();
List<CreateIdEntityStatus<Long, Greeting>> entities = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(entities.size(), 2);
Assert.assertNotNull(entities.get(0).getEntity());
Assert.assertFalse(entities.get(0).getEntity().hasMessage());
Assert.assertTrue(entities.get(0).getEntity().hasId());
Assert.assertNotNull(entities.get(1).getEntity());
Assert.assertFalse(entities.get(1).getEntity().hasMessage());
Assert.assertTrue(entities.get(1).getEntity().hasId());
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testFinderWithMetadataProjection.
@Test
public void testFinderWithMetadataProjection() throws Exception {
PagingMetadataProjections greetings = new PagingMetadataProjectionsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<CollectionResponse<Greeting>> result = greetings.findByMetadataAutomaticPagingFullyAutomatic(params -> params.withMetadataMask(metadataMask -> metadataMask.withId()));
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.assertFalse(metadata.hasMessage());
Assert.assertFalse(metadata.hasTone());
Assert.assertTrue(metadata.hasId());
// 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());
Assert.assertTrue(metadata.hasId());
}
use of com.linkedin.restli.examples.greetings.client.Greetings in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testBatchUpdateWithErrors.
@Test
public void testBatchUpdateWithErrors() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
final Map<Long, Greeting> inputs = new HashMap<>();
inputs.put(-6L, getGreeting());
CompletionStage<Long> createResult = greetings.create(getGreeting());
CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(id -> {
inputs.put(id, getGreeting("Batch update test"));
return greetings.batchUpdate(inputs);
});
CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(ids.size(), 2);
Assert.assertEquals(ids.get(createResult.toCompletableFuture().get()).getStatus().intValue(), 204);
Assert.assertEquals(ids.get(-6L).getStatus().intValue(), 404);
}
Aggregations