Search in sources :

Example 16 with Greetings

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

the class TestParseqBasedFluentClientApi method testDeleteFailure.

@Test
public void testDeleteFailure() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<Void> result = greetings.delete(-1L);
    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 17 with Greetings

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

the class TestParseqBasedFluentClientApi method testCreateAndThenBatchDelete.

@Test
public void testCreateAndThenBatchDelete() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    // Create entities first so we don't delete those used by other tests.
    CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
    CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(ids -> greetings.batchDelete(Sets.newHashSet(ids.stream().map(CreateIdStatus::getKey).collect(Collectors.toList()))));
    CompletableFuture<Map<Long, UpdateStatus>> future = result.toCompletableFuture();
    Map<Long, UpdateStatus> ids = future.get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(ids.size(), 2);
    for (UpdateStatus status : ids.values()) {
        Assert.assertEquals(status.getStatus().intValue(), 204);
    }
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.linkedin.data.template.StringMap) Test(org.testng.annotations.Test)

Example 18 with Greetings

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

the class TestParseqBasedFluentClientApi method testPartialUpdateAfterCreateAndGet.

@Test
public void testPartialUpdateAfterCreateAndGet() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    // Create a new greeting to use for partial update test.
    CompletionStage<Long> createResult = greetings.create(getGreeting());
    CompletionStage<Void> updateResult = createResult.thenCompose(greetings::get).thenCompose(greeting -> {
        try {
            Greeting update = greeting.copy();
            greeting.setMessage("Partial update message");
            return greetings.partialUpdate(1L, PatchGenerator.diff(greeting, update));
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
    });
    CompletableFuture<Void> future = updateResult.toCompletableFuture();
    future.get(5000, TimeUnit.MILLISECONDS);
    Assert.assertFalse(future.isCompletedExceptionally());
}
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) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) Test(org.testng.annotations.Test)

Example 19 with Greetings

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

the class TestParseqBasedFluentClientApi method testUpdate.

@Test
public void testUpdate() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<Long> createResult = greetings.create(getGreeting());
    final String message = "Update test";
    CompletionStage<Void> updateResult = createResult.thenCompose(id -> greetings.update(id, getGreeting(message)));
    CompletionStage<Greeting> getResult = createResult.thenCombine(updateResult, (id, v) -> id).thenCompose(greetings::get);
    CompletableFuture<Greeting> future = getResult.toCompletableFuture();
    future.get(5000, TimeUnit.MILLISECONDS);
    // Get the greeting to test updated value
    Assert.assertEquals(future.get().getMessage(), message);
}
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) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) Test(org.testng.annotations.Test)

Example 20 with Greetings

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

the class TestParseqBasedFluentClientApi method testFinder.

@Test
public void testFinder() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<CollectionResponse<Greeting>> result = greetings.findBySearch(params -> params.setTone(Tone.FRIENDLY));
    CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
    List<Greeting> greetingList = future.get(5000, TimeUnit.MILLISECONDS).getElements();
    Assert.assertTrue(greetingList.size() > 0);
    for (Greeting greeting : greetingList) {
        Assert.assertEquals(greeting.getTone(), Tone.FRIENDLY);
    }
}
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) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) 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