Search in sources :

Example 1 with HighLevelRecordWithDefault

use of com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault in project rest.li by linkedin.

the class FieldFillInDefaultResources method getAllHighLevelRecordWithDefault.

@RestMethod.GetAll
public CollectionResult<HighLevelRecordWithDefault, LowLevelRecordWithDefault> getAllHighLevelRecordWithDefault(@PagingContextParam PagingContext pagingContext) {
    final int total = 3;
    List<HighLevelRecordWithDefault> elements = new LinkedList<>();
    for (int i = 0; i < total; i++) {
        elements.add(new HighLevelRecordWithDefault().setNoDefaultFieldA(i));
    }
    LowLevelRecordWithDefault metadata = new LowLevelRecordWithDefault();
    return new CollectionResult<>(elements, total, metadata);
}
Also used : CollectionResult(com.linkedin.restli.server.CollectionResult) LowLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault) LinkedList(java.util.LinkedList) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault)

Example 2 with HighLevelRecordWithDefault

use of com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault in project rest.li by linkedin.

the class TestFillInDefaultValue method testGetAllData.

@DataProvider(name = "testGetAllData")
private Object[][] testGetAllData() throws CloneNotSupportedException {
    final int count = 3;
    List<HighLevelRecordWithDefault> elements = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        elements.add(new HighLevelRecordWithDefault(expectedTestData.clone()).setNoDefaultFieldA(i));
    }
    CollectionMetadata collectionMetadata = new CollectionMetadata().setCount(10).setTotal(3).setStart(0).setLinks(new LinkArray());
    LowLevelRecordWithDefault metadata = new LowLevelRecordWithDefault();
    metadata.setNameWithDefault(metadata.getNameWithDefault());
    return new Object[][] { { elements, collectionMetadata, metadata } };
}
Also used : CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) LinkArray(com.linkedin.restli.common.LinkArray) ArrayList(java.util.ArrayList) LowLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) DataProvider(org.testng.annotations.DataProvider)

Example 3 with HighLevelRecordWithDefault

use of com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault in project rest.li by linkedin.

the class TestFillInDefaultValue method testGet.

@Test(dataProvider = "testGetData")
public void testGet(Long id, HighLevelRecordWithDefault expectedRecord) throws RemoteInvocationException, IOException {
    FillInDefaultsRequestBuilders requestBuilders = new FillInDefaultsRequestBuilders();
    FillInDefaultsGetRequestBuilder getRequestBuilder = requestBuilders.get();
    GetRequest<HighLevelRecordWithDefault> req = getRequestBuilder.id(id).setParam(RestConstants.FILL_IN_DEFAULTS_PARAM, true).build();
    HighLevelRecordWithDefault actual = getClient().sendRequest(req).getResponse().getEntity();
    Assert.assertEquals(actual, expectedRecord);
}
Also used : FillInDefaultsGetRequestBuilder(com.linkedin.restli.examples.defaults.api.FillInDefaultsGetRequestBuilder) FillInDefaultsRequestBuilders(com.linkedin.restli.examples.defaults.api.FillInDefaultsRequestBuilders) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) Test(org.testng.annotations.Test)

Example 4 with HighLevelRecordWithDefault

use of com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault in project rest.li by linkedin.

the class TestFillInDefaultValue method testFillInDefaultBatchGet.

@Test(dataProvider = "testBatchGetData")
public void testFillInDefaultBatchGet(Long[] ids, HighLevelRecordWithDefault[] expected) throws RemoteInvocationException {
    Map<Integer, HighLevelRecordWithDefault> idToRecord = new HashMap<>();
    for (int i = 0; i < ids.length; i++) {
        idToRecord.put(Math.toIntExact(ids[i]), expected[i]);
    }
    FillInDefaultsRequestBuilders builders = new FillInDefaultsRequestBuilders();
    BatchGetEntityRequest<Long, HighLevelRecordWithDefault> request = builders.batchGet().setParam(RestConstants.FILL_IN_DEFAULTS_PARAM, true).ids(ids).build();
    BatchKVResponse<Long, EntityResponse<HighLevelRecordWithDefault>> batchKVResponse = getClient().sendRequest(request).getResponse().getEntity();
    for (Map.Entry<Long, EntityResponse<HighLevelRecordWithDefault>> entry : batchKVResponse.getResults().entrySet()) {
        HighLevelRecordWithDefault actualEntity = entry.getValue().getEntity();
        Assert.assertEquals(actualEntity, idToRecord.getOrDefault(actualEntity.getNoDefaultFieldA(), null));
    }
}
Also used : HashMap(java.util.HashMap) EntityResponse(com.linkedin.restli.common.EntityResponse) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) FillInDefaultsRequestBuilders(com.linkedin.restli.examples.defaults.api.FillInDefaultsRequestBuilders) Test(org.testng.annotations.Test)

Example 5 with HighLevelRecordWithDefault

use of com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault in project rest.li by linkedin.

the class TestFillInDefaultValue method testGetWithFillInDefaults.

@Test(dataProvider = "testGetDataNoFillIn")
public void testGetWithFillInDefaults(Long id, HighLevelRecordWithDefault expectedRecord) throws RemoteInvocationException {
    FillInDefaultsRequestBuilders requestBuilders = new FillInDefaultsRequestBuilders();
    FillInDefaultsGetRequestBuilder getRequestBuilder = requestBuilders.get();
    GetRequest<HighLevelRecordWithDefault> req = getRequestBuilder.id(id).build();
    HighLevelRecordWithDefault actual = getClient().sendRequest(req).getResponse().getEntity();
    Assert.assertEquals(actual, expectedRecord);
}
Also used : FillInDefaultsGetRequestBuilder(com.linkedin.restli.examples.defaults.api.FillInDefaultsGetRequestBuilder) FillInDefaultsRequestBuilders(com.linkedin.restli.examples.defaults.api.FillInDefaultsRequestBuilders) HighLevelRecordWithDefault(com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault) Test(org.testng.annotations.Test)

Aggregations

HighLevelRecordWithDefault (com.linkedin.restli.examples.defaults.api.HighLevelRecordWithDefault)16 FillInDefaultsRequestBuilders (com.linkedin.restli.examples.defaults.api.FillInDefaultsRequestBuilders)8 Test (org.testng.annotations.Test)8 DataProvider (org.testng.annotations.DataProvider)6 LowLevelRecordWithDefault (com.linkedin.restli.examples.defaults.api.LowLevelRecordWithDefault)5 ArrayList (java.util.ArrayList)4 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)3 LinkArray (com.linkedin.restli.common.LinkArray)3 DataMap (com.linkedin.data.DataMap)2 FillInDefaultsGetRequestBuilder (com.linkedin.restli.examples.defaults.api.FillInDefaultsGetRequestBuilder)2 RecordCriteria (com.linkedin.restli.examples.defaults.api.RecordCriteria)2 CollectionResult (com.linkedin.restli.server.CollectionResult)2 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)1 EntityResponse (com.linkedin.restli.common.EntityResponse)1 BatchFinder (com.linkedin.restli.server.annotations.BatchFinder)1 Finder (com.linkedin.restli.server.annotations.Finder)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1