Search in sources :

Example 6 with LinkArray

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

the class TestCollectionResponseBuilder method dataProvider.

@DataProvider(name = "testData")
public Object[][] dataProvider() throws CloneNotSupportedException {
    Foo metadata = new Foo().setStringField("metadata").setIntField(7);
    Foo projectedMetadata = new Foo().setIntField(7);
    final List<Foo> generatedList = generateTestList();
    final List<Foo> testListWithProjection = generateTestListWithProjection();
    CollectionResult<Foo, Foo> collectionResult = new CollectionResult<>(generatedList, generatedList.size(), metadata);
    DataMap dataProjectionDataMap = new DataMap();
    dataProjectionDataMap.put("stringField", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    MaskTree dataMaskTree = new MaskTree(dataProjectionDataMap);
    DataMap metadataProjectionDataMap = new DataMap();
    metadataProjectionDataMap.put("intField", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    MaskTree metadataMaskTree = new MaskTree(metadataProjectionDataMap);
    DataMap pagingProjectDataMap = new DataMap();
    pagingProjectDataMap.put("count", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    MaskTree pagingMaskTree = new MaskTree(pagingProjectDataMap);
    CollectionMetadata collectionMetadata1 = new CollectionMetadata().setCount(10).setStart(0).setLinks(new LinkArray());
    CollectionMetadata collectionMetadata2 = collectionMetadata1.clone().setTotal(2);
    CollectionMetadata collectionMetadataWithProjection = new CollectionMetadata().setCount(10);
    ProjectionMode auto = ProjectionMode.AUTOMATIC;
    ProjectionMode manual = ProjectionMode.MANUAL;
    List<Object[]> data = new ArrayList<>();
    for (ResourceMethod resourceMethod : BUILDERS.keySet()) {
        // auto projection for data and metadata with null projection masks
        data.add(new Object[] { generatedList, null, generatedList, collectionMetadata1, null, null, null, auto, auto, resourceMethod });
        data.add(new Object[] { collectionResult, metadata.data(), collectionResult.getElements(), collectionMetadata2, null, null, null, auto, auto, resourceMethod });
        // manual projection for data and metadata with null projection masks
        data.add(new Object[] { generatedList, null, generatedList, collectionMetadata1, null, null, null, manual, manual, resourceMethod });
        data.add(new Object[] { collectionResult, metadata.data(), collectionResult.getElements(), collectionMetadata2, null, null, null, manual, manual, resourceMethod });
        // NOTE - we always apply projections to the CollectionMetaData if the paging MaskTree is non-null
        // since ProjectionMode.AUTOMATIC is used.
        // manual projection for data and metadata with non-null projection masks
        data.add(new Object[] { generatedList, null, generatedList, collectionMetadataWithProjection, dataMaskTree, metadataMaskTree, pagingMaskTree, manual, manual, resourceMethod });
        data.add(new Object[] { collectionResult, metadata.data(), collectionResult.getElements(), collectionMetadataWithProjection, dataMaskTree, metadataMaskTree, pagingMaskTree, manual, manual, resourceMethod });
        // auto projection for data with non-null data and paging projection masks
        data.add(new Object[] { generatedList, null, testListWithProjection, collectionMetadataWithProjection, dataMaskTree, null, pagingMaskTree, auto, auto, resourceMethod });
        // auto projection for data and metadata with non-null projection masks
        data.add(new Object[] { collectionResult, projectedMetadata.data(), testListWithProjection, collectionMetadataWithProjection, dataMaskTree, metadataMaskTree, pagingMaskTree, auto, auto, resourceMethod });
        // auto data projection, manual metadata projection, and auto (default) paging projection
        data.add(new Object[] { collectionResult, metadata.data(), testListWithProjection, collectionMetadataWithProjection, dataMaskTree, metadataMaskTree, pagingMaskTree, auto, manual, resourceMethod });
    }
    return data.toArray(new Object[data.size()][]);
}
Also used : CollectionResult(com.linkedin.restli.server.CollectionResult) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) MaskTree(com.linkedin.data.transform.filter.request.MaskTree) LinkArray(com.linkedin.restli.common.LinkArray) ProjectionMode(com.linkedin.restli.server.ProjectionMode) Foo(com.linkedin.pegasus.generator.examples.Foo) ArrayList(java.util.ArrayList) ResourceMethod(com.linkedin.restli.common.ResourceMethod) DataMap(com.linkedin.data.DataMap) DataProvider(org.testng.annotations.DataProvider)

Aggregations

CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)6 LinkArray (com.linkedin.restli.common.LinkArray)6 ArrayList (java.util.ArrayList)4 DataProvider (org.testng.annotations.DataProvider)4 HighLevelRecordWithDefault (com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault)3 LowLevelRecordWithDefault (com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault)3 Link (com.linkedin.restli.common.Link)2 DataMap (com.linkedin.data.DataMap)1 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)1 Foo (com.linkedin.pegasus.generator.examples.Foo)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 Parameter (com.linkedin.restli.internal.server.model.Parameter)1 CollectionResult (com.linkedin.restli.server.CollectionResult)1 PagingContext (com.linkedin.restli.server.PagingContext)1 ProjectionMode (com.linkedin.restli.server.ProjectionMode)1