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