Search in sources :

Example 1 with KeyValueRecordFactory

use of com.linkedin.restli.common.KeyValueRecordFactory 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 2 with KeyValueRecordFactory

use of com.linkedin.restli.common.KeyValueRecordFactory 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)

Example 3 with KeyValueRecordFactory

use of com.linkedin.restli.common.KeyValueRecordFactory in project rest.li by linkedin.

the class TestClientBuilders method testComplexKeyBatchUpdateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKeyAndParam")
public void testComplexKeyBatchUpdateRequestBuilder(URIDetails expectedURIDetails) throws Exception {
    BatchUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    ComplexResourceKey<TestRecord, TestRecord> id1 = buildComplexKey(1L, "KeyMessage1", 10L, "ParamMessage1");
    ComplexResourceKey<TestRecord, TestRecord> id2 = buildComplexKey(2L, "KeyMessage2", 20L, "ParamMessage2");
    RecordTemplate param = buildComplexParam(123, "ParamMessage");
    TestRecord t1 = new TestRecord().setMessage("foo");
    TestRecord t2 = new TestRecord().setMessage("bar");
    BatchUpdateRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.input(id1, t1).input(id2, t2).setParam("testParam", param).build();
    // using toStringFull (which is deprecated) because this is only used to check v1
    BatchRequest<TestRecord> expectedRequest = new BatchRequest<TestRecord>(new DataMap(), TestRecord.class);
    expectedRequest.getEntities().put(toEntityKey(id1, expectedURIDetails.getProtocolVersion()), t1);
    expectedRequest.getEntities().put(toEntityKey(id2, expectedURIDetails.getProtocolVersion()), t2);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    Assert.assertTrue(request.isIdempotent());
    Assert.assertFalse(request.isSafe());
    @SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<ComplexResourceKey, TestRecord> factory = new KeyValueRecordFactory<ComplexResourceKey, TestRecord>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, TestRecord.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new ComplexResourceKey[] { id1, id2 }, new TestRecord[] { t1, t2 });
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), null);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) RecordTemplate(com.linkedin.data.template.RecordTemplate) DynamicRecordTemplate(com.linkedin.data.template.DynamicRecordTemplate) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 4 with KeyValueRecordFactory

use of com.linkedin.restli.common.KeyValueRecordFactory in project rest.li by linkedin.

the class TestClientBuilders method testBatchUpdateCompoundKeyRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchCompoundKey")
public void testBatchUpdateCompoundKeyRequestBuilder(URIDetails expectedURIDetails) {
    BatchUpdateRequestBuilder<CompoundKey, TestRecord> builder = new BatchUpdateRequestBuilder<CompoundKey, TestRecord>(TEST_URI, TestRecord.class, _ASSOC_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    Map<CompoundKey, TestRecord> inputs = new HashMap<CompoundKey, TestRecord>();
    CompoundKey key1 = new CompoundKey().append("part1", 1L).append("part2", "2");
    CompoundKey key2 = new CompoundKey().append("part1", 11L).append("part2", "22");
    TestRecord t1 = new TestRecord().setId(1L).setMessage("1");
    TestRecord t2 = new TestRecord().setId(2L);
    inputs.put(key1, t1);
    inputs.put(key2, t2);
    BatchRequest<TestRecord> expectedRequest = new BatchRequest<TestRecord>(new DataMap(), TestRecord.class);
    expectedRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), t1);
    expectedRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), t2);
    BatchUpdateRequest<CompoundKey, TestRecord> request = builder.inputs(inputs).build();
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), true);
    KeyValueRecordFactory<CompoundKey, TestRecord> factory = new KeyValueRecordFactory<CompoundKey, TestRecord>(CompoundKey.class, null, null, getCompoundKeyFieldTypes(), TestRecord.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new CompoundKey[] { key1, key2 }, new TestRecord[] { t1, t2 });
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_UPDATE, collectionRequest, expectedRequest, Collections.<String, String>emptyMap(), null);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) CompoundKey(com.linkedin.restli.common.CompoundKey) 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 5 with KeyValueRecordFactory

use of com.linkedin.restli.common.KeyValueRecordFactory in project rest.li by linkedin.

the class TestClientBuilders method testComplexKeyBatchPartialUpdateRequestBuilder.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKey")
public void testComplexKeyBatchPartialUpdateRequestBuilder(URIDetails expectedURIDetails) {
    BatchPartialUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchPartialUpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    Map<ComplexResourceKey<TestRecord, TestRecord>, PatchRequest<TestRecord>> inputs = new HashMap<ComplexResourceKey<TestRecord, TestRecord>, PatchRequest<TestRecord>>();
    ComplexResourceKey<TestRecord, TestRecord> key1 = buildComplexKey(1L, "keyMessage1", 2L, "paramMessage1");
    ComplexResourceKey<TestRecord, TestRecord> key2 = buildComplexKey(3L, "keyMessage2", 4L, "paramMessage2");
    TestRecord t1 = new TestRecord().setId(1L);
    TestRecord t2 = new TestRecord().setId(2L).setMessage("foo");
    TestRecord t3 = new TestRecord().setMessage("bar");
    PatchRequest<TestRecord> patch1 = PatchGenerator.diff(t1, t2);
    PatchRequest<TestRecord> patch2 = PatchGenerator.diff(t2, t3);
    inputs.put(key1, patch1);
    inputs.put(key2, patch2);
    BatchPartialUpdateRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.inputs(inputs).build();
    Assert.assertEquals(request.isSafe(), false);
    Assert.assertEquals(request.isIdempotent(), false);
    testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
    // using .toStringFull (which is deprecated) because this is only used for checking v1
    @SuppressWarnings({ "unchecked", "rawtypes" }) BatchRequest<PatchRequest<TestRecord>> batchRequest = new BatchRequest(new DataMap(), PatchRequest.class);
    batchRequest.getEntities().put(toEntityKey(key1, expectedURIDetails.getProtocolVersion()), patch1);
    batchRequest.getEntities().put(toEntityKey(key2, expectedURIDetails.getProtocolVersion()), patch2);
    @SuppressWarnings({ "unchecked", "rawtypes" }) KeyValueRecordFactory<ComplexResourceKey, PatchRequest> factory = new KeyValueRecordFactory<ComplexResourceKey, PatchRequest>(ComplexResourceKey.class, TestRecord.class, TestRecord.class, null, PatchRequest.class);
    @SuppressWarnings({ "unchecked", "rawtypes" }) CollectionRequest<KeyValueRecord> collectionRequest = buildCollectionRequest(factory, new ComplexResourceKey[] { key1, key2 }, new PatchRequest[] { patch1, patch2 });
    checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_PARTIAL_UPDATE, collectionRequest, batchRequest, Collections.<String, String>emptyMap(), null);
}
Also used : BatchRequest(com.linkedin.restli.common.BatchRequest) HashMap(java.util.HashMap) KeyValueRecordFactory(com.linkedin.restli.common.KeyValueRecordFactory) PatchRequest(com.linkedin.restli.common.PatchRequest) DataMap(com.linkedin.data.DataMap) KeyValueRecord(com.linkedin.restli.common.KeyValueRecord) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Aggregations

TestRecord (com.linkedin.restli.client.test.TestRecord)10 KeyValueRecord (com.linkedin.restli.common.KeyValueRecord)10 KeyValueRecordFactory (com.linkedin.restli.common.KeyValueRecordFactory)10 Test (org.testng.annotations.Test)10 HashMap (java.util.HashMap)7 DataMap (com.linkedin.data.DataMap)6 BatchRequest (com.linkedin.restli.common.BatchRequest)6 CollectionRequest (com.linkedin.restli.common.CollectionRequest)4 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)3 CompoundKey (com.linkedin.restli.common.CompoundKey)3 PatchRequest (com.linkedin.restli.common.PatchRequest)3 DynamicRecordTemplate (com.linkedin.data.template.DynamicRecordTemplate)1 RecordTemplate (com.linkedin.data.template.RecordTemplate)1