Search in sources :

Example 1 with ValidationDemosBuilders

use of com.linkedin.restli.examples.greetings.client.ValidationDemosBuilders in project rest.li by linkedin.

the class TestRestLiValidation method testBatchCreateManualFailure.

@Test(dataProvider = "batchCreateFailureData")
public void testBatchCreateManualFailure(List<ValidationDemo> validationDemos, List<String> errorMessages) throws RemoteInvocationException {
    Response<CollectionResponse<CreateStatus>> response = _restClientManual.sendRequest(new RootBuilderWrapper<Integer, ValidationDemo>(new ValidationDemosBuilders()).batchCreate().inputs(validationDemos).build()).getResponse();
    List<CreateStatus> results = response.getEntity().getElements();
    int i = 0;
    for (CreateStatus result : results) {
        Assert.assertEquals((int) result.getStatus(), HttpStatus.S_422_UNPROCESSABLE_ENTITY.getCode());
        Assert.assertTrue(result.getError().getMessage().contains(errorMessages.get(i++)));
    }
    response = _restClientManual.sendRequest(new RootBuilderWrapper<Integer, ValidationDemo>(new ValidationDemosRequestBuilders()).batchCreate().inputs(validationDemos).build()).getResponse();
    @SuppressWarnings("unchecked") List<CreateIdStatus<Integer>> results2 = ((BatchCreateIdResponse<Integer>) (Object) response.getEntity()).getElements();
    i = 0;
    for (CreateIdStatus<Integer> result : results2) {
        Assert.assertEquals((int) result.getStatus(), HttpStatus.S_422_UNPROCESSABLE_ENTITY.getCode());
        Assert.assertTrue(result.getError().getMessage().contains(errorMessages.get(i++)));
    }
}
Also used : CreateStatus(com.linkedin.restli.common.CreateStatus) CollectionResponse(com.linkedin.restli.common.CollectionResponse) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) RootBuilderWrapper(com.linkedin.restli.test.util.RootBuilderWrapper) CreateIdStatus(com.linkedin.restli.common.CreateIdStatus) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) ValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.ValidationDemosBuilders) AutoValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders) AutoValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders) ValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.ValidationDemosRequestBuilders) Test(org.testng.annotations.Test)

Example 2 with ValidationDemosBuilders

use of com.linkedin.restli.examples.greetings.client.ValidationDemosBuilders in project rest.li by linkedin.

the class TestRestLiValidation method testBatchGet.

@Test
public void testBatchGet() throws RemoteInvocationException {
    BatchGetRequest<ValidationDemo> request = new ValidationDemosBuilders().batchGet().ids(1, 2, 3).build();
    Response<BatchResponse<ValidationDemo>> response = _restClientManual.sendRequest(request).getResponse();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
    BatchGetEntityRequest<Integer, ValidationDemo> request2 = new ValidationDemosRequestBuilders().batchGet().ids(1, 2, 3).build();
    Response<BatchKVResponse<Integer, EntityResponse<ValidationDemo>>> response2 = _restClientManual.sendRequest(request2).getResponse();
    Assert.assertEquals(response2.getStatus(), HttpStatus.S_200_OK.getCode());
}
Also used : ValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.ValidationDemosBuilders) AutoValidationDemosBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders) BatchResponse(com.linkedin.restli.common.BatchResponse) AutoValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders) ValidationDemosRequestBuilders(com.linkedin.restli.examples.greetings.client.ValidationDemosRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

Aggregations

ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)2 AutoValidationDemosBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationDemosBuilders)2 AutoValidationDemosRequestBuilders (com.linkedin.restli.examples.greetings.client.AutoValidationDemosRequestBuilders)2 ValidationDemosBuilders (com.linkedin.restli.examples.greetings.client.ValidationDemosBuilders)2 ValidationDemosRequestBuilders (com.linkedin.restli.examples.greetings.client.ValidationDemosRequestBuilders)2 Test (org.testng.annotations.Test)2 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)1 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)1 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)1 BatchResponse (com.linkedin.restli.common.BatchResponse)1 CollectionResponse (com.linkedin.restli.common.CollectionResponse)1 CreateIdStatus (com.linkedin.restli.common.CreateIdStatus)1 CreateStatus (com.linkedin.restli.common.CreateStatus)1 RootBuilderWrapper (com.linkedin.restli.test.util.RootBuilderWrapper)1