Search in sources :

Example 6 with Message

use of com.linkedin.restli.examples.greetings.api.Message 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());
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) EmptyRecord(com.linkedin.restli.common.EmptyRecord) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Map(java.util.Map) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap)

Example 7 with Message

use of com.linkedin.restli.examples.greetings.api.Message 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);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PatchRequest(com.linkedin.restli.common.PatchRequest) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) EntityResponse(com.linkedin.restli.common.EntityResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Map(java.util.Map) HashMap(java.util.HashMap) DataMap(com.linkedin.data.DataMap)

Example 8 with Message

use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.

the class TestEscapeCharsInStringKeys method testGetSubResourceKeys.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestStringKeysSubBuilderDataProvider")
public void testGetSubResourceKeys(RootBuilderWrapper<String, Message> builders) throws Exception {
    String parentKey = key1();
    String subKey = key2();
    Request<Message> request = builders.get().setPathKey("parentKey", parentKey).id(subKey).build();
    Message response = getClient().sendRequest(request).get().getEntity();
    Assert.assertNotNull(response);
    Assert.assertEquals(response.getId(), parentKey + " " + subKey, "Message should be key1 + ' ' + key2 for subResourceKey(key1,key2)");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) Test(org.testng.annotations.Test)

Example 9 with Message

use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.

the class TestEscapeCharsInStringKeys method testBatchGetWithSimpleKey.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestStringKeysOptionsDataProvider")
public void testBatchGetWithSimpleKey(RestliRequestOptions requestOptions) throws Exception {
    Set<String> keys = new HashSet<String>();
    keys.add(key1());
    keys.add(key2());
    Request<BatchResponse<Message>> req = new StringKeysBuilders(requestOptions).batchGet().ids(keys).build();
    BatchResponse<Message> response = getClient().sendRequest(req).get().getEntity();
    Map<String, Message> results = response.getResults();
    Assert.assertEquals(results.get(key1()).getMessage(), key1(), "Message should match key for key1");
    Assert.assertEquals(results.get(key2()).getMessage(), key2(), "Message should match key for key2");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) StringKeysBuilders(com.linkedin.restli.examples.greetings.client.StringKeysBuilders) BatchResponse(com.linkedin.restli.common.BatchResponse) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with Message

use of com.linkedin.restli.examples.greetings.api.Message in project rest.li by linkedin.

the class TestComplexKeysResource method testCreateMainOldBuilders.

private void testCreateMainOldBuilders(CreateRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> createRequestBuilder, GetRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> getRequestBuilder) throws RemoteInvocationException {
    final String messageText = "newMessage";
    Message message = new Message();
    message.setMessage(messageText);
    Request<EmptyRecord> request = createRequestBuilder.input(message).build();
    ResponseFuture<EmptyRecord> future = getClient().sendRequest(request);
    Response<EmptyRecord> response = future.getResponse();
    Assert.assertEquals(response.getStatus(), 201);
    ComplexResourceKey<TwoPartKey, TwoPartKey> expectedComplexKey = getComplexKey(messageText, messageText);
    try {
        @SuppressWarnings("deprecation") String stringId = response.getId();
        Assert.fail("getId() should throw an exception for complex resource keys!");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    @SuppressWarnings("unchecked") CreateResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>> createResponse = (CreateResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>) response.getEntity();
    Assert.assertEquals(createResponse.getId(), expectedComplexKey);
    // attempt to get the record you just created
    @SuppressWarnings("unchecked") Request<Message> getRequest = getRequestBuilder.id(expectedComplexKey).build();
    ResponseFuture<Message> getFuture = getClient().sendRequest(getRequest);
    Response<Message> getResponse = getFuture.getResponse();
    Assert.assertEquals(getResponse.getEntity().getMessage(), messageText);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) EmptyRecord(com.linkedin.restli.common.EmptyRecord) Message(com.linkedin.restli.examples.greetings.api.Message) CreateResponse(com.linkedin.restli.client.response.CreateResponse) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Aggregations

Message (com.linkedin.restli.examples.greetings.api.Message)38 Test (org.testng.annotations.Test)17 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)13 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)11 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 EntityResponse (com.linkedin.restli.common.EntityResponse)6 HashSet (java.util.HashSet)6 CompoundKey (com.linkedin.restli.common.CompoundKey)5 DataMap (com.linkedin.data.DataMap)4 EmptyRecord (com.linkedin.restli.common.EmptyRecord)4 Map (java.util.Map)4 CollectionResponse (com.linkedin.restli.common.CollectionResponse)3 UpdateStatus (com.linkedin.restli.common.UpdateStatus)3 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)3 UpdateResponse (com.linkedin.restli.server.UpdateResponse)3 BatchCreateIdResponse (com.linkedin.restli.common.BatchCreateIdResponse)2 StringKeysBuilders (com.linkedin.restli.examples.greetings.client.StringKeysBuilders)2 StringKeysRequestBuilders (com.linkedin.restli.examples.greetings.client.StringKeysRequestBuilders)2