Search in sources :

Example 1 with PartialUpdateGreeting

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

the class TestParseqBasedFluentClientApi method testSubResource_oneLayerPathKey.

/**
 * Test {@link com.linkedin.restli.examples.greetings.server.SimpleResourceUnderCollectionResource}
 * A complete set of request tests were tested in {@link TestSimpleResourceHierarchy}
 */
@Test
public void testSubResource_oneLayerPathKey() throws Exception {
    // Get
    com.linkedin.restli.examples.greetings.client.Greeting.Subgreetings.Subsubgreeting subsubClient = new GreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine()).subgreetingsOf().subsubgreetingOf(1L);
    Greeting greeting = subsubClient.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    // value should be (pathKey * 10)
    Assert.assertEquals(greeting.getId().longValue(), 10L);
    // Update
    Greeting updateGreeting = new Greeting();
    updateGreeting.setMessage("Message1");
    updateGreeting.setTone(Tone.INSULTING);
    updateGreeting.setId(1L);
    subsubClient.update(updateGreeting).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(subsubClient.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS).getTone(), Tone.INSULTING);
    // Partial Update
    Greeting partialUpdateGreeting = new Greeting();
    partialUpdateGreeting.setMessage("Message1");
    partialUpdateGreeting.setTone(Tone.SINCERE);
    partialUpdateGreeting.setId(1L);
    PatchRequest<Greeting> patch = PatchGenerator.diffEmpty(partialUpdateGreeting);
    subsubClient.partialUpdate(patch).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(subsubClient.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS).getTone(), Tone.SINCERE);
    // Delete
    subsubClient.delete().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    try {
        subsubClient.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
        Assert.fail("Sub resource call without path key should fail");
    } catch (Exception e) {
        Assert.assertTrue(e.getCause() instanceof RestLiResponseException);
        Assert.assertEquals(((RestLiResponseException) e.getCause()).getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
    }
}
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) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 2 with PartialUpdateGreeting

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

the class TestParseqBasedFluentClientApi method testPartialUpdateError.

@Test
public void testPartialUpdateError() 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(-1L, PatchGenerator.diff(original, update));
    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) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) Test(org.testng.annotations.Test)

Example 3 with PartialUpdateGreeting

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

the class TestParseqBasedFluentClientApi method testBatchPartialUpdateAndGetWithErrors.

@Test
public void testBatchPartialUpdateAndGetWithErrors() throws Exception {
    PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Map<Long, PatchRequest<Greeting>> inputs = new HashMap<>();
    Greeting original = getGreeting();
    String message = "Edited message: fluent api test partialUpdateAndGet";
    Greeting update = getGreeting(message);
    inputs.put(21L, PatchGenerator.diff(original, update));
    inputs.put(-2L, PatchGenerator.diff(original, update));
    CompletionStage<Map<Long, UpdateEntityStatus<Greeting>>> result = greetings.batchPartialUpdateAndGet(inputs);
    CompletableFuture<Map<Long, UpdateEntityStatus<Greeting>>> future = result.toCompletableFuture();
    Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
    Assert.assertEquals(future.get().get(21L).getStatus().intValue(), 200);
    Assert.assertEquals(future.get().get(21L).getEntity().getId().longValue(), 21L);
    Assert.assertEquals(future.get().get(21L).getEntity().getMessage(), message);
    Assert.assertEquals(future.get().get(-2L).getStatus().intValue(), 404);
    Assert.assertFalse(future.get().get(-2L).hasEntity());
}
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) HashMap(java.util.HashMap) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) PatchRequest(com.linkedin.restli.common.PatchRequest) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.linkedin.data.template.StringMap) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) Test(org.testng.annotations.Test)

Example 4 with PartialUpdateGreeting

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

the class TestParseqBasedFluentClientApi method testBatchPartialUpdateAndGet.

@Test
public void testBatchPartialUpdateAndGet() throws Exception {
    PartialUpdateGreeting greetings = new PartialUpdateGreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Map<Long, PatchRequest<Greeting>> inputs = new HashMap<>();
    Greeting original = getGreeting();
    String message = "Edited message: fluent api test partialUpdateAndGet";
    Greeting update = getGreeting(message);
    inputs.put(21L, PatchGenerator.diff(original, update));
    inputs.put(22L, PatchGenerator.diff(original, update));
    CompletionStage<Map<Long, UpdateEntityStatus<Greeting>>> result = greetings.batchPartialUpdateAndGet(inputs);
    CompletableFuture<Map<Long, UpdateEntityStatus<Greeting>>> future = result.toCompletableFuture();
    Assert.assertNotNull(future.get(5000, TimeUnit.MILLISECONDS));
    Assert.assertEquals(future.get().get(21L).getEntity().getId().longValue(), 21L);
    Assert.assertEquals(future.get().get(21L).getEntity().getMessage(), message);
    Assert.assertEquals(future.get().get(22L).getEntity().getId().longValue(), 22L);
    Assert.assertEquals(future.get().get(22L).getEntity().getMessage(), message);
}
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) HashMap(java.util.HashMap) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) PatchRequest(com.linkedin.restli.common.PatchRequest) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.linkedin.data.template.StringMap) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) Test(org.testng.annotations.Test)

Example 5 with PartialUpdateGreeting

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

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)9 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)9 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)9 PartialUpdateGreetingFluentClient (com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient)9 Test (org.testng.annotations.Test)9 PatchRequest (com.linkedin.restli.common.PatchRequest)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 StringMap (com.linkedin.data.template.StringMap)4 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)4 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)4 CreateGreetingFluentClient (com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient)3 ExecutionException (java.util.concurrent.ExecutionException)3 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)2 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)2 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)2 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)2 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)2 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)2 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)2