Search in sources :

Example 16 with RestLiResponseException

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());
    }
}
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 17 with RestLiResponseException

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

Example 18 with RestLiResponseException

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);
    }
}
Also used : AutoValidationWithProjectionFluentClient(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) AutoValidationWithProjection(com.linkedin.restli.examples.greetings.client.AutoValidationWithProjection) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 19 with RestLiResponseException

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);
    }
}
Also used : Greetings(com.linkedin.restli.examples.greetings.client.Greetings) GreetingsFluentClient(com.linkedin.restli.examples.greetings.client.GreetingsFluentClient) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 20 with RestLiResponseException

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!");
}
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)77 Test (org.testng.annotations.Test)67 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)30 EmptyRecord (com.linkedin.restli.common.EmptyRecord)10 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)10 FlowId (org.apache.gobblin.service.FlowId)10 ExecutionException (java.util.concurrent.ExecutionException)9 StringMap (com.linkedin.data.template.StringMap)8 RestResponse (com.linkedin.r2.message.rest.RestResponse)7 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)6 FlowConfig (org.apache.gobblin.service.FlowConfig)6 ErrorResponse (com.linkedin.restli.common.ErrorResponse)5 HashMap (java.util.HashMap)5 RemoteInvocationException (com.linkedin.r2.RemoteInvocationException)4 MockRestliResponseExceptionBuilder (com.linkedin.restli.client.testutils.MockRestliResponseExceptionBuilder)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)4 AutoValidationWithProjectionBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationWithProjectionBuilders)4 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)4 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)4 GroupMembershipParam (com.linkedin.restli.examples.groups.api.GroupMembershipParam)4