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);
}
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()));
}
}
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);
}
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);
}
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);
}
Aggregations