Search in sources :

Example 31 with Foo

use of com.linkedin.pegasus.generator.examples.Foo in project rest.li by linkedin.

the class TestBatchCreateResponseBuilder method provideReturnEntityData.

@DataProvider(name = "returnEntityData")
public Object[][] provideReturnEntityData() {
    CreateResponse createResponse = new CreateResponse(1L, HttpStatus.S_201_CREATED);
    List<CreateResponse> createResponses = new ArrayList<>();
    createResponses.add(createResponse);
    BatchCreateResult<Long, Foo> batchCreateResult = new BatchCreateResult<>(createResponses);
    Foo entity = new Foo().setStringField("value").setFruitsField(Fruits.APPLE);
    CreateKVResponse<Long, Foo> createKVResponse = new CreateKVResponse<>(1L, entity);
    List<CreateKVResponse<Long, Foo>> createKVResponses = new ArrayList<>();
    createKVResponses.add(createKVResponse);
    BatchCreateKVResult<Long, Foo> batchCreateKVResult = new BatchCreateKVResult<>(createKVResponses);
    return new Object[][] { { batchCreateResult, createResponses, true, false }, { batchCreateResult, createResponses, false, false }, { batchCreateKVResult, createKVResponses, true, true }, { batchCreateKVResult, createKVResponses, false, false } };
}
Also used : CreateResponse(com.linkedin.restli.server.CreateResponse) Foo(com.linkedin.pegasus.generator.examples.Foo) ArrayList(java.util.ArrayList) BatchCreateResult(com.linkedin.restli.server.BatchCreateResult) BatchCreateKVResult(com.linkedin.restli.server.BatchCreateKVResult) CreateKVResponse(com.linkedin.restli.server.CreateKVResponse) DataProvider(org.testng.annotations.DataProvider)

Example 32 with Foo

use of com.linkedin.pegasus.generator.examples.Foo 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

Foo (com.linkedin.pegasus.generator.examples.Foo)32 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)16 Test (org.testng.annotations.Test)16 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)14 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)10 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 DataProvider (org.testng.annotations.DataProvider)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)9 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)8 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)8 DataMap (com.linkedin.data.DataMap)7 CreateKVResponse (com.linkedin.restli.server.CreateKVResponse)7 URI (java.net.URI)7 PathSpec (com.linkedin.data.schema.PathSpec)6 RecordTemplate (com.linkedin.data.template.RecordTemplate)5 RestRequest (com.linkedin.r2.message.rest.RestRequest)5 CompoundKey (com.linkedin.restli.common.CompoundKey)5 BatchResult (com.linkedin.restli.server.BatchResult)5 RequestContext (com.linkedin.r2.message.RequestContext)4