Search in sources :

Example 31 with Greetings

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());
}
Also used : PagingMetadataProjections(com.linkedin.restli.examples.greetings.client.PagingMetadataProjections) Arrays(java.util.Arrays) RestLiValidationFilter(com.linkedin.restli.server.validation.RestLiValidationFilter) CollectionResponse(com.linkedin.restli.common.CollectionResponse) AutoValidationWithProjectionFluentClient(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionFluentClient) Test(org.testng.annotations.Test) PatchGenerator(com.linkedin.restli.client.util.PatchGenerator) EntityResponse(com.linkedin.restli.common.EntityResponse) Map(java.util.Map) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) ManualProjections(com.linkedin.restli.examples.greetings.client.ManualProjections) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) ParSeqRestliClientConfigBuilder(com.linkedin.restli.client.ParSeqRestliClientConfigBuilder) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) ParSeqRestliClientBuilder(com.linkedin.restli.client.ParSeqRestliClientBuilder) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) AutoValidationWithProjection(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjection) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) PatchRequest(com.linkedin.restli.common.PatchRequest) Assert(org.testng.Assert) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) ManualProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.ManualProjectionsFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ParSeqUnitTestHelper(com.linkedin.parseq.ParSeqUnitTestHelper) Tone(com.linkedin.restli.examples.greetings.api.Tone) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) AfterClass(org.testng.annotations.AfterClass) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) PagingMetadataProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.PagingMetadataProjectionsFluentClient) ParSeqRestliClient(com.linkedin.restli.client.ParSeqRestliClient) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) com.linkedin.restli.examples.greetings.api.myItem(com.linkedin.restli.examples.greetings.api.myItem) Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) Sets(org.testng.collections.Sets) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) List(java.util.List) Test(org.testng.annotations.Test)

Example 32 with Greetings

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());
}
Also used : PagingMetadataProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.PagingMetadataProjectionsFluentClient) PagingMetadataProjections(com.linkedin.restli.examples.greetings.client.PagingMetadataProjections) Arrays(java.util.Arrays) RestLiValidationFilter(com.linkedin.restli.server.validation.RestLiValidationFilter) CollectionResponse(com.linkedin.restli.common.CollectionResponse) AutoValidationWithProjectionFluentClient(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionFluentClient) Test(org.testng.annotations.Test) PatchGenerator(com.linkedin.restli.client.util.PatchGenerator) EntityResponse(com.linkedin.restli.common.EntityResponse) Map(java.util.Map) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) ManualProjections(com.linkedin.restli.examples.greetings.client.ManualProjections) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) ParSeqRestliClientConfigBuilder(com.linkedin.restli.client.ParSeqRestliClientConfigBuilder) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) ParSeqRestliClientBuilder(com.linkedin.restli.client.ParSeqRestliClientBuilder) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) AutoValidationWithProjection(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjection) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) com.linkedin.restli.examples.greetings.api.myRecord(com.linkedin.restli.examples.greetings.api.myRecord) PatchRequest(com.linkedin.restli.common.PatchRequest) Assert(org.testng.Assert) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) ManualProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.ManualProjectionsFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ParSeqUnitTestHelper(com.linkedin.parseq.ParSeqUnitTestHelper) Tone(com.linkedin.restli.examples.greetings.api.Tone) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) AfterClass(org.testng.annotations.AfterClass) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) PagingMetadataProjectionsFluentClient(com.linkedin.restli.examples.greetings.client.PagingMetadataProjectionsFluentClient) ParSeqRestliClient(com.linkedin.restli.client.ParSeqRestliClient) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) com.linkedin.restli.examples.greetings.api.myItem(com.linkedin.restli.examples.greetings.api.myItem) Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) Sets(org.testng.collections.Sets) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) PagingMetadataProjections(com.linkedin.restli.examples.greetings.client.PagingMetadataProjections) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) Test(org.testng.annotations.Test)

Example 33 with Greetings

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);
}
Also used : CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) UpdateStatus(com.linkedin.restli.common.UpdateStatus) HashMap(java.util.HashMap) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.linkedin.data.template.StringMap) Test(org.testng.annotations.Test)

Aggregations

Greetings (com.linkedin.restli.examples.greetings.client.Greetings)33 GreetingsFluentClient (com.linkedin.restli.examples.greetings.client.GreetingsFluentClient)33 Test (org.testng.annotations.Test)33 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)23 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)23 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)23 HashMap (java.util.HashMap)20 Map (java.util.Map)20 List (java.util.List)19 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)18 ExecutionException (java.util.concurrent.ExecutionException)18 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)17 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)16 CollectionResponse (com.linkedin.restli.common.CollectionResponse)16 EntityResponse (com.linkedin.restli.common.EntityResponse)16 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)16 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)15 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)14 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)14 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)14