Search in sources :

Example 46 with DataMap

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

the class TestPatchGeneration method testDiffFromNullNested.

@Test
public void testDiffFromNullNested() throws Exception {
    Group g1 = new Group();
    Group g2 = new Group(g1.data().copy());
    Location loc = new Location();
    loc.setLatitude(42.0f);
    loc.setLongitude(17.0f);
    g2.setLocation(loc);
    PatchTree update = PatchCreator.diff(g1, g2);
    //"{$set={location={longitude=17.0, latitude=42.0}}}"
    final DataMap setMap = new DataMap();
    final DataMap latLongMap = new DataMap();
    latLongMap.put("longitude", 17.0f);
    latLongMap.put("latitude", 42.0f);
    final DataMap locationMap = new DataMap();
    locationMap.put("location", latLongMap);
    setMap.put(PatchConstants.SET_COMMAND, locationMap);
    assertEquals(update.getDataMap(), setMap, "PatchTree DataMap should be correct");
}
Also used : Group(com.linkedin.restli.examples.groups.api.Group) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) Location(com.linkedin.restli.examples.groups.api.Location) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 47 with DataMap

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

the class TestGroupsRequestBuilders method requestMembershipsBatchDataProviderBatch.

@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestMembershipsBatchDataProvider")
private static Object[][] requestMembershipsBatchDataProviderBatch() {
    //Sample URIs:
    //"groupMemberships?ids=groupID%3D1%26memberID%3D1&ids=groupID%3D2%26memberID%3D1&ids=groupID%3D2%26memberID%3D2"
    //"groupMemberships?ids=List((groupID:2,memberID:1),(groupID:2,memberID:2),(groupID:1,memberID:1))"
    //Note that we need two different ID sets, one for V1 and one for V2 since batch operations on compound keys
    //are unique.
    final Set<String> idSetV1 = new HashSet<String>();
    idSetV1.add("groupID=2&memberID=1");
    idSetV1.add("groupID=2&memberID=2");
    idSetV1.add("groupID=1&memberID=1");
    final Set<DataMap> idSetV2 = new HashSet<DataMap>();
    final DataMap id1 = new DataMap();
    id1.put("groupID", "2");
    id1.put("memberID", "1");
    final DataMap id2 = new DataMap();
    id2.put("groupID", "2");
    id2.put("memberID", "2");
    final DataMap id3 = new DataMap();
    id3.put("groupID", "1");
    id3.put("memberID", "1");
    idSetV2.add(id1);
    idSetV2.add(id2);
    idSetV2.add(id3);
    final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "groupMemberships", idSetV1, null, null);
    final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "groupMemberships", idSetV2, null, null);
    return new Object[][] { { uriDetails1 }, { uriDetails2 } };
}
Also used : URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashSet(java.util.HashSet) DataMap(com.linkedin.data.DataMap) DataProvider(org.testng.annotations.DataProvider)

Example 48 with DataMap

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

the class TestPatchGeneration method testNestedPositiveMask.

@Test
public void testNestedPositiveMask() throws Exception {
    List<PathSpec> fields = Arrays.asList(Group.fields().id(), Group.fields().location().latitude(), Group.fields().location().longitude(), Group.fields().name());
    MaskTree mask = MaskCreator.createPositiveMask(fields);
    //"{id=1, location={longitude=1, latitude=1}, name=1}"
    final DataMap idLocationNameMap = new DataMap();
    idLocationNameMap.put("id", 1);
    idLocationNameMap.put("name", 1);
    final DataMap longLatMap = new DataMap();
    longLatMap.put("longitude", 1);
    longLatMap.put("latitude", 1);
    idLocationNameMap.put("location", longLatMap);
    Assert.assertEquals(mask.getDataMap(), idLocationNameMap, "The MaskTree DataMap should match");
    //The ordering might be different but the URI should look something like:
    //"id,location:(longitude,latitude),name";
    final String actualEncodedMaskURI = URIMaskUtil.encodeMaskForURI(mask);
    //We convert back into a MaskTree so we can compare DataMaps because the URI could be in any order
    final MaskTree generatedMaskTree = URIMaskUtil.decodeMaskUriFormat(new StringBuilder(actualEncodedMaskURI));
    Assert.assertEquals(generatedMaskTree.getDataMap(), idLocationNameMap, "The actual encoded Mask URI should be correct");
}
Also used : MaskTree(com.linkedin.data.transform.filter.request.MaskTree) PathSpec(com.linkedin.data.schema.PathSpec) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 49 with DataMap

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

the class ExceptionsResource method create.

/**
   * Responds with an error for requests to create insulting greetings, responds
   * with 201 created for all other requests.
   */
@RestMethod.Create
public CreateResponse create(Greeting g) {
    if (g.hasTone() && g.getTone() == Tone.INSULTING) {
        RestLiServiceException notAcceptableException = new RestLiServiceException(HttpStatus.S_406_NOT_ACCEPTABLE, "I will not tolerate your insolence!");
        DataMap details = new DataMap();
        details.put("reason", "insultingGreeting");
        notAcceptableException.setErrorDetails(details);
        notAcceptableException.setServiceErrorCode(999);
        throw notAcceptableException;
    } else {
        return new CreateResponse(g.getId(), HttpStatus.S_201_CREATED);
    }
}
Also used : RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) CreateResponse(com.linkedin.restli.server.CreateResponse) DataMap(com.linkedin.data.DataMap)

Example 50 with DataMap

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

the class TestComplexKeysResource method testBatchGetEntityEmpty.

@SuppressWarnings("deprecation")
public void testBatchGetEntityEmpty(BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> builder) throws Exception {
    final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> request = builder.build();
    final FutureCallback<RestResponse> callback = new FutureCallback<RestResponse>();
    getClient().sendRestRequest(request, new RequestContext(), callback);
    final RestResponse result = callback.get();
    final DataMap responseMap = DataMapUtils.readMap(result);
    final DataMap resultsMap = responseMap.getDataMap(BatchKVResponse.RESULTS);
    Assert.assertNotNull(resultsMap, "Response does not contain results map");
    Assert.assertTrue(resultsMap.isEmpty());
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message) RestResponse(com.linkedin.r2.message.rest.RestResponse) RequestContext(com.linkedin.r2.message.RequestContext) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) FutureCallback(com.linkedin.common.callback.FutureCallback) DataMap(com.linkedin.data.DataMap)

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