Search in sources :

Example 1 with AssociationAltKeyFluentClient

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!");
}
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) Tone(com.linkedin.restli.examples.greetings.api.Tone) CustomLong(com.linkedin.restli.examples.custom.types.CustomLong) AssociationAltKey(com.linkedin.restli.examples.greetings.client.AssociationAltKey) AssociationAltKeyFluentClient(com.linkedin.restli.examples.greetings.client.AssociationAltKeyFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Aggregations

RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)1 CustomLong (com.linkedin.restli.examples.custom.types.CustomLong)1 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)1 Tone (com.linkedin.restli.examples.greetings.api.Tone)1 AssociationAltKey (com.linkedin.restli.examples.greetings.client.AssociationAltKey)1 AssociationAltKeyFluentClient (com.linkedin.restli.examples.greetings.client.AssociationAltKeyFluentClient)1 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)1 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)1 ExecutionException (java.util.concurrent.ExecutionException)1 Test (org.testng.annotations.Test)1