Search in sources :

Example 66 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestAbstractRequestBuilder method testProjectionFields.

@Test
public void testProjectionFields() {
    final AbstractRequestBuilder<?, ?, ?> builder = new DummyAbstractRequestBuilder();
    builder.addFields(new PathSpec("firstField"), new PathSpec("secondField", PathSpec.WILDCARD, "thirdField"));
    Assert.assertTrue(builder.getParam(RestConstants.FIELDS_PARAM) instanceof PathSpec[]);
    final PathSpec[] fieldsPathSpecs = (PathSpec[]) builder.getParam(RestConstants.FIELDS_PARAM);
    Assert.assertEquals(fieldsPathSpecs[0].toString(), "/firstField", "The path spec(s) should match!");
    Assert.assertEquals(fieldsPathSpecs[1].toString(), "/secondField/*/thirdField", "The path spec(s) should match!");
    builder.addMetadataFields(new PathSpec(PathSpec.WILDCARD, "fourthField"), new PathSpec("fifthField"));
    Assert.assertTrue(builder.getParam(RestConstants.METADATA_FIELDS_PARAM) instanceof PathSpec[]);
    final PathSpec[] metadataFieldsPathSpecs = (PathSpec[]) builder.getParam(RestConstants.METADATA_FIELDS_PARAM);
    Assert.assertEquals(metadataFieldsPathSpecs[0].toString(), "/*/fourthField", "The path spec(s) should match!");
    Assert.assertEquals(metadataFieldsPathSpecs[1].toString(), "/fifthField", "The path spec(s) should match!");
    builder.addPagingFields(new PathSpec("sixthField", PathSpec.WILDCARD), new PathSpec("seventhField"), new PathSpec(PathSpec.WILDCARD));
    Assert.assertTrue(builder.getParam(RestConstants.PAGING_FIELDS_PARAM) instanceof PathSpec[]);
    final PathSpec[] pagingFieldsPathSpecs = (PathSpec[]) builder.getParam(RestConstants.PAGING_FIELDS_PARAM);
    Assert.assertEquals(pagingFieldsPathSpecs[0].toString(), "/sixthField/*", "The path spec(s) should match!");
    Assert.assertEquals(pagingFieldsPathSpecs[1].toString(), "/seventhField", "The path spec(s) should match!");
    Assert.assertEquals(builder.buildReadOnlyQueryParameters().size(), 3, "We should have 3 query parameters, one for each projection type");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 67 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestMaskCreation method testMixedMask.

@Test
public void testMixedMask() {
    MaskTree mask = new MaskTree();
    mask.addOperation(new PathSpec("foo", "bar"), MaskOperation.POSITIVE_MASK_OP);
    mask.addOperation(new PathSpec("baz", "qux"), MaskOperation.NEGATIVE_MASK_OP);
    //"{baz={qux=0}, foo={bar=1}}"
    final DataMap bazFooMap = new DataMap();
    final DataMap bazMap = new DataMap();
    final DataMap fooMap = new DataMap();
    bazMap.put("qux", MaskOperation.NEGATIVE_MASK_OP.getRepresentation());
    fooMap.put("bar", MaskOperation.POSITIVE_MASK_OP.getRepresentation());
    bazFooMap.put("baz", bazMap);
    bazFooMap.put("foo", fooMap);
    Assert.assertEquals(mask.getDataMap(), bazFooMap, "The MaskTree DataMap should match");
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 68 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestPatchCreation method testExplicitPatchCreationSet.

@Test
public void testExplicitPatchCreationSet() {
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.setFieldOp(42));
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.setFieldOp("The quick brown fox"));
    //"{$set={foo=42}, bar={$set={baz=The quick brown fox}}}"
    final DataMap setBarMap = new DataMap();
    final DataMap bazMap = new DataMap();
    bazMap.put("baz", "The quick brown fox");
    final DataMap setMap = new DataMap();
    setMap.put(PatchConstants.SET_COMMAND, bazMap);
    setBarMap.put("bar", setMap);
    final DataMap fooMap = new DataMap();
    fooMap.put("foo", 42);
    setBarMap.put(PatchConstants.SET_COMMAND, fooMap);
    assertEquals(patch.getDataMap(), setBarMap, "PatchTree DataMap must be correct");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 69 with PathSpec

use of com.linkedin.data.schema.PathSpec in project rest.li by linkedin.

the class TestPatchCreation method testExplicitPatchCreationRemove.

@Test
public void testExplicitPatchCreationRemove() {
    PatchTree patch = new PatchTree();
    patch.addOperation(new PathSpec("foo"), PatchOpFactory.REMOVE_FIELD_OP);
    patch.addOperation(new PathSpec("bar", "baz"), PatchOpFactory.REMOVE_FIELD_OP);
    Assert.assertEquals(patch.toString(), "{bar={$delete=[baz]}, $delete=[foo]}");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) Test(org.testng.annotations.Test)

Example 70 with PathSpec

use of com.linkedin.data.schema.PathSpec 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)

Aggregations

PathSpec (com.linkedin.data.schema.PathSpec)79 Test (org.testng.annotations.Test)63 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)31 DataMap (com.linkedin.data.DataMap)21 HashSet (java.util.HashSet)11 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)9 DataList (com.linkedin.data.DataList)8 RecordTemplate (com.linkedin.data.template.RecordTemplate)7 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)7 ByteString (com.linkedin.data.ByteString)6 ArrayList (java.util.ArrayList)6 Foo (com.linkedin.pegasus.generator.examples.Foo)5 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)5 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)5 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)5 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)5 AfterTest (org.testng.annotations.AfterTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 TestRecord (com.linkedin.restli.client.test.TestRecord)4 List (java.util.List)4