Search in sources :

Example 81 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestRestLiResponseHandler method testFieldProjection_batch.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicDataWithBatchUri")
public void testFieldProjection_batch(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String uri, String errorResponseHeaderName) throws Exception {
    RestResponse response;
    Map<Integer, Status> statusBatch = buildStatusBatchResponse(10, "f1", "f2", "f3");
    RestRequest request = buildRequest(uri, acceptTypeData.acceptHeaders, protocolVersion);
    response = _responseHandler.buildResponse(request, buildRoutingResult(ResourceMethod.BATCH_GET, request, acceptTypeData.acceptHeaders), statusBatch);
    checkResponse(response, 200, 2, acceptTypeData.responseContentType, BatchResponse.class.getName(), Status.class.getName(), true, errorResponseHeaderName);
    DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());
    BatchResponse<Status> batchResponse = new BatchResponse<Status>(dataMap, Status.class);
    assertEquals(batchResponse.getResults().size(), 10);
    for (Status status : batchResponse.getResults().values()) {
        assertTrue(status.data().containsKey("f1"));
        assertTrue(status.data().containsKey("f2"));
        assertFalse(status.data().containsKey("f3"));
    }
    // ensure that output map was not modified by rest.li!
    Status status1 = statusBatch.get(1);
    assertNotNull(status1);
    assertTrue(status1.data().containsKey("f3"));
}
Also used : UpdateStatus(com.linkedin.restli.common.UpdateStatus) CreateStatus(com.linkedin.restli.common.CreateStatus) Status(com.linkedin.restli.server.twitter.TwitterTestDataModels.Status) HttpStatus(com.linkedin.restli.common.HttpStatus) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestResponse(com.linkedin.r2.message.rest.RestResponse) PartialRestResponse(com.linkedin.restli.internal.server.response.PartialRestResponse) BatchResponse(com.linkedin.restli.common.BatchResponse) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 82 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestRestLiResponseHandler method testRestLiResponseData.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "statusActionDataPartial")
public void testRestLiResponseData(AcceptTypeData acceptTypeData, String response1, String response2, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    RestLiResponseData responseData;
    RoutingResult routingResult1 = buildRoutingResultAction(Status.class, request, acceptTypeData.acceptHeaders);
    // #1 simple record template
    responseData = _responseHandler.buildRestLiResponseData(request, routingResult1, buildStatusRecord());
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    assertEquals(responseData.getRecordResponseEnvelope().getRecord().toString(), response1);
    // #2 DataTemplate response
    StringMap map = new StringMap();
    map.put("key1", "value1");
    map.put("key2", "value2");
    RoutingResult routingResult2 = buildRoutingResultAction(StringMap.class, request, acceptTypeData.acceptHeaders);
    responseData = _responseHandler.buildRestLiResponseData(request, routingResult2, map);
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, true, errorResponseHeaderName);
    //Obtain the maps necessary for comparison
    final DataMap actualMap;
    final DataMap expectedMap;
    actualMap = responseData.getRecordResponseEnvelope().getRecord().data();
    expectedMap = JACKSON_DATA_CODEC.stringToMap(response2);
    assertEquals(actualMap, expectedMap);
    RoutingResult routingResult3 = buildRoutingResultAction(Void.TYPE, request, acceptTypeData.acceptHeaders);
    // #3 empty response
    responseData = _responseHandler.buildRestLiResponseData(request, routingResult3, null);
    checkResponseData(responseData, HttpStatus.S_200_OK, 1, false, false, errorResponseHeaderName);
    assertEquals(responseData.getRecordResponseEnvelope().getRecord(), null);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) StringMap(com.linkedin.data.template.StringMap) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 83 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testPromiseGetAssociativeResource.

@Test
public void testPromiseGetAssociativeResource() throws Exception {
    ResourceModel followsResourceModel = buildResourceModel(PromiseFollowsAssociativeResource.class);
    ResourceMethodDescriptor methodDescriptor;
    PromiseFollowsAssociativeResource resource;
    // #1: get
    methodDescriptor = followsResourceModel.findMethod(ResourceMethod.GET);
    resource = getMockResource(PromiseFollowsAssociativeResource.class);
    CompoundKey rawKey = new CompoundKey();
    rawKey.append("followerID", 1L);
    rawKey.append("followeeID", 2L);
    CompoundKey key = eq(rawKey);
    EasyMock.expect(resource.get(key)).andReturn(Promises.value(new Followed(new DataMap()))).once();
    checkInvocation(resource, methodDescriptor, "GET", version, "/promisefollows/(followerID:1,followeeID:2)", buildPathKeys("followerID", 1L, "followeeID", 2L, followsResourceModel.getKeyName(), rawKey));
}
Also used : PromiseFollowsAssociativeResource(com.linkedin.restli.server.twitter.PromiseFollowsAssociativeResource) CompoundKey(com.linkedin.restli.common.CompoundKey) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) Followed(com.linkedin.restli.server.twitter.TwitterTestDataModels.Followed) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 84 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class BatchCreateRequestBuilder method buildReadOnlyInput.

private CollectionRequest<V> buildReadOnlyInput() {
    try {
        DataMap map = new DataMap();
        CollectionRequest<V> input = new CollectionRequest<V>(map, _valueClass);
        for (V entity : _entities) {
            input.getElements().add(getReadOnlyOrCopyDataTemplate(entity));
        }
        map.setReadOnly();
        return input;
    } catch (CloneNotSupportedException cloneException) {
        throw new IllegalArgumentException("Entity cannot be copied.", cloneException);
    }
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) DataMap(com.linkedin.data.DataMap)

Example 85 with DataMap

use of com.linkedin.data.DataMap in project rest.li by linkedin.

the class BatchPartialUpdateRequestBuilder method buildReadOnlyInput.

private CollectionRequest<KeyValueRecord<K, PatchRequest<V>>> buildReadOnlyInput() {
    try {
        DataMap map = new DataMap();
        @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord<K, PatchRequest<V>>> input = new CollectionRequest(map, KeyValueRecord.class);
        for (Map.Entry<K, PatchRequest<V>> inputEntityEntry : _partialUpdateInputMap.entrySet()) {
            K key = getReadOnlyOrCopyKey(inputEntityEntry.getKey());
            PatchRequest<V> entity = getReadOnlyOrCopyDataTemplate(inputEntityEntry.getValue());
            KeyValueRecord<K, PatchRequest<V>> keyValueRecord = _keyValueRecordFactory.create(key, entity);
            keyValueRecord.data().setReadOnly();
            input.getElements().add(keyValueRecord);
        }
        map.setReadOnly();
        return input;
    } catch (CloneNotSupportedException cloneException) {
        throw new IllegalArgumentException("Entity cannot be copied.", cloneException);
    }
}
Also used : CollectionRequest(com.linkedin.restli.common.CollectionRequest) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap) Map(java.util.Map)

Aggregations

DataMap (com.linkedin.data.DataMap)471 Test (org.testng.annotations.Test)238 DataList (com.linkedin.data.DataList)130 ByteString (com.linkedin.data.ByteString)110 HashMap (java.util.HashMap)56 TestUtil.dataMapFromString (com.linkedin.data.TestUtil.dataMapFromString)49 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)47 TestUtil.dataSchemaFromString (com.linkedin.data.TestUtil.dataSchemaFromString)46 DataSchema (com.linkedin.data.schema.DataSchema)45 Map (java.util.Map)45 ArrayList (java.util.ArrayList)31 MaskTree (com.linkedin.data.transform.filter.request.MaskTree)23 PathSpec (com.linkedin.data.schema.PathSpec)21 RecordTemplate (com.linkedin.data.template.RecordTemplate)21 DataProvider (org.testng.annotations.DataProvider)20 HashSet (java.util.HashSet)19 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)18 PatchTree (com.linkedin.data.transform.patch.request.PatchTree)18 CompoundKey (com.linkedin.restli.common.CompoundKey)18 IOException (java.io.IOException)18