use of com.linkedin.restli.client.RestLiResponseException 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.client.RestLiResponseException 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.client.RestLiResponseException in project rest.li by linkedin.
the class TestParseqBasedFluentClientApiWithProjections method testValidationWithNoProjection.
@Test
public void testValidationWithNoProjection() throws Exception {
AutoValidationWithProjection validationDemos = new AutoValidationWithProjectionFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<ValidationDemo> result = validationDemos.get(1);
try {
CompletableFuture<ValidationDemo> future = result.toCompletableFuture();
future.get(5000, TimeUnit.MILLISECONDS);
Assert.fail("Request should have failed validation");
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof RestLiResponseException);
RestLiResponseException responseException = (RestLiResponseException) e.getCause();
Assert.assertEquals(responseException.getServiceErrorMessage(), TestRestLiValidationWithProjection.EXPECTED_VALIDATION_DEMO_FAILURE_MESSAGE);
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testUpdateFailure.
@Test
public void testUpdateFailure() throws Exception {
Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
CompletionStage<Void> result = greetings.update(-7L, getGreeting());
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);
}
}
use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testAssociateResourceSpreadKeyAPI.
@Test
public void testAssociateResourceSpreadKeyAPI() throws Exception {
// Use AssocationAltKeyResource and AltKeyDataProvider
// Get
AssociationAltKey client = new AssociationAltKeyFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
String msgKey = "c";
Long longKey = 3L;
Greeting res = client.get(longKey, msgKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(res.getTone(), Tone.FRIENDLY);
Assert.assertEquals(res.getMessage(), msgKey);
// Update
String newMsg = "aa";
res.setMessage(newMsg);
client.update(longKey, msgKey, res).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
res = client.get(longKey, msgKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(res.getMessage(), newMsg);
// PartialUpdate
Tone updatedTone = Tone.SINCERE;
res.setTone(updatedTone);
Greeting original = client.get(longKey, msgKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
PatchRequest<Greeting> patch = PatchGenerator.diff(original, res);
// Only tone differ
client.partialUpdate(longKey, msgKey, patch).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
res = client.get(longKey, msgKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(res.getMessage(), newMsg);
Assert.assertEquals(res.getTone(), updatedTone);
// Delete
try {
// that resource implementation does not allow deletion
client.delete(longKey, msgKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
Assert.assertEquals(((RestLiResponseException) e.getCause()).getStatus(), 404);
}
// Action
Assert.assertEquals(client.testAction(longKey, msgKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS), "Hello!");
}
Aggregations