Search in sources :

Example 1 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class ResourceSchemaToResourceSpecTranslator method toDynamicRecordMetadata.

private ActionCollectionMetadata toDynamicRecordMetadata(ActionSchemaArray actions, ActionSchemaArray entityActions) {
    Map<String, DynamicRecordMetadata> response = new HashMap<>();
    Map<String, DynamicRecordMetadata> request = new HashMap<>();
    ActionSchemaArray[] actionGroups = new ActionSchemaArray[] { actions, entityActions };
    for (ActionSchemaArray actionGroup : actionGroups) {
        if (actionGroup != null) {
            for (ActionSchema action : actionGroup) {
                ActionMetadata metadata = toActionMetadata(action);
                request.put(metadata._name, metadata._request);
                response.put(metadata._name, metadata._response);
            }
        }
    }
    return new ActionCollectionMetadata(request, response);
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) HashMap(java.util.HashMap) ActionSchemaArray(com.linkedin.restli.restspec.ActionSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 2 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class TestResourceSchemaToResourceSpecTranslator method compareActions.

private void compareActions(ResourceSpec actual, ResourceSpec expected, ActionSchemaArray actions) {
    for (ActionSchema action : actions) {
        ParameterSchemaArray parameters = action.getParameters();
        DynamicRecordMetadata actualRequest = actual.getRequestMetadata(action.getName());
        DynamicRecordMetadata expectedRequest = expected.getRequestMetadata(action.getName());
        if (expectedRequest != null) {
            Assert.assertNotNull(actualRequest);
            Assert.assertEquals(actualRequest.getRecordDataSchema(), expectedRequest.getRecordDataSchema());
            if (parameters != null) {
                for (ParameterSchema parameter : parameters) {
                    compareFieldDef(actualRequest.getFieldDef(parameter.getName()), expectedRequest.getFieldDef(parameter.getName()));
                }
            }
        } else {
            Assert.assertNull(actualRequest);
        }
        compareParameters(actual.getActionResponseMetadata(action.getName()), expected.getActionResponseMetadata(action.getName()));
    }
}
Also used : DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ParameterSchema(com.linkedin.restli.restspec.ParameterSchema) ParameterSchemaArray(com.linkedin.restli.restspec.ParameterSchemaArray) ActionSchema(com.linkedin.restli.restspec.ActionSchema)

Example 3 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class TestClientBuilders method testActionRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "action")
public void testActionRequestBuilder(URIDetails expectedURIDetails) {
    FieldDef<String> pParam = new FieldDef<>("p", String.class, DataTemplateUtil.getSchema(String.class));
    Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
    DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>singleton(pParam));
    requestMetadataMap.put("action", requestMetadata);
    DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
    Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<>();
    responseMetadataMap.put("action", responseMetadata);
    ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, Long.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
    ActionRequestBuilder<Long, TestRecord> builder = new ActionRequestBuilder<>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, "42").id(1L).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
    DataMap d = new DataMap();
    d.put("p", "42");
    @SuppressWarnings("unchecked") DynamicRecordTemplate expectedRecordTemplate = new DynamicRecordTemplate(d, DynamicRecordMetadata.buildSchema("action", Arrays.asList(new FieldDef<>("p", String.class, DataTemplateUtil.getSchema(String.class)))));
    URIDetails.testUriGeneration(request, expectedURIDetails);
    Assert.assertEquals(request.getMethod(), ResourceMethod.ACTION);
    Assert.assertEquals(request.getHeaders(), Collections.<String, String>emptyMap());
    Assert.assertEquals(request.getInputRecord(), expectedRecordTemplate);
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    Assert.assertEquals(request.getStreamingAttachments(), _streamingDataSources);
    try {
        request.getStreamingAttachments().add(new RestLiTestAttachmentDataSource("1", ByteString.empty()));
        Assert.fail("Should not be able to add to an immutable list");
    } catch (Exception e) {
        Assert.assertTrue(e instanceof UnsupportedOperationException);
    }
    Assert.assertEquals(request.getResponseDecoder().getEntityClass(), Void.class);
}
Also used : HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) RestLiTestAttachmentDataSource(com.linkedin.restli.internal.testutils.RestLiTestAttachmentDataSource) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 4 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class TestClientBuilders method testActionRequestNullOptionalParams.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "action")
public void testActionRequestNullOptionalParams(URIDetails expectedURIDetails) {
    FieldDef<String> pParam = new FieldDef<>("p", String.class, DataTemplateUtil.getSchema(String.class));
    Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
    DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>singleton(pParam));
    requestMetadataMap.put("action", requestMetadata);
    DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
    Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<>();
    responseMetadataMap.put("action", responseMetadata);
    ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, Long.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
    ActionRequestBuilder<Long, TestRecord> builder = new ActionRequestBuilder<>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
    pParam.getField().setOptional(true);
    ActionRequest<TestRecord> requestNullOptionalValue = builder.name("action").setParam(pParam, null).id(2L).build();
    Assert.assertEquals(requestNullOptionalValue.getMethod(), ResourceMethod.ACTION);
    Assert.assertEquals(requestNullOptionalValue.getHeaders(), Collections.<String, String>emptyMap());
    Assert.assertEquals(requestNullOptionalValue.isSafe(), false);
    Assert.assertEquals(requestNullOptionalValue.isIdempotent(), false);
    Assert.assertEquals(requestNullOptionalValue.getResponseDecoder().getEntityClass(), Void.class);
}
Also used : HashMap(java.util.HashMap) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 5 with DynamicRecordMetadata

use of com.linkedin.data.template.DynamicRecordMetadata in project rest.li by linkedin.

the class TestClientBuilders method testBuilderPathKeys1.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subSubResourceAction1")
public void testBuilderPathKeys1(URIDetails expectedURIDetails) {
    List<FieldDef<?>> fieldDefs = new ArrayList<>();
    fieldDefs.add(new FieldDef<>("key1", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
    fieldDefs.add(new FieldDef<>("key2", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
    DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", fieldDefs);
    Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<>();
    requestMetadataMap.put("action", requestMetadata);
    DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
    Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<>();
    responseMetadataMap.put("action", responseMetadata);
    ResourceSpec resourceSpec = getResourceSpecForBuilderPathKeys();
    Map<String, Integer> expectedPathKeys = new HashMap<>();
    expectedPathKeys.put("key1", 1);
    expectedPathKeys.put("key2", 2);
    Request<TestRecord> request = new ActionRequestBuilder<Void, TestRecord>(SUBRESOURCE_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS).name("action").pathKey("key1", 1).pathKey("key2", 2).build();
    URIDetails.testUriGeneration(request, expectedURIDetails);
    testPathKeys(request, SUBRESOURCE_URI, expectedPathKeys);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResourceSpec(com.linkedin.restli.common.ResourceSpec) ByteString(com.linkedin.data.ByteString) FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Aggregations

DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)21 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)14 TestRecord (com.linkedin.restli.client.test.TestRecord)13 Test (org.testng.annotations.Test)13 ResourceMethod (com.linkedin.restli.common.ResourceMethod)10 FieldDef (com.linkedin.data.template.FieldDef)6 HashMap (java.util.HashMap)6 ByteString (com.linkedin.data.ByteString)5 ResourceSpec (com.linkedin.restli.common.ResourceSpec)4 CompoundKey (com.linkedin.restli.common.CompoundKey)3 ActionSchema (com.linkedin.restli.restspec.ActionSchema)3 ArrayList (java.util.ArrayList)3 DataSchema (com.linkedin.data.schema.DataSchema)2 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)2 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)2 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)2 DataMap (com.linkedin.data.DataMap)1 ActionRequestBuilder (com.linkedin.restli.client.ActionRequestBuilder)1 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)1