Search in sources :

Example 1 with BatchFinderCriteriaResult

use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.

the class TestMockBatchCollectionResponseFactory method testCreateWithPagingAndMetadata.

@Test
public void testCreateWithPagingAndMetadata() {
    List<List<Greeting>> greetingsList = new ArrayList<>();
    Greeting g1 = new Greeting().setId(1L).setMessage("g1");
    List<Greeting> greetings1 = Collections.singletonList(g1);
    greetingsList.add(greetings1);
    Greeting g2 = new Greeting().setId(2L).setMessage("g2");
    List<Greeting> greetings2 = Collections.singletonList(g2);
    greetingsList.add(greetings2);
    List<CollectionMetadata> pagingList = new ArrayList<>();
    CollectionMetadata paging1 = new CollectionMetadata().setCount(2).setStart(0).setTotal(2);
    pagingList.add(paging1);
    pagingList.add(null);
    List<DataMap> metadataList = new ArrayList<>();
    metadataList.add(null);
    DataMap customMetadata2 = new DataMap();
    customMetadata2.put("foo", "bar");
    metadataList.add(customMetadata2);
    BatchCollectionResponse<Greeting> batchCollectionResponse = MockBatchCollectionResponseFactory.create(Greeting.class, greetingsList, pagingList, metadataList);
    List<BatchFinderCriteriaResult<Greeting>> elements = batchCollectionResponse.getResults();
    Assert.assertEquals(elements.size(), 2);
    BatchFinderCriteriaResult<Greeting> criteriaResult1 = elements.get(0);
    Assert.assertEquals(criteriaResult1.getElements(), greetings1);
    Assert.assertEquals(criteriaResult1.getPaging(), paging1);
    Assert.assertNull(criteriaResult1.getMetadataRaw());
    BatchFinderCriteriaResult<Greeting> criteriaResult2 = elements.get(1);
    Assert.assertEquals(criteriaResult2.getElements(), greetings2);
    Assert.assertNull(criteriaResult2.getPaging());
    Assert.assertEquals(criteriaResult2.getMetadataRaw(), customMetadata2);
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionMetadata(com.linkedin.restli.common.CollectionMetadata) ArrayList(java.util.ArrayList) DataMap(com.linkedin.data.DataMap) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 2 with BatchFinderCriteriaResult

use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.

the class TestMockBatchCollectionResponseFactory method testCreate.

@Test
public void testCreate() {
    Greeting g1 = new Greeting().setId(1L).setMessage("g1");
    Greeting g2 = new Greeting().setId(2L).setMessage("g2");
    List<Greeting> greetings1 = Collections.singletonList(g1);
    List<Greeting> greetings2 = Collections.singletonList(g2);
    List<List<Greeting>> greetingsList = new ArrayList<>();
    greetingsList.add(greetings1);
    greetingsList.add(greetings2);
    BatchCollectionResponse<Greeting> batchCollectionResponse = MockBatchCollectionResponseFactory.create(Greeting.class, greetingsList, Collections.emptyList(), Collections.emptyList());
    List<BatchFinderCriteriaResult<Greeting>> elements = batchCollectionResponse.getResults();
    Assert.assertEquals(elements.size(), 2);
    BatchFinderCriteriaResult<Greeting> criteriaResult1 = elements.get(0);
    Assert.assertEquals(criteriaResult1.getElements(), greetings1);
    Assert.assertNull(criteriaResult1.getPaging());
    Assert.assertNull(criteriaResult1.getMetadataRaw());
    BatchFinderCriteriaResult<Greeting> criteriaResult2 = elements.get(1);
    Assert.assertEquals(criteriaResult2.getElements(), greetings2);
    Assert.assertNull(criteriaResult2.getPaging());
    Assert.assertNull(criteriaResult2.getMetadataRaw());
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 3 with BatchFinderCriteriaResult

use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.

the class TestBatchFinderResource method testBatchFinderWithError.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinderWithError(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c3 = new GreetingCriteria().setId(100L);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").addQueryParam("criteria", c3).setQueryParam("message", "hello world").build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 1);
    ErrorResponse error = batchResult.get(0).getError();
    Assert.assertEquals(error.getMessage(), "Fail to find Greeting!");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 4 with BatchFinderCriteriaResult

use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.

the class TestBatchFinderResource method testBatchFinder.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinder(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c1 = new GreetingCriteria().setId(1L).setTone(Tone.SINCERE);
    GreetingCriteria c2 = new GreetingCriteria().setId(2L).setTone(Tone.FRIENDLY);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").setQueryParam("criteria", Arrays.asList(c1, c2)).setQueryParam("message", "hello world").build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    List<Greeting> greetings1 = batchResult.get(0).getElements();
    Assert.assertTrue(greetings1.get(0).hasTone());
    Assert.assertTrue(greetings1.get(0).getTone().equals(Tone.SINCERE));
    List<Greeting> greetings2 = batchResult.get(1).getElements();
    Assert.assertTrue(greetings2.get(0).hasId());
    Assert.assertTrue(greetings2.get(0).getTone().equals(Tone.FRIENDLY));
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) Test(org.testng.annotations.Test)

Example 5 with BatchFinderCriteriaResult

use of com.linkedin.restli.common.BatchFinderCriteriaResult in project rest.li by linkedin.

the class TestBatchFinderResource method testBatchFinderWithNotFoundCriteria.

@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "batchFindersRequestBuilderDataProvider")
public void testBatchFinderWithNotFoundCriteria(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
    GreetingCriteria c4 = new GreetingCriteria().setId(0L);
    Request<BatchCollectionResponse<Greeting>> request = builders.batchFindBy("searchGreetings").addQueryParam("criteria", c4).setQueryParam("message", "hello world").build();
    ResponseFuture<BatchCollectionResponse<Greeting>> future = getClient().sendRequest(request);
    BatchCollectionResponse<Greeting> response = future.getResponse().getEntity();
    List<BatchFinderCriteriaResult<Greeting>> batchResult = response.getResults();
    Assert.assertEquals(batchResult.size(), 1);
    ErrorResponse error = batchResult.get(0).getError();
    Assert.assertEquals(error.getMessage(), "The server didn't find a representation for this criteria");
}
Also used : Greeting(com.linkedin.restli.examples.greetings.api.Greeting) BatchFinderCriteriaResult(com.linkedin.restli.common.BatchFinderCriteriaResult) BatchCollectionResponse(com.linkedin.restli.common.BatchCollectionResponse) GreetingCriteria(com.linkedin.restli.examples.greetings.api.GreetingCriteria) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Aggregations

BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)14 Test (org.testng.annotations.Test)14 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)12 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)11 GreetingCriteria (com.linkedin.restli.examples.greetings.api.GreetingCriteria)10 ErrorResponse (com.linkedin.restli.common.ErrorResponse)6 List (java.util.List)4 CollectionMetadata (com.linkedin.restli.common.CollectionMetadata)3 Batchfinders (com.linkedin.restli.examples.greetings.client.Batchfinders)3 BatchfindersFluentClient (com.linkedin.restli.examples.greetings.client.BatchfindersFluentClient)3 CreateGreeting (com.linkedin.restli.examples.greetings.client.CreateGreeting)3 PartialUpdateGreeting (com.linkedin.restli.examples.greetings.client.PartialUpdateGreeting)3 ParSeqUnitTestHelper (com.linkedin.parseq.ParSeqUnitTestHelper)2 ParSeqRestliClient (com.linkedin.restli.client.ParSeqRestliClient)2 ParSeqRestliClientBuilder (com.linkedin.restli.client.ParSeqRestliClientBuilder)2 ParSeqRestliClientConfigBuilder (com.linkedin.restli.client.ParSeqRestliClientConfigBuilder)2 RestLiResponseException (com.linkedin.restli.client.RestLiResponseException)2 PatchGenerator (com.linkedin.restli.client.util.PatchGenerator)2 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 CreateIdEntityStatus (com.linkedin.restli.common.CreateIdEntityStatus)2