Search in sources :

Example 1 with ComplexKeysFluentClient

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

the class TestParseqBasedFluentClientApi method testSubResource_complexKeyParentResource.

/**
 * Test {@link com.linkedin.restli.server.resources.ComplexKeyResource}
 *
 * A complete set of request tests were tested in {@link TestComplexKeysResource}
 */
@Test
public void testSubResource_complexKeyParentResource() throws Exception {
    TwoPartKey key = new TwoPartKey();
    key.setMajor("a");
    key.setMinor("b");
    TwoPartKey param = new TwoPartKey();
    param.setMajor("c");
    param.setMinor("d");
    ComplexResourceKey<TwoPartKey, TwoPartKey> complexKey = new ComplexResourceKey<>(key, param);
    ComplexKeysSubFluentClient subFluentClient = new ComplexKeysSubFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    subFluentClient.withKeys(complexKey);
    TwoPartKey response = subFluentClient.get("stringKey").toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(response.getMajor(), "aANDc");
    Assert.assertEquals(response.getMinor(), "bANDd");
    // Repeat using sub client generated from parent
    ComplexKeys.ComplexKeysSub subFluentClient2 = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine()).complexKeysSubOf(complexKey);
    response = subFluentClient2.get("stringKey").toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(response.getMajor(), "aANDc");
    Assert.assertEquals(response.getMinor(), "bANDd");
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) ComplexKeysSubFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysSubFluentClient) Test(org.testng.annotations.Test)

Example 2 with ComplexKeysFluentClient

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

the class TestParseqBasedFluentClientApi method testComplexKey_entityAction.

@Test
public void testComplexKey_entityAction() throws Exception {
    ComplexResourceKey<TwoPartKey, TwoPartKey> key = getComplexKey("major", "minor");
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Integer entity = complexKeyClient.entityAction(key).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(entity.longValue(), 1L);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) ComplexKeys(com.linkedin.restli.examples.greetings.client.ComplexKeys) ComplexKeysFluentClient(com.linkedin.restli.examples.greetings.client.ComplexKeysFluentClient) Test(org.testng.annotations.Test)

Example 3 with ComplexKeysFluentClient

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

the class TestParseqBasedFluentClientApi method testComplexKey_get.

// ComplexKeysResource: Test "Get", "create", "batchGet"
@Test
public void testComplexKey_get() throws Exception {
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    ComplexResourceKey<TwoPartKey, TwoPartKey> testKeys = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
    Message result = complexKeyClient.get(testKeys).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(result.hasId());
    Assert.assertEquals(result.getMessage(), StringTestKeys.SIMPLEKEY + " " + StringTestKeys.SIMPLEKEY2);
}
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)

Example 4 with ComplexKeysFluentClient

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

the class TestParseqBasedFluentClientApi method testComplexKey_batchDelete.

@Test
public void testComplexKey_batchDelete() throws Exception {
    String messageText = "m1";
    Message message = new Message();
    message.setMessage(messageText);
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    ComplexResourceKey<TwoPartKey, TwoPartKey> createResponse = complexKeyClient.create(message).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    String messageText2 = "m2";
    message.setMessage(messageText2);
    createResponse = complexKeyClient.create(message).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key1 = getComplexKey(messageText, messageText);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(messageText2, messageText2);
    ArrayList<ComplexResourceKey<TwoPartKey, TwoPartKey>> ids = new ArrayList<>();
    ids.add(key1);
    ids.add(key2);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, UpdateStatus> deleteResponse = complexKeyClient.batchDelete(new HashSet<>(ids)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(deleteResponse.size(), ids.size());
    Assert.assertEquals(deleteResponse.get(key1).getStatus().intValue(), 204);
    Assert.assertEquals(deleteResponse.get(key2).getStatus().intValue(), 204);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> getResponse = complexKeyClient.batchGet(new HashSet<>(ids)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(getResponse.get(key1).getError().getStatus().intValue(), 404);
    Assert.assertEquals(getResponse.get(key2).getError().getStatus().intValue(), 404);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) UpdateStatus(com.linkedin.restli.common.UpdateStatus) Message(com.linkedin.restli.examples.greetings.api.Message) ArrayList(java.util.ArrayList) 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 5 with ComplexKeysFluentClient

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

the class TestParseqBasedFluentClientApi method testComplexKey_batchUpdate.

@Test
public void testComplexKey_batchUpdate() throws Exception {
    ComplexKeys complexKeyClient = new ComplexKeysFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    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> key1 = getComplexKey(StringTestKeys.SIMPLEKEY, StringTestKeys.SIMPLEKEY2);
    ComplexResourceKey<TwoPartKey, TwoPartKey> key2 = getComplexKey(StringTestKeys.URL, StringTestKeys.URL2);
    inputs.put(key1, message);
    inputs.put(key2, message2);
    complexKeyClient.batchUpdate(inputs).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Map<ComplexResourceKey<TwoPartKey, TwoPartKey>, EntityResponse<Message>> result = complexKeyClient.batchGet(new HashSet<>(Arrays.asList(key1, key2))).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertNotNull(result.get(key1));
    Assert.assertNotNull(result.get(key2));
    Assert.assertEquals(result.get(key1).getEntity().getTone(), Tone.INSULTING);
    Assert.assertEquals(result.get(key2).getEntity().getTone(), Tone.INSULTING);
}
Also used : TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) Message(com.linkedin.restli.examples.greetings.api.Message) HashMap(java.util.HashMap) 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)

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