Search in sources :

Example 1 with Greetings

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

the class TestParseqBasedFluentClientApi method testBatchCreate.

@Test
public void testBatchCreate() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<List<CreateIdStatus<Long>>> result = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
    CompletableFuture<List<CreateIdStatus<Long>>> future = result.toCompletableFuture();
    List<CreateIdStatus<Long>> ids = future.get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(ids.size(), 2);
}
Also used : 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) Test(org.testng.annotations.Test)

Example 2 with Greetings

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

the class TestParseqBasedFluentClientApi method testGetAll.

@Test
public void testGetAll() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    // Create some greetings with "GetAll" in message so they will be returned by getAll test method..
    CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting("GetAll"), getGreeting("GetAll")));
    CompletionStage<CollectionResponse<Greeting>> result = createResult.thenCompose(ids -> greetings.getAll());
    CompletableFuture<CollectionResponse<Greeting>> future = result.toCompletableFuture();
    List<Greeting> greetingList = future.get(5000, TimeUnit.MILLISECONDS).getElements();
    Assert.assertTrue(greetingList.size() >= 2);
    for (Greeting greeting : greetingList) {
        Assert.assertTrue(greeting.getMessage().contains("GetAll"));
    }
}
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) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 3 with Greetings

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

the class TestParseqBasedFluentClientApi method testCollectionActionWithException.

@Test(expectedExceptions = { RestLiResponseException.class })
public void testCollectionActionWithException() throws Throwable {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletableFuture<Void> stage = greetings.exceptionTest().toCompletableFuture();
    try {
        stage.get(5000, TimeUnit.MILLISECONDS);
        Assert.fail("expected exception");
    } catch (Exception e) {
        assert (stage.isCompletedExceptionally());
        throw e.getCause();
    }
}
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 4 with Greetings

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

the class TestParseqBasedFluentClientApi method testBatchUpdate.

@Test
public void testBatchUpdate() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<List<CreateIdStatus<Long>>> createResult = greetings.batchCreate(Arrays.asList(getGreeting(), getGreeting()));
    final Map<Long, Greeting> inputs = new HashMap<>();
    CompletionStage<Map<Long, UpdateStatus>> result = createResult.thenCompose(idStatuses -> {
        for (CreateIdStatus<Long> idStatus : idStatuses) {
            inputs.put(idStatus.getKey(), 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);
    for (Long id : inputs.keySet()) {
        Assert.assertEquals(ids.get(id).getStatus().intValue(), 204);
    }
}
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) 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 5 with Greetings

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

the class TestParseqBasedFluentClientApi method testBatchGetRequestWithPartialErrors.

@Test
public void testBatchGetRequestWithPartialErrors() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Set<Long> ids = Sets.newHashSet(Arrays.asList(-1L, -2L, 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);
        if (id > 0) {
            Assert.assertTrue(g.hasEntry());
            Assert.assertEquals(id, g.getEntity().getId());
        } else {
            Assert.assertTrue(g.hasError());
        }
    }
}
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)

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