Search in sources :

Example 91 with DataMap

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());
}
Also used : PatchTreeTestModel(com.linkedin.restli.client.util.test.PatchTreeTestModel) RemoveFieldOp(com.linkedin.data.transform.patch.request.RemoveFieldOp) PatchTree(com.linkedin.data.transform.patch.request.PatchTree) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 92 with DataMap

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);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) HashMap(java.util.HashMap) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 93 with DataMap

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 } };
}
Also used : DataComplex(com.linkedin.data.DataComplex) URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) HashSet(java.util.HashSet) DataProvider(org.testng.annotations.DataProvider)

Example 94 with DataMap

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 } };
}
Also used : DataComplex(com.linkedin.data.DataComplex) URIDetails(com.linkedin.restli.internal.testutils.URIDetails) HashMap(java.util.HashMap) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) DataProvider(org.testng.annotations.DataProvider)

Example 95 with DataMap

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);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

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