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());
}
}
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);
}
}
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());
}
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);
}
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());
}
Aggregations