Search in sources :

Example 6 with Greetings

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);
}
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 7 with Greetings

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());
}
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 8 with Greetings

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);
    }
}
Also used : Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 9 with Greetings

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());
    }
}
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) EntityResponse(com.linkedin.restli.common.EntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) 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)

Example 10 with Greetings

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());
}
Also used : ComplexKeysSubFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysSubFluentClient) Arrays(java.util.Arrays) CollectionResponse(com.linkedin.restli.common.CollectionResponse) Date(java.util.Date) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Test(org.testng.annotations.Test) AssociationsSubFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsSubFluentClient) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) AssociationsAssociationsSubFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsSubFluentClient) TransferOwnershipRequest(com.linkedin.restli.examples.groups.api.TransferOwnershipRequest) Groups(com.linkedin.restli.examples.groups.client.Groups) PatchGenerator(com.linkedin.restli.client.util.PatchGenerator) EntityResponse(com.linkedin.restli.common.EntityResponse) Map(java.util.Map) CreateIdEntityStatus(com.linkedin.restli.common.CreateIdEntityStatus) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) AssociationAltKey(com.linkedin.restli.examples.greetings.client.AssociationAltKey) MessageCriteriaArray(com.linkedin.restli.examples.greetings.api.MessageCriteriaArray) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) Collectors(java.util.stream.Collectors) Associations(com.linkedin.restli.examples.greetings.client.Associations) GroupsFluentClient(com.linkedin.restli.examples.groups.client.GroupsFluentClient) ParSeqRestliClientConfigBuilder(com.linkedin.restli.client.ParSeqRestliClientConfigBuilder) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) ParSeqRestliClientBuilder(com.linkedin.restli.client.ParSeqRestliClientBuilder) Actions(com.linkedin.restli.examples.greetings.client.Actions) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) SubgreetingsFluentClient(com.linkedin.restli.examples.greetings.client.SubgreetingsFluentClient) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) AssociationsAssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient) MessageCriteria(com.linkedin.restli.examples.greetings.api.MessageCriteria) AssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsFluentClient) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanArray(com.linkedin.data.template.BooleanArray) ArrayList(java.util.ArrayList) CustomTypes2(com.linkedin.restli.examples.greetings.client.CustomTypes2) HashSet(java.util.HashSet) PatchRequest(com.linkedin.restli.common.PatchRequest) CustomTypes3(com.linkedin.restli.examples.greetings.client.CustomTypes3) CustomTypes3FluentClient(com.linkedin.restli.examples.greetings.client.CustomTypes3FluentClient) CustomTypes2FluentClient(com.linkedin.restli.examples.greetings.client.CustomTypes2FluentClient) Assert(org.testng.Assert) UpdateEntityStatus(com.linkedin.restli.common.UpdateEntityStatus) StringMap(com.linkedin.data.template.StringMap) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) ParSeqUnitTestHelper(com.linkedin.parseq.ParSeqUnitTestHelper) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) 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) ActionsFluentClient(com.linkedin.restli.examples.greetings.client.ActionsFluentClient) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) CompoundKey(com.linkedin.restli.common.CompoundKey) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) ParSeqRestliClient(com.linkedin.restli.client.ParSeqRestliClient) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) HttpStatus(com.linkedin.restli.common.HttpStatus) AssociationAltKeyFluentClient(com.linkedin.restli.examples.greetings.client.AssociationAltKeyFluentClient) Message(com.linkedin.restli.examples.greetings.api.Message) Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) Sets(org.testng.collections.Sets) StringMap(com.linkedin.data.template.StringMap) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) TransferOwnershipRequest(com.linkedin.restli.examples.groups.api.TransferOwnershipRequest) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) BooleanArray(com.linkedin.data.template.BooleanArray) 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