Search in sources :

Example 1 with Batchfinders

use of com.linkedin.restli.examples.greetings.client.Batchfinders in project rest.li by linkedin.

the class TestParseqBasedFluentClientApiWithProjections method testBatchFinderWithProjection.

@Test
public void testBatchFinderWithProjection() throws Exception {
    Batchfinders batchFinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    CompletionStage<BatchCollectionResponse<Greeting>> result = batchFinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world", params -> params.withMask(mask -> mask.withTone().withId()));
    CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertEquals(greetings1.get(0).getTone(), Tone.SINCERE);
    Assert.assertTrue(greetings1.get(0).hasId());
    Assert.assertFalse(greetings1.get(0).hasMessage());
    List<Greeting> greetings2 = batchResult.get(1).getElements();
    Assert.assertTrue(greetings2.get(0).hasId());
    Assert.assertEquals(greetings2.get(0).getTone(), Tone.FRIENDLY);
    Assert.assertTrue(greetings2.get(0).hasId());
    Assert.assertFalse(greetings2.get(0).hasMessage());
}
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) Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) Test(org.testng.annotations.Test)

Example 2 with Batchfinders

use of com.linkedin.restli.examples.greetings.client.Batchfinders in project rest.li by linkedin.

the class TestParseqBasedFluentClientApiWithProjections method testBatchFinderWithPagingProjection.

@Test
public void testBatchFinderWithPagingProjection() throws Exception {
    Batchfinders batchFinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    CompletionStage<BatchCollectionResponse<Greeting>> result = batchFinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world", params -> params.withPagingMask(mask -> mask.withStart()).withMask(fieldMask -> fieldMask.withId().withTone()));
    CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
    for (BatchFinderCriteriaResult<?> singleCriteria : batchResult) {
        CollectionMetadata paging = singleCriteria.getPaging();
        Assert.assertTrue(paging.hasStart());
        Assert.assertFalse(paging.hasCount());
        Assert.assertFalse(paging.hasTotal());
        Assert.assertFalse(paging.hasLinks());
    }
    // Same request without paging mask (setting field mask to avoid validation error on server)
    result = batchFinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world", params -> params.withMask(fieldMask -> fieldMask.withId().withTone()));
    future = result.toCompletableFuture();
    batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
    for (BatchFinderCriteriaResult<?> singleCriteria : batchResult) {
        CollectionMetadata paging = singleCriteria.getPaging();
        Assert.assertTrue(paging.hasStart());
        Assert.assertTrue(paging.hasCount());
        Assert.assertTrue(paging.hasTotal());
        Assert.assertTrue(paging.hasLinks());
    }
}
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) Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) Test(org.testng.annotations.Test)

Example 3 with Batchfinders

use of com.linkedin.restli.examples.greetings.client.Batchfinders in project rest.li by linkedin.

the class TestParseqBasedFluentClientApi method testBatchFinder.

@Test
public void testBatchFinder() throws Exception {
    Batchfinders batchfinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    CompletionStage<BatchCollectionResponse<Greeting>> result = batchfinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world");
    CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertEquals(greetings1.get(0).getTone(), Tone.SINCERE);
    List<Greeting> greetings2 = batchResult.get(1).getElements();
    Assert.assertTrue(greetings2.get(0).hasId());
    Assert.assertEquals(greetings2.get(0).getTone(), Tone.FRIENDLY);
}
Also used : Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) Test(org.testng.annotations.Test)

Aggregations

BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)3 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)3 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)3 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)3 Batchfinders (com.linkedin.restli.examples.greetings.client.Batchfinders)3 BatchfindersFluentClient (com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient)3 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)3 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)3 Test (org.testng.annotations.Test)3 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)2 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)2 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)2 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)2 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)2 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 CreateIdEntityStatus (com.linkedin.restli.common.CreateIdEntityStatus)2 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)2 EntityResponse (com.linkedin.restli.common.EntityResponse)2