Search in sources :

Example 11 with Greetings

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

the class TestParseqBasedFluentClientApi method testGetRequest.

@Test
public void testGetRequest() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<Greeting> result = greetings.get(1L);
    CompletableFuture<Greeting> future = result.toCompletableFuture();
    Greeting greeting = future.get(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(greeting.hasId());
    Assert.assertEquals((Long) 1L, greeting.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) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) Test(org.testng.annotations.Test)

Example 12 with Greetings

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

the class TestParseqBasedFluentClientApi method testGetRequestFailure.

@Test
public void testGetRequestFailure() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<Greeting> result = greetings.get(-1L);
    CompletableFuture<Greeting> 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 : CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) 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 13 with Greetings

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

the class TestParseqBasedFluentClientApi method testCollectionEntityActionWithReturn.

// ----- Tests with actions ------
@Test
public void testCollectionEntityActionWithReturn() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Greeting newGreeting;
    newGreeting = greetings.updateTone(1L, param -> param.setNewTone(Tone.SINCERE).setDelOld(false)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(newGreeting);
    Assert.assertEquals(newGreeting.getId().longValue(), 1L);
    Assert.assertEquals(newGreeting.getTone(), Tone.SINCERE);
    newGreeting = greetings.updateTone(1L, param -> param.setNewTone(Tone.INSULTING)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(newGreeting);
    Assert.assertEquals(newGreeting.getId().longValue(), 1L);
    Assert.assertEquals(newGreeting.getTone(), Tone.INSULTING);
}
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) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) Test(org.testng.annotations.Test)

Example 14 with Greetings

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

the class TestParseqBasedFluentClientApiWithProjections method testGetAllWithPagingProjection.

@Test
public void testGetAllWithPagingProjection() throws Exception {
    PagingMetadataProjections greetings = new PagingMetadataProjectionsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<CollectionResponse<Greeting>> result = greetings.getAll(params -> params.withPagingMask(pageMask -> pageMask.withTotal().withStart()));
    CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
    CollectionResponse<Greeting> greetingResult = future.get(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(greetingResult.hasPaging());
    Assert.assertFalse(greetingResult.getPaging().hasCount());
    Assert.assertTrue(greetingResult.getPaging().hasStart());
    Assert.assertEquals((int) greetingResult.getPaging().getStart(), 0);
    Assert.assertFalse(greetingResult.getPaging().hasLinks());
    Assert.assertTrue(greetingResult.getPaging().getTotal() > 0);
    // Same request without projection.
    result = greetings.getAll();
    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());
// The resource applies manual projection and returns total only when it is explicitly projected. So no total field here.
}
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 15 with Greetings

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

the class TestParseqBasedFluentClientApiWithProjections method testPartialUpdateAndGetWithProjection.

@Test
public void testPartialUpdateAndGetWithProjection() throws Exception {
    PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Greeting original = getGreeting();
    String message = "Edited message: fluent api test partialUpdateAndGet";
    Greeting update = getGreeting(message);
    CompletionStage<Greeting> result = greetings.partialUpdateAndGet(21L, PatchGenerator.diff(original, update), optionalParams -> optionalParams.withMask(mask -> mask.withId()));
    CompletableFuture<Greeting> future = result.toCompletableFuture();
    Greeting greeting = future.get(5000, TimeUnit.MILLISECONDS);
    Assert.assertFalse(greeting.hasMessage());
    Assert.assertTrue(greeting.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) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) 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