use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestPatchTreeRecorder method testFluentSetWithRemove.
@Test
public void testFluentSetWithRemove() {
PatchTreeRecorder<PatchTreeTestModel> pc = makeOne();
PatchTreeTestModel testModel = pc.getRecordingProxy();
PatchTreeTestModel.FooUnion fooUnion = new PatchTreeTestModel.FooUnion();
fooUnion.setInt(10);
testModel.setFooRequired(100).setFooUnion(fooUnion).setFooRecordTemplate(null, SetMode.REMOVE_IF_NULL).removeFooOptional();
PatchTree ptExpect = PatchCreator.diff(new DataMap(), new PatchTreeTestModel().setFooRequired(100).setFooUnion(fooUnion).data());
// Augment the patch request with the removes
ptExpect.addOperation(PatchTreeTestModel.fields().fooRecordTemplate(), new RemoveFieldOp());
ptExpect.addOperation(PatchTreeTestModel.fields().fooOptional(), new RemoveFieldOp());
Assert.assertEquals(pc.generatePatchTree().getDataMap(), ptExpect.getDataMap());
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestClientBuilders method testBatchUpdateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batch")
public void testBatchUpdateRequestBuilder(URIDetails expectedURIDetails) {
BatchUpdateRequestBuilder<Long, TestRecord> builder = new BatchUpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
Map<Long, TestRecord> updates = new HashMap<Long, TestRecord>();
updates.put(1L, new TestRecord());
updates.put(2L, new TestRecord());
updates.put(3L, new TestRecord());
BatchUpdateRequest<Long, TestRecord> request = builder.inputs(updates).appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.getObjectIds(), new HashSet<Long>(Arrays.asList(1L, 2L, 3L)));
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), true);
BatchRequest<TestRecord> expectedRequest = new BatchRequest<TestRecord>(new DataMap(), TestRecord.class);
expectedRequest.getEntities().put("1", new TestRecord());
expectedRequest.getEntities().put("2", new TestRecord());
expectedRequest.getEntities().put("3", new TestRecord());
@SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<Long, TestRecord> factory = new KeyValueRecordFactory<Long, TestRecord>(Long.class, null, null, null, TestRecord.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new Long[] { 1L, 2L, 3L }, new TestRecord[] { new TestRecord(), new TestRecord(), new TestRecord() });
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), _streamingDataSources);
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestClientBuilders method batchComplexKeyAndParam.
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKeyAndParam")
public Object[][] batchComplexKeyAndParam() {
//Sample valid URIs:
//"test?ids%5B0%5D.$params.id=20&ids%5B0%5D.$params.message=ParamMessage2&ids%5B0%5D.id=2&ids%5B0%5D.message=KeyMessage2&ids%5B1%5D.$params.id=10&ids%5B1%5D.$params.message=ParamMessage1&ids%5B1%5D.id=1&ids%5B1%5D.message=KeyMessage1&testParam.id=123&testParam.message=ParamMessage"
//"test?ids=List(($params:(id:20,message:ParamMessage2),id:2,message:KeyMessage2),($params:(id:10,message:ParamMessage1),id:1,message:KeyMessage1))&testParam=(id:123,message:ParamMessage)"
final DataMap idMessageMap = new DataMap();
idMessageMap.put("id", "123");
idMessageMap.put("message", "ParamMessage");
final Map<String, DataComplex> queryParamsMap = new HashMap<String, DataComplex>();
queryParamsMap.put("testParam", idMessageMap);
final Set<DataMap> idList = new HashSet<DataMap>();
final DataMap idMapOne = new DataMap();
idMapOne.put("id", "1");
idMapOne.put("message", "KeyMessage1");
final DataMap paramMapOne = new DataMap();
paramMapOne.put("id", "10");
paramMapOne.put("message", "ParamMessage1");
idMapOne.put("$params", paramMapOne);
final DataMap idMapTwo = new DataMap();
idMapTwo.put("id", "2");
idMapTwo.put("message", "KeyMessage2");
final DataMap paramMapTwo = new DataMap();
paramMapTwo.put("id", "20");
paramMapTwo.put("message", "ParamMessage2");
idMapTwo.put("$params", paramMapTwo);
idList.add(idMapOne);
idList.add(idMapTwo);
final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "test", idList, queryParamsMap, null);
final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "test", idList, queryParamsMap, null);
return new Object[][] { { uriDetails1 }, { uriDetails2 } };
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestClientBuilders method complexKeyAndParam.
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKeyAndParam")
public Object[][] complexKeyAndParam() {
//Sample URIs:
//"test/$params.id=10&$params.message=ParamMessage&id=1&message=KeyMessage?testParam.id=123&testParam.message=ParamMessage"
//"test/($params:(id:10,message:ParamMessage),id:1,message:KeyMessage)?testParam=(id:123,message:ParamMessage)"
final DataMap idMessageMap = new DataMap();
idMessageMap.put("id", "123");
idMessageMap.put("message", "ParamMessage");
final Map<String, DataComplex> queryParamsMap = new HashMap<String, DataComplex>();
queryParamsMap.put("testParam", idMessageMap);
final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "test/$params.id=10&$params.message=ParamMessage&id=1&message=KeyMessage", null, queryParamsMap, null);
final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "test/($params:(id:10,message:ParamMessage),id:1,message:KeyMessage)", null, queryParamsMap, null);
return new Object[][] { { uriDetails1 }, { uriDetails2 } };
}
use of com.linkedin.data.DataMap in project rest.li by linkedin.
the class TestClientBuilders method testBatchPartialUpdateRequestBuilder.
// need suppress on the method because the more specific suppress isn't being obeyed.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batch")
public void testBatchPartialUpdateRequestBuilder(URIDetails expectedURIDetails) {
BatchPartialUpdateRequestBuilder<Long, TestRecord> builder = new BatchPartialUpdateRequestBuilder<Long, TestRecord>(TEST_URI, TestRecord.class, _COLL_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
builder.input(1L, new PatchRequest<TestRecord>());
builder.input(2L, new PatchRequest<TestRecord>());
builder.input(3L, new PatchRequest<TestRecord>());
BatchPartialUpdateRequest<Long, TestRecord> request = builder.appendSingleAttachment(_dataSourceWriterA).appendMultipleAttachments(_dataSourceIterator).appendSingleAttachment(_dataSourceWriterB).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.getObjectIds(), new HashSet<Long>(Arrays.asList(1L, 2L, 3L)));
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), false);
@SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> expectedRequest = new BatchRequest(new DataMap(), PatchRequest.class);
expectedRequest.getEntities().put("1", new PatchRequest<TestRecord>());
expectedRequest.getEntities().put("2", new PatchRequest<TestRecord>());
expectedRequest.getEntities().put("3", new PatchRequest<TestRecord>());
KeyValueRecordFactory<Long, PatchRequest> factory = new KeyValueRecordFactory<Long, PatchRequest>(Long.class, null, null, null, PatchRequest.class);
CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new Long[] { 1L, 2L, 3L }, new PatchRequest[] { new PatchRequest(), new PatchRequest(), new PatchRequest() });
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), _streamingDataSources);
}
Aggregations