use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestCollectionResponseBuilder method testBuilder.
@SuppressWarnings("unchecked")
@Test(dataProvider = "testData")
public void testBuilder(Object results, DataMap expectedMetadata, List<Foo> expectedElements, CollectionMetadata expectedPaging, MaskTree dataMaskTree, MaskTree metaDataMaskTree, MaskTree pagingMaskTree, ProjectionMode dataProjectionMode, ProjectionMode metadataProjectionMode) throws URISyntaxException {
for (ResourceMethod resourceMethod : Arrays.asList(ResourceMethod.GET_ALL, ResourceMethod.FINDER)) {
Map<String, String> headers = ResponseBuilderUtil.getHeaders();
ResourceContext mockContext = getMockResourceContext(dataMaskTree, metaDataMaskTree, pagingMaskTree, dataProjectionMode, metadataProjectionMode);
ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor(resourceMethod);
RoutingResult routingResult = new RoutingResult(mockContext, mockDescriptor);
CollectionResponseBuilder responseBuilder = new CollectionResponseBuilder();
RestLiResponseData responseData = responseBuilder.buildRestLiResponseData(getRestRequest(), routingResult, results, headers, Collections.<HttpCookie>emptyList());
PartialRestResponse restResponse = responseBuilder.buildResponse(routingResult, responseData);
EasyMock.verify(mockContext, mockDescriptor);
ResponseBuilderUtil.validateHeaders(restResponse, headers);
CollectionResponse<Foo> actualResults = (CollectionResponse<Foo>) restResponse.getEntity();
Assert.assertEquals(actualResults.getElements(), expectedElements);
Assert.assertEquals(actualResults.getMetadataRaw(), expectedMetadata);
Assert.assertEquals(actualResults.getPaging(), expectedPaging);
EasyMock.verify(mockContext);
}
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestMockActionResponseFactory method testDynamicSchema.
@Test
public void testDynamicSchema() {
final RecordTemplateWithDefaultValue record = new RecordTemplateWithDefaultValue();
record.setId(42L);
record.setMessage("Lorem ipsum");
final CollectionResponse<RecordTemplateWithDefaultValue> collectionResponse = new CollectionResponse<RecordTemplateWithDefaultValue>(RecordTemplateWithDefaultValue.class);
collectionResponse.getElements().add(record);
@SuppressWarnings("unchecked") final ActionResponse<CollectionResponse<RecordTemplateWithDefaultValue>> response = (ActionResponse<CollectionResponse<RecordTemplateWithDefaultValue>>) (Object) MockActionResponseFactory.create(CollectionResponse.class, collectionResponse.schema(), collectionResponse);
Assert.assertEquals(response.getValue(), collectionResponse);
final RecordDataSchema schema = response.schema();
Assert.assertEquals(schema.getName(), ActionResponse.class.getSimpleName());
Assert.assertEquals(schema.getField(ActionResponse.VALUE_NAME).getType(), collectionResponse.schema());
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestSimpleResourceHierarchy method testSubCollectionFinder.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestSubBuilderDataProvider")
public void testSubCollectionFinder(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Request<CollectionResponse<Greeting>> request = builders.findBy("Search").setQueryParam("tone", Tone.SINCERE).paginate(1, 2).build();
Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
CollectionResponse<Greeting> collectionResponse = response.getEntity();
List<Greeting> greetings = collectionResponse.getElements();
for (Greeting g : greetings) {
Assert.assertEquals(g.getTone(), Tone.SINCERE);
}
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestPagingProjection method testMetadataManualPagingAutomaticPartialNullNonExistentFields.
/**
* Calls the resource method metadataManualPagingAutomaticPartialNull without even specifying projection fields
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataManualPagingAutomaticPartialNullNonExistentFields(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataManualPagingAutomaticPartialNull").build();
final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
assertGreeting(metadataGreeting, true, /*hasTone*/
true, /*hasMessage*/
true);
//Resource method returned null here for total, so only the total is missing
assertPaging(response.getEntity().getPaging(), false, /*hasTotal*/
true, /*hasStart*/
true, /*hasCount*/
true);
}
use of com.linkedin.restli.common.CollectionResponse in project rest.li by linkedin.
the class TestPagingProjection method testMetadataManualPagingFullyAutomaticSingleMetaMultiplePaging.
/**
* Calls the resource method metadataManualPagingFullyAutomatic with a single metadata field and multiple paging
* fields using 'links' and 'total'.
*/
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testMetadataManualPagingFullyAutomaticSingleMetaMultiplePaging(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
final Request<CollectionResponse<Greeting>> request = builders.findBy("metadataManualPagingFullyAutomatic").metadataFields(Greeting.fields().message()).pagingFields(CollectionMetadata.fields().total(), CollectionMetadata.fields().links()).build();
final Response<CollectionResponse<Greeting>> response = getClient().sendRequest(request).getResponse();
final Greeting metadataGreeting = new Greeting(response.getEntity().getMetadataRaw());
//We should ideally only get back the message field in our metadata, but the resource method here intentionally
//sends back the message and the ID to verify that restli doesn't interfere with a manual metadata projection.
assertGreeting(metadataGreeting, false, /*hasTone*/
true, /*hasMessage*/
true);
Assert.assertTrue(response.getEntity().hasPaging(), "We must have paging!");
assertPaging(response.getEntity().getPaging(), true, /*hasTotal*/
false, /*hasStart*/
false, /*hasCount*/
true);
final int totalCount = response.getEntity().getPaging().getTotal();
Assert.assertEquals(totalCount, 2, "We must have 2 in our count");
}
Aggregations