Search in sources :

Example 6 with ComplexKeysFluentClient

use of com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient in project rest.li by linkedin.

the class TestParseqBasedFluentClientApi method testComplexKey_batchGet.

@Test
public void testComplexKey_batchGet() throws Exception {
    List<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = getBatchComplexKeys();
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> resultMap = complexKeyClient.batchGet(new HashSet<>(ids)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(resultMap.size(), 3);
    Assert.assertNotNull(resultMap.get(ids.get(0)).getEntity());
    Assert.assertNotNull(resultMap.get(ids.get(1)).getEntity());
    Assert.assertNotNull(resultMap.get(ids.get(2)).getError());
}
Also used : EntityResponse(com.linkedin.restli.common.EntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Example 7 with ComplexKeysFluentClient

use of com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient in project rest.li by linkedin.

the class TestParseqBasedFluentClientApi method testComplexKey_partialUpdate.

@Test
public void testComplexKey_partialUpdate() throws Exception {
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    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> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
    inputs.put(key1, patch);
    inputs.put(key2, patch);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> result = complexKeyClient.batchPartialUpdate(inputs).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    // Update return valid result
    Assert.assertEquals(result.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(result.get(key2).getStatus().intValue(), 204);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResult = complexKeyClient.batchGet(new HashSet<>(Arrays.asList(key1, key2))).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(getResult.get(key1).getEntity().getTone(), Tone.FRIENDLY);
    Assert.assertEquals(getResult.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) PatchRequest(com.linkedin.restli.common.PatchRequest) EntityResponse(com.linkedin.restli.common.EntityResponse) IdEntityResponse(com.linkedin.restli.common.IdEntityResponse) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) Test(org.testng.annotations.Test)

Example 8 with ComplexKeysFluentClient

use of com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient in project rest.li by linkedin.

the class TestParseqBasedFluentClientApi method testComplexKey_createThenGet.

@Test
public void testComplexKey_createThenGet() throws Exception {
    final String messageText = "newMessage";
    Message message = new Message();
    message.setMessage(messageText);
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    ComplexResourceKey<TwoPartKey, TwoPartKey> result = complexKeyClient.create(message).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(result, getComplexKey(messageText, messageText));
    Assert.assertEquals(complexKeyClient.get(result).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS).getMessage(), messageText);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) Test(org.testng.annotations.Test)

Aggregations

ComplexKeys (com.linkedin.restli.examples.greetings.client.ComplexKeys)8 ComplexKeysFluentClient (com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient)8 Test (org.testng.annotations.Test)8 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)7 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)5 Message (com.linkedin.restli.examples.greetings.api.Message)5 EntityResponse (com.linkedin.restli.common.EntityResponse)4 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)4 UpdateStatus (com.linkedin.restli.common.UpdateStatus)2 HashMap (java.util.HashMap)2 PatchRequest (com.linkedin.restli.common.PatchRequest)1 ComplexKeysSubFluentClient (com.linkedin.restli.examples.greetings.client.ComplexKeysSubFluentClient)1 ArrayList (java.util.ArrayList)1