use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyBatchGetRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchComplexKeyAndParam")
public void testComplexKeyBatchGetRequestBuilder(URIDetails expectedURIDetails) throws Exception {
BatchGetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new BatchGetRequestBuilder<>(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");
@SuppressWarnings("unchecked") BatchGetKVRequest<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> request = builder.ids(id1, id2).setParam("testParam", param).buildKV();
Assert.assertTrue(request.isIdempotent());
Assert.assertTrue(request.isSafe());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.BATCH_GET, null, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestClientBuilders method buildComplexKey.
/**
* Helper method to build complex key instance
*/
private ComplexResourceKey<TestRecord, TestRecord> buildComplexKey(long keyId, String keyMessage, long paramId, String paramMessage) {
ComplexResourceKey<TestRecord, TestRecord> id = new ComplexResourceKey<>(new TestRecord(), new TestRecord());
id.getKey().setId(keyId);
id.getKey().setMessage(keyMessage);
id.getParams().setId(paramId);
id.getParams().setMessage(paramMessage);
return id;
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyUpdateRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKey")
public void testComplexKeyUpdateRequestBuilder(URIDetails expectedURIDetails) {
UpdateRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new UpdateRequestBuilder<>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
ComplexResourceKey<TestRecord, TestRecord> key = buildComplexKey(1L, "keyMessage", 2L, "paramMessage");
UpdateRequest<TestRecord> request = builder.id(key).input(new TestRecord()).build();
testBaseUriGeneration(request, expectedURIDetails.getProtocolVersion());
Assert.assertEquals(request.isSafe(), false);
Assert.assertEquals(request.isIdempotent(), true);
checkBasicRequest(request, expectedURIDetails, ResourceMethod.UPDATE, new TestRecord(), Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.common.ComplexResourceKey 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);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method batchUpdate.
public BatchUpdateResult<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchUpdate(BatchUpdateRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entities) {
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateResponse> results = new HashMap<>();
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, RestLiServiceException> errors = new HashMap<>();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> entry : entities.getData().entrySet()) {
if (_db.containsKey(keyToString(entry.getKey().getKey()))) {
_db.put(keyToString(entry.getKey().getKey()), entry.getValue());
results.put(entry.getKey(), new UpdateResponse(HttpStatus.S_200_OK));
} else {
errors.put(entry.getKey(), new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
}
}
return new BatchUpdateResult<>(results, errors);
}
Aggregations