use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testAsyncBatchPatchComplexKeyResource.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "asyncBatchUpdateComplexKey")
public void testAsyncBatchPatchComplexKeyResource(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel discoveredResourceModel = buildResourceModel(AsyncDiscoveredItemsResource.class);
RestLiCallback<?> callback = getCallback();
ResourceMethodDescriptor methodDescriptor;
AsyncDiscoveredItemsResource discoveredResource;
methodDescriptor = discoveredResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
discoveredResource = getMockResource(AsyncDiscoveredItemsResource.class);
@SuppressWarnings("unchecked") BatchPatchRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> mockBatchPatchReq = (BatchPatchRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>) EasyMock.anyObject();
discoveredResource.batchUpdate(mockBatchPatchReq, EasyMock.<Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>>anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
@SuppressWarnings("unchecked") Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>> callback = (Callback<BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem>>) EasyMock.getCurrentArguments()[1];
callback.onSuccess(null);
return null;
}
});
EasyMock.replay(discoveredResource);
checkAsyncInvocation(discoveredResource, callback, methodDescriptor, "POST", version, uri, body, buildBatchPathKeys(getDiscoveredItemComplexKey(1, 1, 1), getDiscoveredItemComplexKey(2, 2, 2), getDiscoveredItemComplexKey(3, 3, 3)));
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestRestLiMethodInvocation method testBatchPatchComplexKey.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchUpdateComplexKey")
public void testBatchPatchComplexKey(ProtocolVersion version, String uri, String body) throws Exception {
ResourceModel discoveredItemsResourceModel = buildResourceModel(DiscoveredItemsResource.class);
ResourceMethodDescriptor methodDescriptor = discoveredItemsResourceModel.findMethod(ResourceMethod.BATCH_PARTIAL_UPDATE);
DiscoveredItemsResource discoveredItemsResource = getMockResource(DiscoveredItemsResource.class);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyA = getDiscoveredItemComplexKey(1L, 2, 3L);
ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams> keyB = getDiscoveredItemComplexKey(4L, 5, 6L);
BatchPatchRequest<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> batchPatchRequest = EasyMock.anyObject();
@SuppressWarnings("unchecked") BatchUpdateResult<ComplexResourceKey<DiscoveredItemKey, DiscoveredItemKeyParams>, DiscoveredItem> batchUpdateResult = discoveredItemsResource.batchUpdate(batchPatchRequest);
EasyMock.expect(batchUpdateResult).andReturn(null).once();
checkInvocation(discoveredItemsResource, methodDescriptor, "POST", version, uri, body, buildBatchPathKeys(keyA, keyB));
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class MockBatchKVResponseFactory method createWithComplexKey.
/**
* Create a {@link BatchKVResponse} where the key is a {@link ComplexResourceKey}
*
* @param valueClass the value class
* @param keyKeyClass the class of the key part of the {@link ComplexResourceKey}
* @param keyParamsClass the class of the params part of the {@link ComplexResourceKey}
* @param recordTemplates the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getResults()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param errorResponses the data that will be returned for a call to {@link com.linkedin.restli.client.response.BatchKVResponse#getErrors()}
* NOTE: the params part of the {@link ComplexResourceKey} is removed in this map. A new
* instance of the params class is created with no data in it.
* @param <V>
* @return
*/
@SuppressWarnings("rawtypes")
public static <KK extends RecordTemplate, KP extends RecordTemplate, V extends RecordTemplate> BatchKVResponse<ComplexResourceKey<KK, KP>, V> createWithComplexKey(Class<V> valueClass, Class<KK> keyKeyClass, Class<KP> keyParamsClass, Map<ComplexResourceKey<KK, KP>, V> recordTemplates, Map<ComplexResourceKey<KK, KP>, ErrorResponse> errorResponses) {
ProtocolVersion version = AllProtocolVersions.BASELINE_PROTOCOL_VERSION;
DataMap batchResponseDataMap = buildDataMap(recordTemplates, errorResponses, version);
@SuppressWarnings("unchecked") BatchKVResponse<ComplexResourceKey<KK, KP>, V> response = (BatchKVResponse<ComplexResourceKey<KK, KP>, V>) (Object) new BatchKVResponse<ComplexResourceKey, V>(batchResponseDataMap, ComplexResourceKey.class, valueClass, null, keyKeyClass, keyParamsClass, version);
return response;
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyGetRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKeyAndParam")
public void testComplexKeyGetRequestBuilder(URIDetails expectedURIDetails) throws Exception {
GetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new GetRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
ComplexResourceKey<TestRecord, TestRecord> id = buildComplexKey(1L, "KeyMessage", 10L, "ParamMessage");
RecordTemplate param1 = buildComplexParam(123, "ParamMessage");
GetRequest<TestRecord> request = builder.id(id).setParam("testParam", param1).build();
Assert.assertTrue(request.isSafe());
Assert.assertTrue(request.isIdempotent());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.GET, null, Collections.<String, String>emptyMap(), null);
}
use of com.linkedin.restli.common.ComplexResourceKey in project rest.li by linkedin.
the class TestClientBuilders method testComplexKeyDeleteRequestBuilder.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "complexKeyAndParam")
public void testComplexKeyDeleteRequestBuilder(URIDetails expectedURIDetails) throws Exception {
DeleteRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord> builder = new DeleteRequestBuilder<ComplexResourceKey<TestRecord, TestRecord>, TestRecord>(TEST_URI, TestRecord.class, _COMPLEX_KEY_SPEC, RestliRequestOptions.DEFAULT_OPTIONS);
ComplexResourceKey<TestRecord, TestRecord> id = buildComplexKey(1L, "KeyMessage", 10L, "ParamMessage");
RecordTemplate param = buildComplexParam(123, "ParamMessage");
DeleteRequest<TestRecord> request = builder.id(id).setParam("testParam", param).build();
Assert.assertFalse(request.isSafe());
Assert.assertTrue(request.isIdempotent());
checkBasicRequest(request, expectedURIDetails, ResourceMethod.DELETE, null, Collections.<String, String>emptyMap(), null);
}
Aggregations