Search in sources :

Example 1 with ResourceProperties

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

the class TestRequest method testResourceProperties.

@Test
public void testResourceProperties() {
    Set<ResourceMethod> expectedSupportedMethods = new HashSet<ResourceMethod>();
    expectedSupportedMethods.add(ResourceMethod.GET);
    expectedSupportedMethods.add(ResourceMethod.BATCH_PARTIAL_UPDATE);
    ResourceSpec expectedResourceSpec = new ResourceSpecImpl(expectedSupportedMethods, null, null, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, Object>emptyMap());
    Map<String, Object> pathKeys = new HashMap<String, Object>();
    pathKeys.put("id", new ComplexResourceKey<TestRecord, TestRecord>(new TestRecord(), new TestRecord()));
    Request<TestRecord> request = new Request<TestRecord>(ResourceMethod.GET, null, Collections.<String, String>emptyMap(), Collections.<HttpCookie>emptyList(), new EntityResponseDecoder<TestRecord>(TestRecord.class), expectedResourceSpec, Collections.<String, Object>emptyMap(), Collections.<String, Class<?>>emptyMap(), null, "testRecord", pathKeys, RestliRequestOptions.DEFAULT_OPTIONS, null);
    ResourceProperties expectedResourceProperties = new ResourcePropertiesImpl(expectedResourceSpec.getSupportedMethods(), expectedResourceSpec.getKeyType(), expectedResourceSpec.getComplexKeyType(), expectedResourceSpec.getValueType(), expectedResourceSpec.getKeyParts());
    Assert.assertEquals(request.getResourceProperties(), expectedResourceProperties);
}
Also used : HashMap(java.util.HashMap) ResourcePropertiesImpl(com.linkedin.restli.internal.common.ResourcePropertiesImpl) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ResourceProperties(com.linkedin.restli.common.ResourceProperties) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceMethod(com.linkedin.restli.common.ResourceMethod) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with ResourceProperties

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

the class TestScatterGather method testRequest.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void testRequest(BatchRequest<?> request, Set<String> expectedParams, Set<PathSpec> expectedFields, Map<Long, Greeting> expectedInput, Set<Set<String>> requestIdSets, Set<Long> requestIds) {
    Assert.assertEquals(request.getQueryParamsObjects().keySet(), expectedParams);
    if (expectedFields != null) {
        Collection<PathSpec> actualFields = (Collection<PathSpec>) request.getQueryParamsObjects().get(RestConstants.FIELDS_PARAM);
        for (PathSpec field : actualFields) {
            Assert.assertTrue(expectedFields.contains(field));
        }
    }
    Set<String> uriIds = new HashSet<String>();
    for (Long id : (Collection<Long>) request.getQueryParamsObjects().get(RestConstants.QUERY_BATCH_IDS_PARAM)) {
        uriIds.add(id.toString());
    }
    if (expectedInput != null) {
        RecordTemplate inputRecordTemplate;
        if (request instanceof BatchUpdateRequest) {
            ResourceProperties resourceProperties = request.getResourceProperties();
            CollectionRequest inputRecord = (CollectionRequest) request.getInputRecord();
            inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord, resourceProperties.getKeyType(), resourceProperties.getComplexKeyType(), resourceProperties.getKeyParts(), resourceProperties.getValueType());
        } else {
            inputRecordTemplate = request.getInputRecord();
        }
        checkInput(inputRecordTemplate.data().getDataMap(com.linkedin.restli.common.BatchRequest.ENTITIES), expectedInput, uriIds);
    }
    Set<Object> idObjects = request.getObjectIds();
    Set<String> theseIds = new HashSet<String>(idObjects.size());
    for (Object o : idObjects) {
        theseIds.add(o.toString());
    }
    Assert.assertEquals(uriIds, theseIds);
    //no duplicate requests
    Assert.assertFalse(requestIdSets.contains(theseIds));
    for (String id : theseIds) {
        //no duplicate ids
        Assert.assertFalse(requestIds.contains(Long.parseLong(id)));
        requestIds.add(Long.parseLong(id));
    }
    requestIdSets.add(theseIds);
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) ResourceProperties(com.linkedin.restli.common.ResourceProperties) PathSpec(com.linkedin.data.schema.PathSpec) RecordTemplate(com.linkedin.data.template.RecordTemplate) Collection(java.util.Collection) HashSet(java.util.HashSet)

Example 3 with ResourceProperties

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

the class TestScatterGather method testGetEntityRequest.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void testGetEntityRequest(BatchRequest<BatchKVResponse<Long, EntityResponse<Greeting>>> request, Set<String> expectedParams, Set<PathSpec> expectedFields, Map<Long, Greeting> expectedInput, Set<Set<String>> requestIdSets, Set<Long> requestIds) {
    Assert.assertEquals(request.getQueryParamsObjects().keySet(), expectedParams);
    if (expectedFields != null) {
        Collection<PathSpec> actualFields = (Collection<PathSpec>) request.getQueryParamsObjects().get(RestConstants.FIELDS_PARAM);
        for (PathSpec field : actualFields) {
            Assert.assertTrue(expectedFields.contains(field));
        }
    }
    Set<String> uriIds = new HashSet<String>();
    for (Long id : (Collection<Long>) request.getQueryParamsObjects().get(RestConstants.QUERY_BATCH_IDS_PARAM)) {
        uriIds.add(id.toString());
    }
    if (expectedInput != null) {
        RecordTemplate inputRecordTemplate;
        if (request instanceof BatchUpdateRequest) {
            ResourceProperties resourceProperties = request.getResourceProperties();
            CollectionRequest inputRecord = (CollectionRequest) request.getInputRecord();
            inputRecordTemplate = CollectionRequestUtil.convertToBatchRequest(inputRecord, resourceProperties.getKeyType(), resourceProperties.getComplexKeyType(), resourceProperties.getKeyParts(), resourceProperties.getValueType());
        } else {
            inputRecordTemplate = request.getInputRecord();
        }
        checkInput(inputRecordTemplate.data().getDataMap(com.linkedin.restli.common.BatchRequest.ENTITIES), expectedInput, uriIds);
    }
    Set<Object> idObjects = request.getObjectIds();
    Set<String> theseIds = new HashSet<String>(idObjects.size());
    for (Object o : idObjects) {
        theseIds.add(o.toString());
    }
    Assert.assertEquals(uriIds, theseIds);
    //no duplicate requests
    Assert.assertFalse(requestIdSets.contains(theseIds));
    for (String id : theseIds) {
        //no duplicate ids
        Assert.assertFalse(requestIds.contains(Long.parseLong(id)));
        requestIds.add(Long.parseLong(id));
    }
    requestIdSets.add(theseIds);
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) ResourceProperties(com.linkedin.restli.common.ResourceProperties) PathSpec(com.linkedin.data.schema.PathSpec) RecordTemplate(com.linkedin.data.template.RecordTemplate) Collection(java.util.Collection) HashSet(java.util.HashSet)

Aggregations

ResourceProperties (com.linkedin.restli.common.ResourceProperties)3 HashSet (java.util.HashSet)3 PathSpec (com.linkedin.data.schema.PathSpec)2 RecordTemplate (com.linkedin.data.template.RecordTemplate)2 CollectionRequest (com.linkedin.restli.common.CollectionRequest)2 Collection (java.util.Collection)2 TestRecord (com.linkedin.restli.client.test.TestRecord)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 ResourceSpec (com.linkedin.restli.common.ResourceSpec)1 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)1 ResourcePropertiesImpl (com.linkedin.restli.internal.common.ResourcePropertiesImpl)1 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1