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);
}
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());
}
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!");
}
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));
}
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");
}
Aggregations