use of com.linkedin.restli.examples.greetings.client.GreetingFluentClient 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.GreetingFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testSubResource_getSubClientFromParent.
// ----- Test with Sub Resources ------
// These tests is to verify subresources methods in FluentClient subresources
// works as expected as non-subresources.
@Test
public void testSubResource_getSubClientFromParent() throws Exception {
com.linkedin.restli.examples.greetings.client.Greeting greetingClient = new GreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
Greeting greeting = greetingClient.subgreetingsOf().subsubgreetingOf(1L).get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
// value should be (pathKey * 10)
Assert.assertEquals(greeting.getId().longValue(), 10L);
}
use of com.linkedin.restli.examples.greetings.client.GreetingFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testSubResource_twoLayersPathKeys.
/**
* Test {@link com.linkedin.restli.examples.greetings.server.CollectionOfCollectionOfCollectionOfSimpleResource}
*/
@Test
public void testSubResource_twoLayersPathKeys() throws Exception {
com.linkedin.restli.examples.greetings.client.Greeting.Subgreetings.GreetingsOfgreetingsOfgreeting.GreetingsOfgreetingsOfgreetingsOfgreeting gggs = new GreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine()).subgreetingsOf().greetingsOfgreetingsOfgreetingOf(100L).greetingsOfgreetingsOfgreetingsOfgreetingOf(1000L);
Greeting response = gggs.get(10L).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(response.getId() == 1110);
}
use of com.linkedin.restli.examples.greetings.client.GreetingFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testSimpleResourceDeleteMethodAndGetMethod.
@Test
public void testSimpleResourceDeleteMethodAndGetMethod() throws Exception {
com.linkedin.restli.examples.greetings.client.Greeting greeting = new GreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
greeting.delete().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
try {
Greeting greetingEntity = greeting.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.fail("should fail since entity delete");
} catch (Exception e) {
}
final String message = "Test Get";
greeting.update(getGreeting(message)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Greeting greetingEntity = greeting.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertTrue(greetingEntity.hasId());
Assert.assertEquals(greetingEntity.getMessage(), message);
}
use of com.linkedin.restli.examples.greetings.client.GreetingFluentClient in project rest.li by linkedin.
the class TestParseqBasedFluentClientApi method testSimpleResourceUpdate.
// ----- Test with Simple Resources ------
@Test
public void testSimpleResourceUpdate() throws Exception {
final String message = "Update test";
com.linkedin.restli.examples.greetings.client.Greeting greeting = new GreetingFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
greeting.update(getGreeting(message)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Greeting greetingEntity = greeting.get().toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
Assert.assertEquals(greetingEntity.getMessage(), message);
}
Aggregations