Search in sources :

Example 46 with PathSpec

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

the class TestClientBuilders method testBatchGetCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchGetWithEncoding")
public void testBatchGetCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
    BatchGetRequestBuilder<CompoundKey, TestRecord> builder = new BatchGetRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    CompoundKey key1 = new CompoundKey();
    key1.append("equals", "=");
    key1.append("ampersand", "&");
    CompoundKey key2 = new CompoundKey();
    key2.append("equals", "==");
    key2.append("ampersand", "&&");
    BatchGetKVRequest<CompoundKey, TestRecord> request = builder.ids(key1, key2).fields(TestRecord.fields().id(), TestRecord.fields().message()).buildKV();
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    // Compare key sets. Note that have to convert keys to Strings as the request internally converts them to string
    HashSet<CompoundKey> expectedIds = new HashSet<CompoundKey>(Arrays.asList(key1, key2));
    Assert.assertEquals(request.getObjectIds(), expectedIds);
    Assert.assertEquals(request.getFields(), new HashSet<PathSpec>(Arrays.asList(TestRecord.fields().id(), TestRecord.fields().message())));
    Assert.assertEquals(request.isSafe(), true);
    Assert.assertEquals(request.isIdempotent(), true);
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_GET, null, Collections.<String, String>emptyMap(), null);
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) TestRecord(com.linkedin.restli.client.test.TestRecord) PathSpec(com.linkedin.data.schema.PathSpec) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 47 with PathSpec

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

the class TestClientBuilders method checkRequestIsReadOnly.

@SuppressWarnings("unchecked")
private void checkRequestIsReadOnly(final Request<?> request) {
    final Set<PathSpec> fields = request.getFields();
    if (fields != null) {
        checkReadOnlyOperation(new Runnable() {

            @Override
            public void run() {
                fields.add(new PathSpec("abc"));
            }
        });
    }
    checkReadOnlyOperation(new Runnable() {

        @Override
        public void run() {
            request.getHeaders().put("abc", "abc");
        }
    });
    final RecordTemplate input = request.getInputRecord();
    if (input != null) {
        checkReadOnlyOperation(new Runnable() {

            @Override
            public void run() {
                input.data().put("abc", "abc");
            }
        });
    }
    final Map<String, Object> pathKeys = request.getPathKeys();
    if (pathKeys != null) {
        checkReadOnlyOperation(new Runnable() {

            @Override
            public void run() {
                pathKeys.put("abc", "abc");
            }
        });
        final List<Object> keysToEdit = new ArrayList<Object>();
        for (Object key : pathKeys.values()) {
            if (key instanceof CompoundKey || key instanceof ComplexResourceKey) {
                keysToEdit.add(key);
            } else {
                Assert.assertTrue(isPrimitiveOrEnum(key));
            }
        }
        for (final Object keytoEdit : keysToEdit) {
            checkReadOnlyOperation(new Runnable() {

                @Override
                public void run() {
                    if (keytoEdit instanceof ComplexResourceKey) {
                        ((ComplexResourceKey) keytoEdit).getKey().data().put("abc", "abc");
                    } else if (keytoEdit instanceof CompoundKey) {
                        ((CompoundKey) keytoEdit).append("abc", "abc");
                    }
                }
            });
        }
        Collection<Object> queryParamObjects = request.getQueryParamsObjects().values();
        List<Object> readOnlyTargets = new ArrayList<Object>();
        for (Object queryParamObject : queryParamObjects) {
            collectReadOnlyQueryParamObjectTargets(queryParamObject, readOnlyTargets);
        }
        for (final Object readOnlyTarget : readOnlyTargets) {
            checkReadOnlyOperation(new Runnable() {

                @Override
                public void run() {
                    if (readOnlyTarget instanceof DataTemplate) {
                        Object data = ((DataTemplate) readOnlyTarget).data();
                        if (data instanceof DataMap) {
                            ((DataMap) data).put("abc", "abc");
                        } else if (data instanceof DataList) {
                            ((DataList) data).add("abc");
                        }
                    } else if (readOnlyTarget instanceof CompoundKey) {
                        ((CompoundKey) readOnlyTarget).append("abc", "abc");
                    } else if (readOnlyTarget instanceof ComplexResourceKey) {
                        ((ComplexResourceKey) readOnlyTarget).getKey().data().put("abc", "abc");
                    } else if (readOnlyTarget instanceof List) {
                        ((List<Object>) readOnlyTarget).add("abc");
                    }
                }
            });
        }
    }
}
Also used : CompoundKey(com.linkedin.restli.common.CompoundKey) DataTemplate(com.linkedin.data.template.DataTemplate) ArrayList(java.util.ArrayList) ByteString(com.linkedin.data.ByteString) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) DataList(com.linkedin.data.DataList) RecordTemplate(com.linkedin.data.template.RecordTemplate) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) List(java.util.List) ArrayList(java.util.ArrayList) DataList(com.linkedin.data.DataList)

Example 48 with PathSpec

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

the class TestPathSpec method testUnionPathSpec.

@Test
public void testUnionPathSpec() {
    PathSpec p = UnionTest.fields().unionWithInline().RecordInUnion().a();
    Assert.assertEquals(p.toString(), "/unionWithInline/com.linkedin.pegasus.generator.test.RecordInUnion/a");
    p = UnionTest.fields().unionWithoutNull().RecordBar().location();
    Assert.assertEquals(p.toString(), "/unionWithoutNull/com.linkedin.pegasus.generator.test.RecordBar/location");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 49 with PathSpec

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

the class TestPathSpec method testSelfReferencePathSpec.

@Test
public void testSelfReferencePathSpec() {
    PathSpec p = AliasTest.fields().a1().a1().a1().a1();
    Assert.assertEquals(p.toString(), "/a1/a1/a1/a1");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

Example 50 with PathSpec

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

the class TestPathSpec method testTyperefPathSpec.

@Test
public void testTyperefPathSpec() {
    PathSpec p = TyperefTest.fields().bar1().location();
    Assert.assertEquals(p.toString(), "/bar1/location");
    p = TyperefTest.fields().barRefMap().values().location();
    Assert.assertEquals(p.toString(), "/barRefMap/*/location");
}
Also used : PathSpec(com.linkedin.data.schema.PathSpec) Test(org.testng.annotations.Test)

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