Search in sources :

Example 1 with GreetingFluentClient

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());
    }
}
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) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 2 with GreetingFluentClient

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);
}
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) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) Test(org.testng.annotations.Test)

Example 3 with GreetingFluentClient

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);
}
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) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) Test(org.testng.annotations.Test)

Example 4 with GreetingFluentClient

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);
}
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) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 5 with GreetingFluentClient

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);
}
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) GreetingFluentClient(com.linkedin.restli.examples.greetings.client.GreetingFluentClient) PartialUpdateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient) CreateGreetingFluentClient(com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient) Test(org.testng.annotations.Test)

Aggregations

Greeting (com.linkedin.restli.examples.greetings.api.Greeting)5 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)5 CreateGreetingFluentClient (com.linkedin.restli.examples.greetings.client.CreateGreetingFluentClient)5 GreetingFluentClient (com.linkedin.restli.examples.greetings.client.GreetingFluentClient)5 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)5 PartialUpdateGreetingFluentClient (com.linkedin.restli.examples.greetings.client.PartialUpdateGreetingFluentClient)5 Test (org.testng.annotations.Test)5 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 ExecutionException (java.util.concurrent.ExecutionException)2