use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class ComplexKeysDataProvider method create.
public ComplexResourceKey<TwoPartKey, TwoPartKey> create(Message message) {
TwoPartKey key = new TwoPartKey();
key.setMajor(message.getMessage());
key.setMinor(message.getMessage());
_db.put(keyToString(key), message);
return new ComplexResourceKey<TwoPartKey, TwoPartKey>(key, new TwoPartKey());
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchGetEntityEmpty.
@SuppressWarnings("deprecation")
public void testBatchGetEntityEmpty(BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> builder) throws Exception {
final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> request = builder.build();
final FutureCallback<RestResponse> callback = new FutureCallback<RestResponse>();
getClient().sendRestRequest(request, new RequestContext(), callback);
final RestResponse result = callback.get();
final DataMap responseMap = DataMapUtils.readMap(result);
final DataMap resultsMap = responseMap.getDataMap(BatchKVResponse.RESULTS);
Assert.assertNotNull(resultsMap, "Response does not contain results map");
Assert.assertTrue(resultsMap.isEmpty());
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchCreateMain.
private void testBatchCreateMain(BatchCreateRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchCreateRequestBuilder, BatchGetRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
final String messageText1 = "firstMessage";
Message message1 = new Message();
message1.setMessage(messageText1);
final String messageText2 = "secondMessage";
Message message2 = new Message();
message2.setMessage(messageText2);
List<Message> messages = new ArrayList<Message>(2);
messages.add(message1);
messages.add(message2);
ComplexResourceKey<TwoPartKey, TwoPartKey> expectedComplexKey1 = getComplexKey(messageText1, messageText1);
ComplexResourceKey<TwoPartKey, TwoPartKey> expectedComplexKey2 = getComplexKey(messageText2, messageText2);
// test build
Request<CollectionResponse<CreateStatus>> request = batchCreateRequestBuilder.inputs(messages).build();
ResponseFuture<CollectionResponse<CreateStatus>> future = getClient().sendRequest(request);
Response<CollectionResponse<CreateStatus>> response = future.getResponse();
Assert.assertEquals(response.getStatus(), 200);
Set<ComplexResourceKey<TwoPartKey, TwoPartKey>> expectedComplexKeys = new HashSet<ComplexResourceKey<TwoPartKey, TwoPartKey>>(2);
expectedComplexKeys.add(expectedComplexKey1);
expectedComplexKeys.add(expectedComplexKey2);
for (CreateStatus createStatus : response.getEntity().getElements()) {
@SuppressWarnings("unchecked") CreateIdStatus<ComplexResourceKey<TwoPartKey, TwoPartKey>> createIdStatus = (CreateIdStatus<ComplexResourceKey<TwoPartKey, TwoPartKey>>) createStatus;
Assert.assertEquals(createIdStatus.getStatus(), new Integer(201));
Assert.assertTrue(expectedComplexKeys.contains(createIdStatus.getKey()));
try {
@SuppressWarnings("deprecation") String id = createIdStatus.getId();
Assert.fail("buildReadOnlyId should throw an exception on ComplexKeys");
} catch (UnsupportedOperationException e) {
// expected
}
expectedComplexKeys.remove(createIdStatus.getKey());
}
Assert.assertTrue(expectedComplexKeys.isEmpty());
// attempt to batch get created records
List<ComplexResourceKey<TwoPartKey, TwoPartKey>> createdKeys = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>(2);
createdKeys.add(expectedComplexKey1);
createdKeys.add(expectedComplexKey2);
BatchGetKVRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> getRequest = batchGetRequestBuilder.ids(createdKeys).buildKV();
ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>> getFuture = getClient().sendRequest(getRequest);
Response<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>> getResponse = getFuture.getResponse();
Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> getResults = getResponse.getEntity().getResults();
Assert.assertEquals(getResults.get(expectedComplexKey1), message1);
Assert.assertEquals(getResults.get(expectedComplexKey2), message2);
Assert.assertEquals(getResults.size(), 2);
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchDeleteMain.
private void testBatchDeleteMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, EmptyRecord> createRequestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
String messageText = "m1";
Message message = new Message();
message.setMessage(messageText);
Request<EmptyRecord> createRequest = createRequestBuilder.input(message).build();
ResponseFuture<EmptyRecord> createFuture = getClient().sendRequest(createRequest);
Response<EmptyRecord> createResponse = createFuture.getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
String messageText2 = "m2";
message.setMessage(messageText2);
createRequest = createRequestBuilder.input(message).build();
createFuture = getClient().sendRequest(createRequest);
createResponse = createFuture.getResponse();
Assert.assertEquals(createResponse.getStatus(), 201);
ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(messageText, messageText);
ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(messageText2, messageText2);
ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
ids.add(key1);
ids.add(key2);
final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.ids(ids).build();
final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
Assert.assertEquals(resp.getValue().getStatus().intValue(), 204);
}
Assert.assertNotNull(response.getResults().get(key1));
Assert.assertNotNull(response.getResults().get(key2));
Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetRequest = batchGetRequestBuilder.ids(ids).build();
ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetFuture = getClient().sendRequest(batchGetRequest);
BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> batchGetResponse = batchGetFuture.getResponse().getEntity();
Assert.assertEquals(batchGetResponse.getResults().size(), batchGetResponse.getErrors().size());
}
use of com.linkedin.restli.examples.greetings.api.TwoPartKey in project rest.li by linkedin.
the class TestComplexKeysResource method testBatchPartialUpdateMain.
private void testBatchPartialUpdateMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
Message message = new Message();
message.setTone(Tone.FRIENDLY);
PatchRequest<Message> patch = PatchGenerator.diffEmpty(message);
final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>> inputs = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, PatchRequest<Message>>();
ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
inputs.put(key1, patch);
inputs.put(key2, patch);
final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.patchInputs(inputs).build();
final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
Assert.assertTrue(inputs.containsKey(resp.getKey()));
Assert.assertEquals(resp.getValue().getStatus().intValue(), 204);
}
Assert.assertNotNull(response.getResults().get(key1));
Assert.assertNotNull(response.getResults().get(key2));
Assert.assertTrue(response.getErrors().isEmpty());
ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
ids.add(key1);
ids.add(key2);
Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetRequest = batchGetRequestBuilder.ids(ids).build();
ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>>> batchGetFuture = getClient().sendRequest(batchGetRequest);
BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> batchGetResponse = batchGetFuture.getResponse().getEntity();
Assert.assertEquals(batchGetResponse.getResults().get(key1).getEntity().getTone(), Tone.FRIENDLY);
Assert.assertEquals(batchGetResponse.getResults().get(key2).getEntity().getTone(), Tone.FRIENDLY);
}
Aggregations