Search in sources :

Example 1 with GreetingsFluentClient

use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient 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 GreetingsFluentClient

use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient 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 GreetingsFluentClient

use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient 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 GreetingsFluentClient

use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient 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 GreetingsFluentClient

use of com.linkedin.restli.examples.greetings.client.GreetingsFluentClient 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

GreetingsFluentClient (com.linkedin.restli.examples.greetings.client.GreetingsFluentClient)26 Test (org.testng.annotations.Test)26 Greetings (com.linkedin.restli.examples.greetings.client.Greetings)25 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)16 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)15 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)15 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)15 HashMap (java.util.HashMap)12 Map (java.util.Map)12 List (java.util.List)11 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)10 ExecutionException (java.util.concurrent.ExecutionException)10 StringMap (com.linkedin.data.template.StringMap)9 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)9 ArrayList (java.util.ArrayList)9 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)8 CollectionResponse (com.linkedin.restli.common.CollectionResponse)8 EntityResponse (com.linkedin.restli.common.EntityResponse)8 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)8 UpdateStatus (com.linkedin.restli.common.UpdateStatus)7