Search in sources :

Example 16 with BatchCollectionResponse

use of com.linkedin.restli.common.BatchCollectionResponse in project rest.li by linkedin.

the class TestRestLiValidation method testBatchFinderAutoWithMultipleErrorFields.

@Test(dataProvider = "autoBuilders")
public void testBatchFinderAutoWithMultipleErrorFields(Object builder) throws RemoteInvocationException {
    try {
        ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(3333).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" + "ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 1 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "ERROR :: /stringB :: field is required but not found and has no default value\n" + "BatchCriteria: 0 Element: 2 ERROR :: /stringA :: length of \"longLengthValueA\" is out of range 1...10\n" + "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)

Example 17 with BatchCollectionResponse

use of com.linkedin.restli.common.BatchCollectionResponse in project rest.li by linkedin.

the class TestAssociationsResource method testBatchFinder.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testBatchFinder(RootBuilderWrapper<CompoundKey, Message> builders) throws RemoteInvocationException {
    MessageCriteria m1 = new MessageCriteria().setMessage("hello").setTone(Tone.FRIENDLY);
    MessageCriteria m2 = new MessageCriteria().setMessage("world").setTone(Tone.SINCERE);
    Request<BatchCollectionResponse<Message>> request = builders.batchFindBy("searchMessages").assocKey("src", "KEY1").setQueryParam("criteria", Arrays.asList(m1, m2)).build();
    ResponseFuture<BatchCollectionResponse<Message>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Message> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Message>> batchResult = response.getResults();
    // on success
    List<Message> messages = batchResult.get(0).getElements();
    Assert.assertTrue(messages.get(0).hasTone());
    Assert.assertTrue(messages.get(0).getTone().equals(Tone.FRIENDLY));
    // on error
    Assert.assertTrue(batchResult.get(1).isError());
    ErrorResponse error = batchResult.get(1).getError();
    Assert.assertEquals(error.getMessage(), "Failed to find message!");
}
Also used : BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) Message(com.linkedin.restli.examples.greetings.api.Message) MessageCriteria(com.linkedin.restli.examples.greetings.api.MessageCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 18 with BatchCollectionResponse

use of com.linkedin.restli.common.BatchCollectionResponse in project rest.li by linkedin.

the class BatchFinderResponseBuilder method buildResponse.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public RestLiResponse buildResponse(RoutingResult routingResult, RestLiResponseData<BatchFinderResponseEnvelope> responseData) {
    BatchFinderResponseEnvelope response = responseData.getResponseEnvelope();
    DataMap dataMap = new DataMap();
    DataList elementsMap = new DataList();
    for (BatchFinderEntry entry : response.getItems()) {
        CheckedUtil.addWithoutChecking(elementsMap, entry.toResponse(_errorResponseBuilder));
    }
    CheckedUtil.putWithoutChecking(dataMap, CollectionResponse.ELEMENTS, elementsMap);
    BatchCollectionResponse<?> collectionResponse = new BatchCollectionResponse<>(dataMap, null);
    RestLiResponse.Builder builder = new RestLiResponse.Builder();
    return builder.entity(collectionResponse).headers(responseData.getHeaders()).cookies(responseData.getCookies()).build();
}
Also used : DataList(com.linkedin.data.DataList) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchFinderEntry(com.linkedin.restli.internal.server.response.BatchFinderResponseEnvelope.BatchFinderEntry) DataMap(com.linkedin.data.DataMap)

Aggregations

BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)18 Test (org.testng.annotations.Test)16 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)11 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)10 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)10 ValidationDemo (com.linkedin.restli.examples.greetings.api.ValidationDemo)7 ErrorResponse (com.linkedin.restli.common.ErrorResponse)6 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)5 ValidationDemoCriteria (com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria)5 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)3 Batchfinders (com.linkedin.restli.examples.greetings.client.Batchfinders)3 BatchfindersFluentClient (com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient)3 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)3 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)3 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)2 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)2 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)2 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)2 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)2 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2