Search in sources :

Example 6 with BatchRequest

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

use of com.linkedin.restli.common.BatchRequest 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<>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
    Map<ComplexResourceKey<TestRecord, TestRecord>, PatchRequest<TestRecord>> inputs = new HashMap<>();
    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.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

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