Search in sources :

Example 1 with AssociationsFluentClient

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

the class TestParseqBasedFluentClientApi method testAssociationBatchFinderUsingAssocKey.

@Test
public void testAssociationBatchFinderUsingAssocKey() throws Exception {
    AssociationsFluentClient associations = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    MessageCriteriaArray criteriaArray = new MessageCriteriaArray();
    criteriaArray.add(new MessageCriteria().setTone(Tone.FRIENDLY));
    criteriaArray.add(new MessageCriteria().setTone(Tone.INSULTING));
    BatchCollectionResponse<Message> messages = associations.findBySearchMessages(AssociationResourceHelpers.URL_COMPOUND_KEY.getPartAsString("src"), criteriaArray).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(messages.getResults().size(), 2);
    BatchFinderCriteriaResult<Message> friendly = messages.getResults().get(0);
    Assert.assertFalse(friendly.isError());
    for (Message message : friendly.getElements()) {
        Assert.assertEquals(message.getTone(), Tone.FRIENDLY);
    }
    BatchFinderCriteriaResult<Message> insulting = messages.getResults().get(1);
    Assert.assertTrue(insulting.isError());
    Assert.assertEquals((int) insulting.getError().getStatus(), 404);
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) MessageCriteria(com.linkedin.restli.examples.greetings.api.MessageCriteria) MessageCriteriaArray(com.linkedin.restli.examples.greetings.api.MessageCriteriaArray) AssociationsAssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient) AssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsFluentClient) Test(org.testng.annotations.Test)

Example 2 with AssociationsFluentClient

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

the class TestParseqBasedFluentClientApi method testAssociationFinderUsingAssocKey.

@Test
public void testAssociationFinderUsingAssocKey() throws Exception {
    AssociationsFluentClient associations = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    CollectionResponse<Message> messages = associations.findByAssocKeyFinder(AssociationResourceHelpers.URL_COMPOUND_KEY.getPartAsString("src")).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(messages.getElements().size() > 0);
    for (Message message : messages.getElements()) {
        Assert.assertEquals(message.getId(), AssociationResourceHelpers.URL_MESSAGE.getId());
    }
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) AssociationsAssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient) AssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsFluentClient) Test(org.testng.annotations.Test)

Example 3 with AssociationsFluentClient

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

the class TestParseqBasedFluentClientApi method testSubResource_associationKey.

/**
 * Test {@link com.linkedin.restli.examples.greetings.server.AssociationsSubResource}
 *
 * A complete set of request tests were tested in {@link TestAssociationsResource}
 */
@Test
public void testSubResource_associationKey() throws Exception {
    // AssociationsSub
    String src = "src";
    String dest = "dest";
    String subKey = "subKey";
    CompoundKey key1 = new AssociationsFluentClient.Key().setSrc(src).setDest(dest);
    AssociationsSubFluentClient subFluentClient = new AssociationsSubFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Message response = subFluentClient.withAssociationsId(key1).get(subKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(response.getId(), "src");
    Assert.assertEquals(response.getMessage(), "dest");
    // Repeat using sub client generated from parent
    Associations.AssociationsSub subFluentClient2 = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine()).associationsSubOf(key1);
    response = subFluentClient2.get(subKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(response.getId(), "src");
    Assert.assertEquals(response.getMessage(), "dest");
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) CompoundKey(com.linkedin.restli.common.CompoundKey) AssociationsSubFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsSubFluentClient) AssociationsAssociationsSubFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsSubFluentClient) Associations(com.linkedin.restli.examples.greetings.client.Associations) AssociationsAssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient) AssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsFluentClient) AssociationAltKey(com.linkedin.restli.examples.greetings.client.AssociationAltKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Example 4 with AssociationsFluentClient

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

the class TestParseqBasedFluentClientApi method testAssociateResourceGet.

@Test
public void testAssociateResourceGet() throws Exception {
    Associations associations = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Message response = associations.get(getAssociateResourceUrlKey(associations)).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertTrue(response.hasId());
}
Also used : Message(com.linkedin.restli.examples.greetings.api.Message) Associations(com.linkedin.restli.examples.greetings.client.Associations) AssociationsAssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient) AssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsFluentClient) Test(org.testng.annotations.Test)

Example 5 with AssociationsFluentClient

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

the class TestParseqBasedFluentClientApi method testSubResource_twoLayerAssociationPathKey.

/**
 * Test {@link com.linkedin.restli.examples.greetings.server.AssociationsAssociationsSubResource}
 */
@Test
public void testSubResource_twoLayerAssociationPathKey() throws Exception {
    // AssociationsAssociations
    String src = "src";
    String anotherSrc = "anotherSrc";
    String dest = "dest";
    String anotherDest = "anotherDest";
    String subKey = "subKey";
    CompoundKey key1 = new AssociationsFluentClient.Key().setSrc(src).setDest(dest);
    CompoundKey key2 = new AssociationsAssociationsFluentClient.Key().setAnotherSrc(anotherSrc).setAnotherDest(anotherDest);
    AssociationsAssociationsSubFluentClient subFluentClient = new AssociationsAssociationsSubFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine());
    Message response = subFluentClient.withAssociationsId(key1).withAssociationsAssociationsId(key2).get(subKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(response.getId(), src + anotherSrc + subKey);
    Assert.assertEquals(response.getMessage(), dest + anotherDest);
    // Repeat using sub client generated from parent
    Associations.AssociationsAssociations.AssociationsAssociationsSub subFluentClient2 = new AssociationsFluentClient(_parSeqRestliClient, _parSeqUnitTestHelper.getEngine()).associationsAssociationsOf(key1).associationsAssociationsSubOf(key2);
    response = subFluentClient2.get(subKey).toCompletableFuture().get(5000, TimeUnit.MILLISECONDS);
    Assert.assertEquals(response.getId(), src + anotherSrc + subKey);
    Assert.assertEquals(response.getMessage(), dest + anotherDest);
}
Also used : AssociationsAssociationsSubFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsSubFluentClient) Message(com.linkedin.restli.examples.greetings.api.Message) CompoundKey(com.linkedin.restli.common.CompoundKey) AssociationsAssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient) AssociationsFluentClient(com.linkedin.restli.examples.greetings.client.AssociationsFluentClient) AssociationAltKey(com.linkedin.restli.examples.greetings.client.AssociationAltKey) ComplexResourceKey(com.linkedin.restli.common.ComplexResourceKey) TwoPartKey(com.linkedin.restli.examples.greetings.api.TwoPartKey) CompoundKey(com.linkedin.restli.common.CompoundKey) Test(org.testng.annotations.Test)

Aggregations

AssociationsAssociationsFluentClient (com.linkedin.restli.examples.greetings.client.AssociationsAssociationsFluentClient)8 AssociationsFluentClient (com.linkedin.restli.examples.greetings.client.AssociationsFluentClient)8 Test (org.testng.annotations.Test)8 Message (com.linkedin.restli.examples.greetings.api.Message)6 CompoundKey (com.linkedin.restli.common.CompoundKey)5 Associations (com.linkedin.restli.examples.greetings.client.Associations)5 ComplexResourceKey (com.linkedin.restli.common.ComplexResourceKey)2 UpdateStatus (com.linkedin.restli.common.UpdateStatus)2 TwoPartKey (com.linkedin.restli.examples.greetings.api.TwoPartKey)2 AssociationAltKey (com.linkedin.restli.examples.greetings.client.AssociationAltKey)2 AssociationsAssociationsSubFluentClient (com.linkedin.restli.examples.greetings.client.AssociationsAssociationsSubFluentClient)2 EntityResponse (com.linkedin.restli.common.EntityResponse)1 IdEntityResponse (com.linkedin.restli.common.IdEntityResponse)1 PatchRequest (com.linkedin.restli.common.PatchRequest)1 MessageCriteria (com.linkedin.restli.examples.greetings.api.MessageCriteria)1 MessageCriteriaArray (com.linkedin.restli.examples.greetings.api.MessageCriteriaArray)1 AssociationsSubFluentClient (com.linkedin.restli.examples.greetings.client.AssociationsSubFluentClient)1 HashMap (java.util.HashMap)1