Search in sources :

Example 21 with Message

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

the class TestComplexKeysResource method testBatchUpdateMain.

private void testBatchUpdateMain(RootBuilderWrapper.MethodBuilderWrapper<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message, BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> requestBuilder, BatchGetEntityRequestBuilder<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> batchGetRequestBuilder) throws RemoteInvocationException {
    final String messageText = StringTestKeys.SIMPLEKEY + " " + StringTestKeys.SIMPLEKEY2;
    final Message message = new Message();
    message.setId(StringTestKeys.SIMPLEKEY + " " + StringTestKeys.SIMPLEKEY2);
    message.setMessage(messageText);
    message.setTone(Tone.INSULTING);
    final String messageText2 = StringTestKeys.URL + " " + StringTestKeys.URL2;
    final Message message2 = new Message();
    message2.setId(StringTestKeys.URL + " " + StringTestKeys.URL2);
    message2.setMessage(messageText2);
    message2.setTone(Tone.INSULTING);
    final Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message> inputs = new HashMap<ComplexResourceKey<TwoPartKey, TwoPartKey>, Message>();
    ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key3 = getComplexKey(StringTestKeys.ERROR, StringTestKeys.ERROR);
    inputs.put(key1, message);
    inputs.put(key2, message2);
    // key3 should error anyway, so message is irrelevant.
    inputs.put(key3, message);
    final Request<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> request = requestBuilder.inputs(inputs).build();
    final ResponseFuture<BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus>> future = getClient().sendRequest(request);
    final BatchKVResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> response = future.getResponse().getEntity();
    Assert.assertEquals(response.getResults().size(), inputs.size());
    for (Map.Entry<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> resp : response.getResults().entrySet()) {
        Assert.assertTrue(inputs.containsKey(resp.getKey()));
        final UpdateStatus status = resp.getValue();
        if (status.hasError()) {
            Assert.assertTrue(status.getStatus() == status.getError().getStatus(), "Update status should match the status of the error, if there is any.");
        } else {
            Assert.assertEquals((int) status.getStatus(), 200);
        }
    }
    Assert.assertNotNull(response.getResults().get(key1));
    Assert.assertNotNull(response.getResults().get(key2));
    Assert.assertNotNull(response.getErrors().get(key3));
    ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>>();
    ids.add(key1);
    ids.add(key2);
    BatchGetEntityRequest<ComplexResourceKey<TwoPartKey, TwoPartKey>, 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.INSULTING);
    Assert.assertEquals(batchGetResponse.getResults().get(key2).getEntity().getTone(), Tone.INSULTING);
}
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) 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 22 with Message

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

the class TestComplexKeysResource method testCreateMainNewBuilders.

@SuppressWarnings("deprecation")
private void testCreateMainNewBuilders(CreateIdRequestBuilder<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<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> request = createRequestBuilder.input(message).build();
    ResponseFuture<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> future = getClient().sendRequest(request);
    Response<IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>>> response = future.getResponse();
    try {
        response.getId();
        Assert.fail("getId() for a complex key is not allowed!");
    } catch (UnsupportedOperationException e) {
    // expected
    }
    Assert.assertEquals(response.getStatus(), 201);
    IdResponse<ComplexResourceKey<TwoPartKey, TwoPartKey>> entity = response.getEntity();
    ComplexResourceKey<TwoPartKey, TwoPartKey> id = entity.getId();
    Assert.assertEquals(id, getComplexKey(messageText, messageText));
    // attempt to get the record you just created
    @SuppressWarnings("unchecked") Request<Message> getRequest = getRequestBuilder.id(id).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) BatchCreateIdResponse(com.linkedin.restli.common.BatchCreateIdResponse) IdResponse(com.linkedin.restli.common.IdResponse) Message(com.linkedin.restli.examples.greetings.api.Message) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey)

Example 23 with Message

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

the class TestAssociationsResource method testSubresourceGetForbiddenCharacters.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubresourceGetForbiddenCharacters(RootBuilderWrapper<String, Message> builders) throws RemoteInvocationException {
    Request<Message> request = builders.get().setPathKey("dest", "d&est").setPathKey("src", "s&rc").id("id").build();
    Message message = getClient().sendRequest(request).getResponse().getEntity();
    Assert.assertEquals(message.getId(), "s&rc");
    Assert.assertEquals(message.getMessage(), "d&est");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) Test(org.testng.annotations.Test)

Example 24 with Message

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

the class TestAssociationsResource method testBatchGet.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchGet(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Request<BatchKVResponse<CompoundKey, Message>> request = new AssociationsBuilders(requestOptions).batchGet().ids(DB.keySet()).buildKV();
    ResponseFuture<BatchKVResponse<CompoundKey, Message>> responseFuture = getClient().sendRequest(request);
    Response<BatchKVResponse<CompoundKey, Message>> response = responseFuture.getResponse();
    BatchKVResponse<CompoundKey, Message> entity = response.getEntity();
    Assert.assertEquals(entity.getErrors().size(), 0);
    Assert.assertEquals(entity.getResults().size(), 2);
    for (CompoundKey id : DB.keySet()) {
        Assert.assertTrue(entity.getResults().containsKey(id));
        Assert.assertEquals(entity.getResults().get(id), DB.get(id));
    }
}
Also used : AssociationsBuilders(com.linkedin.restli.examples.greetings.client.AssociationsBuilders) Message(com.linkedin.restli.examples.greetings.api.Message) CompoundKey(com.linkedin.restli.common.CompoundKey) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

Example 25 with Message

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

the class TestAssociationsResource method testBatchGetEntity.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestOptionsDataProvider")
public void testBatchGetEntity(RestliRequestOptions requestOptions) throws RemoteInvocationException {
    Request<BatchKVResponse<CompoundKey, EntityResponse<Message>>> request = new AssociationsRequestBuilders(requestOptions).batchGet().ids(DB.keySet()).build();
    ResponseFuture<BatchKVResponse<CompoundKey, EntityResponse<Message>>> responseFuture = getClient().sendRequest(request);
    Response<BatchKVResponse<CompoundKey, EntityResponse<Message>>> response = responseFuture.getResponse();
    BatchKVResponse<CompoundKey, EntityResponse<Message>> entityResponse = response.getEntity();
    Assert.assertEquals(entityResponse.getErrors().size(), 0);
    Assert.assertEquals(entityResponse.getResults().size(), 2);
    for (CompoundKey id : DB.keySet()) {
        EntityResponse<Message> single = entityResponse.getResults().get(id);
        Assert.assertTrue(entityResponse.getResults().containsKey(id));
        Assert.assertEquals(single.getEntity(), DB.get(id));
    }
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) CompoundKey(com.linkedin.restli.common.CompoundKey) EntityResponse(com.linkedin.restli.common.EntityResponse) AssociationsRequestBuilders(com.linkedin.restli.examples.greetings.client.AssociationsRequestBuilders) BatchKVResponse(com.linkedin.restli.client.response.BatchKVResponse) Test(org.testng.annotations.Test)

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