Search in sources :

Example 21 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestParseqBasedFluentClientApi method testGetRequestFailure.

@Test
public void testGetRequestFailure() throws Exception {
    Greetings greetings = new GreetingsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CompletionStage<Greeting> result = greetings.get(-1L);
    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) 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 22 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestSimpleResourceHierarchy method testRootSimpleResourceDelete.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testRootSimpleResourceDelete(RootBuilderWrapper<Void, Greeting> builders) throws RemoteInvocationException {
    // DELETE
    Request<EmptyRecord> writeRequest = builders.delete().build();
    getClient().sendRequest(writeRequest).getResponse();
    // GET again, to verify that our DELETE worked.
    try {
        Request<Greeting> request = builders.get().build();
        Response<Greeting> response = getClient().sendRequest(request).getResponse();
        Greeting greeting = response.getEntity();
        Assert.fail("Entity should have been removed.");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
    }
    // Restore initial state
    testRootSimpleResourceUpdate(builders);
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) Test(org.testng.annotations.Test)

Example 23 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestTyperefCustomDoubleAssociationKeyResource method testGet.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testGet(RestliRequestOptions requestOptions) throws RemoteInvocationException, URISyntaxException {
    HashMap<String, CompoundKey.TypeInfo> keyParts = new HashMap<>();
    keyParts.put("src", new CompoundKey.TypeInfo(CustomDouble.class, CustomDoubleRef.class));
    keyParts.put("dest", new CompoundKey.TypeInfo(URI.class, UriRef.class));
    GetRequestBuilder<CompoundKey, Message> getBuilder = new GetRequestBuilder<>("typerefCustomDoubleAssociationKeyResource", Message.class, new ResourceSpecImpl(EnumSet.of(ResourceMethod.GET), new HashMap<>(), new HashMap<>(), CompoundKey.class, null, null, Message.class, keyParts), requestOptions);
    final String[] stringArray = { "foo" };
    GetRequest<Message> req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.0)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
    Response<Message> resp = REST_CLIENT.sendRequest(req).getResponse();
    Message result = resp.getEntity();
    Assert.assertEquals(result.getId(), "100.0->www.linkedin.com");
    Assert.assertEquals(result.getMessage(), String.format("I need some $20. Array contents %s.", Arrays.asList(stringArray)));
    // key validation failure scenario
    try {
        req = getBuilder.id(new CompoundKey().append("src", new CustomDouble(100.02)).append("dest", new URI("http://www.linkedin.com/"))).setReqParam("array", stringArray).build();
        REST_CLIENT.sendRequest(req).getResponse();
    } catch (RestLiResponseException ex) {
        Assert.assertEquals(ex.getServiceErrorMessage(), "Input field validation failure, reason: ERROR ::  :: \"100.02\" does not match [0-9]*\\.[0-9]\n");
        Assert.assertEquals(ex.getStatus(), HttpStatus.S_400_BAD_REQUEST.getCode());
    }
}
Also used : UriRef(com.linkedin.restli.examples.typeref.api.UriRef) Message(com.linkedin.restli.examples.greetings.api.Message) HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) CustomDouble(com.linkedin.restli.examples.custom.types.CustomDouble) CustomDoubleRef(com.linkedin.restli.examples.typeref.api.CustomDoubleRef) URI(java.net.URI) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) GetRequestBuilder(com.linkedin.restli.client.GetRequestBuilder) Test(org.testng.annotations.Test)

Example 24 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestRestLiValidation method testBatchFinderAutoWithOverLengthField.

@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithOverLengthField(Object builder) throws RemoteInvocationException {
    try {
        ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(2222).setStringB("hello");
        ValidationDemoCriteria c2 = new ValidationDemoCriteria().setIntA(4444).setStringB("world");
        Request<BatchCollectionResponse<ValidationDemo>> request = new RootBuilderWrapper<Integer, ValidationDemo>(builder).batchFindBy("searchValidationDemos").setQueryParam("criteria", Arrays.asList(c1, c2)).build();
        _restClientAuto.sendRequest(request).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), "BatchCriteria: 0 Element: 0 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n");
    }
}
Also used : BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) ValidationDemoCriteria(com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Example 25 with RestLiResponseException

use of com.linkedin.restli.client.RestLiResponseException in project rest.li by linkedin.

the class TestRestLiValidation method testBatchFinderAutoWithMissingField.

@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithMissingField(Object builder) throws RemoteInvocationException {
    try {
        ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(1111).setStringB("hello");
        ValidationDemoCriteria c2 = new ValidationDemoCriteria().setIntA(4444).setStringB("world");
        Request<BatchCollectionResponse<ValidationDemo>> request = new RootBuilderWrapper<Integer, ValidationDemo>(builder).batchFindBy("searchValidationDemos").setQueryParam("criteria", Arrays.asList(c1, c2)).build();
        _restClientAuto.sendRequest(request).getResponse();
        Assert.fail("Expected RestLiResponseException");
    } catch (RestLiResponseException e) {
        Assert.assertEquals(e.getServiceErrorMessage(), "BatchCriteria: 0 Element: 0 ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringB :: field is required but not found and has no default value\n");
    }
}
Also used : BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) ValidationDemoCriteria(com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria) RestLiResponseException(com.linkedin.restli.client.RestLiResponseException) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) 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