use of com.linkedin.data.template.FieldDef in project rest.li by linkedin.
the class TestClientBuilders method getResourceSpecForBuilderPathKeys.
private ResourceSpec getResourceSpecForBuilderPathKeys() {
List<FieldDef<?>> fieldDefs = new ArrayList<FieldDef<?>>();
fieldDefs.add(new FieldDef<Integer>("key1", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
fieldDefs.add(new FieldDef<Integer>("key2", Integer.class, DataTemplateUtil.getSchema(Integer.class)));
DynamicRecordMetadata requestMetadata = new DynamicRecordMetadata("action", fieldDefs);
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
requestMetadataMap.put("action", requestMetadata);
DynamicRecordMetadata responseMetadata = new DynamicRecordMetadata("action", Collections.<FieldDef<?>>emptyList());
Map<String, DynamicRecordMetadata> responseMetadataMap = new HashMap<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
return new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap);
}
use of com.linkedin.data.template.FieldDef in project rest.li by linkedin.
the class TestClientBuilders method testActionRequestInputIsReadOnly.
@Test
@SuppressWarnings("unchecked")
public void testActionRequestInputIsReadOnly() {
FieldDef<TestRecord> pParam = new FieldDef<TestRecord>("p", TestRecord.class, DataTemplateUtil.getSchema(TestRecord.class));
Map<String, DynamicRecordMetadata> requestMetadataMap = new HashMap<String, DynamicRecordMetadata>();
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<String, DynamicRecordMetadata>();
responseMetadataMap.put("action", responseMetadata);
ResourceSpec resourceSpec = new ResourceSpecImpl(Collections.<ResourceMethod>emptySet(), requestMetadataMap, responseMetadataMap, ComplexResourceKey.class, TestRecord.class, TestRecord.class, TestRecord.class, Collections.<String, CompoundKey.TypeInfo>emptyMap());
ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new ActionRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, resourceSpec, RestliRequestOptions.DEFAULT_OPTIONS);
TestRecord testRecord1 = new TestRecord();
TestRecord testRecord2 = new TestRecord();
ComplexResourceKey<TestRecord, TestRecord> key = new ComplexResourceKey<TestRecord, TestRecord>(testRecord1, testRecord2);
ActionRequest<TestRecord> request = builder.name("action").setParam(pParam, testRecord1).id(key).build();
DynamicRecordTemplate inputParams = (DynamicRecordTemplate) request.getInputRecord();
Assert.assertNotSame(inputParams.getValue(pParam).data(), testRecord1.data());
Assert.assertTrue(inputParams.data().isReadOnly());
Assert.assertTrue(inputParams.getValue(pParam).data().isMadeReadOnly());
Assert.assertNotSame(request.getId(), key);
Assert.assertTrue(((ComplexResourceKey<TestRecord, TestRecord>) request.getId()).isReadOnly());
testRecord1.data().makeReadOnly();
testRecord2.data().makeReadOnly();
request = builder.build();
inputParams = (DynamicRecordTemplate) request.getInputRecord();
Assert.assertSame(inputParams.getValue(pParam).data(), testRecord1.data());
Assert.assertTrue(inputParams.data().isReadOnly());
Assert.assertSame(request.getId(), key);
}
use of com.linkedin.data.template.FieldDef in project rest.li by linkedin.
the class ActionResponseBuilder method buildRestLiResponseData.
@Override
public RestLiResponseData buildRestLiResponseData(RestRequest request, RoutingResult routingResult, Object result, Map<String, String> headers, List<HttpCookie> cookies) {
final Object value;
final HttpStatus status;
if (result instanceof ActionResult) {
final ActionResult<?> actionResult = (ActionResult<?>) result;
value = actionResult.getValue();
status = actionResult.getStatus();
if (status == null) {
throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Unexpected null encountered. Null HttpStatus inside of an ActionResult returned by the resource method: " + routingResult.getResourceMethod());
}
} else {
value = result;
status = HttpStatus.S_200_OK;
}
RecordDataSchema actionReturnRecordDataSchema = routingResult.getResourceMethod().getActionReturnRecordDataSchema();
@SuppressWarnings("unchecked") FieldDef<Object> actionReturnFieldDef = (FieldDef<Object>) routingResult.getResourceMethod().getActionReturnFieldDef();
final ActionResponse<?> actionResponse = new ActionResponse<Object>(value, actionReturnFieldDef, actionReturnRecordDataSchema);
RestLiResponseDataImpl responseData = new RestLiResponseDataImpl(status, headers, cookies);
responseData.setResponseEnvelope(new ActionResponseEnvelope(actionResponse, responseData));
return responseData;
}
use of com.linkedin.data.template.FieldDef in project rest.li by linkedin.
the class TestGroupsRequestBuilders method testAction.
// Actions tests are covered in TestGroupsClient.java
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestGroupsBuilderDataProviderEntityAction")
public void testAction(RootBuilderWrapper<Integer, Group> builders, URIDetails expectedURIDetails) {
String testEmail = "test@test.com";
TransferOwnershipRequest ownershipRequest = new TransferOwnershipRequest();
ownershipRequest.setNewOwnerContactEmail(testEmail);
int testId = 9999;
ownershipRequest.setNewOwnerMemberID(testId);
Request<Void> request = builders.<Void>action("TransferOwnership").id(1).setActionParam("Request", ownershipRequest).build();
Map<FieldDef<?>, Object> parameters = new HashMap<FieldDef<?>, Object>(1);
parameters.put(new FieldDef<TransferOwnershipRequest>("request", TransferOwnershipRequest.class, DataTemplateUtil.getSchema(TransferOwnershipRequest.class)), ownershipRequest);
DynamicRecordTemplate requestInput = createDynamicRecordTemplate("transferOwnership", parameters);
checkRequestBuilder(request, ResourceMethod.ACTION, ActionResponseDecoder.class, expectedURIDetails, requestInput);
}
use of com.linkedin.data.template.FieldDef in project rest.li by linkedin.
the class TestGroupsRequestBuilders method testActionOnSubresource.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestContactsBuilderDataProviderAction")
public void testActionOnSubresource(RootBuilderWrapper<Integer, GroupContact> builders, URIDetails expectedURIDetails) {
Request<Void> request = builders.<Void>action("SpamContacts").setPathKey("groupId", 42).build();
Map<FieldDef<?>, Object> parameters = new HashMap<FieldDef<?>, Object>(1);
DynamicRecordTemplate requestInput = createDynamicRecordTemplate("spamContacts", parameters);
checkRequestBuilder(request, ResourceMethod.ACTION, ActionResponseDecoder.class, expectedURIDetails, requestInput);
}
Aggregations