Search in sources :

Example 11 with FieldDef

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);
}
Also used : FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ByteString(com.linkedin.data.ByteString) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl)

Example 12 with FieldDef

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);
}
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) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) Test(org.testng.annotations.Test)

Example 13 with FieldDef

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;
}
Also used : HttpStatus(com.linkedin.restli.common.HttpStatus) ActionResponse(com.linkedin.restli.common.ActionResponse) FieldDef(com.linkedin.data.template.FieldDef) ActionResult(com.linkedin.restli.server.ActionResult) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema)

Example 14 with FieldDef

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);
}
Also used : FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) HashMap(java.util.HashMap) TransferOwnershipRequest(com.linkedin.restli.examples.groups.api.TransferOwnershipRequest) Test(org.testng.annotations.Test)

Example 15 with FieldDef

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);
}
Also used : FieldDef(com.linkedin.data.template.FieldDef) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Aggregations

FieldDef (com.linkedin.data.template.FieldDef)18 HashMap (java.util.HashMap)7 Test (org.testng.annotations.Test)7 ByteString (com.linkedin.data.ByteString)6 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)6 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)6 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)5 DataMap (com.linkedin.data.DataMap)4 TestRecord (com.linkedin.restli.client.test.TestRecord)4 ResourceSpec (com.linkedin.restli.common.ResourceSpec)4 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)4 ArrayList (java.util.ArrayList)4 ActionResponse (com.linkedin.restli.common.ActionResponse)3 CompoundKey (com.linkedin.restli.common.CompoundKey)3 DataSchema (com.linkedin.data.schema.DataSchema)2 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)2 RequestContext (com.linkedin.r2.message.RequestContext)2 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)2 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)2 Callback (com.linkedin.common.callback.Callback)1