Search in sources :

Example 11 with BatchCollectionResponse

use of com.linkedin.restli.common.BatchCollectionResponse 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 12 with BatchCollectionResponse

use of com.linkedin.restli.common.BatchCollectionResponse 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)

Example 13 with BatchCollectionResponse

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

the class MockBatchCollectionResponseFactory method create.

/**
 * Creates a {@link BatchCollectionResponse} with the specified mock data. Make sure the size of the specified lists
 * are the same as the entries at the same index will be used for generating the instances of
 * {@link com.linkedin.restli.common.BatchFinderCriteriaResult} that goes into the final {@link BatchCollectionResponse}.
 * The specified paging and metadata list can contain null entries if the corresponding criteria result instance must
 * not have the paging and/or metadata set.
 *
 * @param entryClass  the class of elements to be stored in {@link BatchCollectionResponse}
 * @param elementsList A list of list containing the instances of type `entryClass`
 * @param pagingList A list of {@link CollectionMetadata} for paging
 * @param metadataList A list of {@link DataMap} for custom metadata
 * @param <T> the type of elements to be stored in {@link BatchCollectionResponse}
 * @return An instance of {@link BatchCollectionResponse} created with the specified mock data
 */
public static <T extends RecordTemplate> BatchCollectionResponse<T> create(Class<T> entryClass, List<List<T>> elementsList, List<CollectionMetadata> pagingList, List<DataMap> metadataList) {
    DataList batchedCollectionResponse = new DataList(DataMapBuilder.getOptimumHashMapCapacityFromSize(elementsList.size()));
    for (int i = 0; i < elementsList.size(); i++) {
        Collection<T> recordElements = elementsList.get(i);
        DataList elements = recordElements.stream().map(RecordTemplate::data).collect(Collectors.toCollection(DataList::new));
        DataMap collectionResponse = new DataMap(DataMapBuilder.getOptimumHashMapCapacityFromSize(3));
        CheckedUtil.putWithoutCheckingOrChangeNotification(collectionResponse, CollectionResponse.ELEMENTS, elements);
        if (!pagingList.isEmpty()) {
            CollectionMetadata paging = pagingList.get(i);
            if (paging != null) {
                CheckedUtil.putWithoutCheckingOrChangeNotification(collectionResponse, CollectionResponse.PAGING, paging.data());
            }
        }
        if (!metadataList.isEmpty()) {
            DataMap metadata = metadataList.get(i);
            if (metadata != null) {
                CheckedUtil.putWithoutCheckingOrChangeNotification(collectionResponse, CollectionResponse.METADATA, metadata);
            }
        }
        CheckedUtil.addWithoutChecking(batchedCollectionResponse, collectionResponse);
    }
    DataMap batchResponse = new DataMap(DataMapBuilder.getOptimumHashMapCapacityFromSize(1));
    CheckedUtil.putWithoutCheckingOrChangeNotification(batchResponse, CollectionResponse.ELEMENTS, batchedCollectionResponse);
    return new BatchCollectionResponse<>(batchResponse, new BatchFinderCriteriaResultDecoder<>(entryClass));
}
Also used : DataList(com.linkedin.data.DataList) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) DataMap(com.linkedin.data.DataMap)

Example 14 with BatchCollectionResponse

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

the class TestParseqBasedFluentClientApi method testBatchFinder.

@Test
public void testBatchFinder() throws Exception {
    Batchfinders batchfinders = new BatchfindersFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    CompletionStage<BatchCollectionResponse<Greeting>> result = batchfinders.findBySearchGreetings(Arrays.asList(c1, c2), "hello world");
    CompletableFuture<BatchCollectionResponse<Greeting>> future = result.toCompletableFuture();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = future.get(5000, TimeUnit.MILLISECONDS).getResults();
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertEquals(greetings1.get(0).getTone(), Tone.SINCERE);
    List<Greeting> greetings2 = batchResult.get(1).getElements();
    Assert.assertTrue(greetings2.get(0).hasId());
    Assert.assertEquals(greetings2.get(0).getTone(), Tone.FRIENDLY);
}
Also used : Batchfinders(com.linkedin.restli.examples.greetings.client.Batchfinders) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) CreateGreeting(com.linkedin.restli.examples.greetings.client.CreateGreeting) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) PartialUpdateGreeting(com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) BatchfindersFluentClient(com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) Test(org.testng.annotations.Test)

Example 15 with BatchCollectionResponse

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

the class TestRestLiValidation method testBatchFinder.

@Test(dataProvider = "manualBuilders")
public void testBatchFinder(Object builder) throws RemoteInvocationException {
    ValidationDemoCriteria c1 = new ValidationDemoCriteria().setIntA(1111).setStringB("hello");
    ValidationDemoCriteria c2 = new ValidationDemoCriteria().setIntA(1111).setStringB("world");
    Request<BatchCollectionResponse<ValidationDemo>> request = new RootBuilderWrapper<Integer, ValidationDemo>(builder).batchFindBy("searchValidationDemos").setQueryParam("criteria", Arrays.asList(c1, c2)).build();
    Response<BatchCollectionResponse<ValidationDemo>> response = _restClientManual.sendRequest(request).getResponse();
    Assert.assertEquals(response.getStatus(), HttpStatus.S_200_OK.getCode());
}
Also used : BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) ValidationDemoCriteria(com.linkedin.restli.examples.greetings.api.ValidationDemoCriteria) ValidationDemo(com.linkedin.restli.examples.greetings.api.ValidationDemo) Test(org.testng.annotations.Test)

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