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