use of com.linkedin.restli.internal.testutils.URIDetails in project rest.li by linkedin.
the class TestCompressionServer method testSearchWithPostFilter.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCompressedResponsesBuilderDataProvider")
public void testSearchWithPostFilter(RestClient client, String operationsForCompression, RootBuilderWrapper<Long, Greeting> builders, ProtocolVersion protocolVersion) throws RemoteInvocationException {
Request<CollectionResponse<Greeting>> findRequest = builders.findBy("SearchWithPostFilter").paginate(0, 5).build();
Response<CollectionResponse<Greeting>> response = client.sendRequest(findRequest).getResponse();
checkHeaderForCompression(response, operationsForCompression, "finder:" + findRequest.getMethodName());
CollectionResponse<Greeting> entity = response.getEntity();
CollectionMetadata paging = entity.getPaging();
Assert.assertEquals(paging.getStart().intValue(), 0);
Assert.assertEquals(paging.getCount().intValue(), 5);
// expected to be 4 instead of 5 because of post filter
Assert.assertEquals(entity.getElements().size(), 4);
// to accommodate post filtering, even though 4 are returned, next page should be 5-10.
Link next = paging.getLinks().get(0);
Assert.assertEquals(next.getRel(), "next");
//Query parameter order is non deterministic
//greetings?count=5&start=5&q=searchWithPostFilter"
final Map<String, String> queryParamsMap = new HashMap<String, String>();
queryParamsMap.put("count", "5");
queryParamsMap.put("start", "5");
queryParamsMap.put("q", "searchWithPostFilter");
final URIDetails uriDetails = new URIDetails(protocolVersion, "/greetings", null, queryParamsMap, null);
URIDetails.testUriGeneration(next.getHref(), uriDetails);
}
use of com.linkedin.restli.internal.testutils.URIDetails in project rest.li by linkedin.
the class TestRestLiResponseHandler method testCollections.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
public void testCollections(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
ResourceModel resourceModel = buildResourceModel(StatusCollectionResource.class);
ResourceMethodDescriptor methodDescriptor = resourceModel.findNamedMethod("search");
RestResponse response;
// #1 check datamap/entity structure
ServerResourceContext context = new ResourceContextImpl();
RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptTypeData.acceptHeaders, context);
response = _responseHandler.buildResponse(buildRequest(acceptTypeData.acceptHeaders, protocolVersion), new RoutingResult(context, methodDescriptor), buildStatusList(3));
checkResponse(response, 200, 2, acceptTypeData.responseContentType, CollectionResponse.class.getName(), Status.class.getName(), true, errorResponseHeaderName);
String baseUri = "/test?someParam=foo";
// #1.1 using CollectionResult
response = invokeResponseHandler(baseUri + "&start=0&count=5", methodDescriptor, new BasicCollectionResult<Status>(buildStatusList(5)), acceptTypeData.acceptHeaders, protocolVersion);
checkCollectionResponse(response, 5, 0, 5, 1, null, null, null, acceptTypeData);
// #1.1 using CollectionResult (with total)
response = invokeResponseHandler(baseUri + "&start=0&count=5", methodDescriptor, new BasicCollectionResult<Status>(buildStatusList(5), 10), acceptTypeData.acceptHeaders, protocolVersion);
checkCollectionResponse(response, 5, 0, 5, 1, 10, null, null, acceptTypeData);
// using CollectionResult with metadata RecordTemplate
CollectionMetadata metadata = new CollectionMetadata();
metadata.setCount(42);
response = invokeResponseHandler(baseUri + "&start=0&count=5", methodDescriptor, new CollectionResult<Status, CollectionMetadata>(buildStatusList(5), 10, metadata), acceptTypeData.acceptHeaders, protocolVersion);
checkCollectionResponse(response, 5, 0, 5, 1, 10, null, null, acceptTypeData);
DataMap dataMap = acceptTypeData.dataCodec.readMap(response.getEntity().asInputStream());
CollectionResponse<Status> collectionResponse = new CollectionResponse<Status>(dataMap, Status.class);
assertEquals(new CollectionMetadata(collectionResponse.getMetadataRaw()), metadata);
// #2 pagination: first page, no next
response = invokeResponseHandler(baseUri + "&start=0&count=5", methodDescriptor, buildStatusList(3), acceptTypeData.acceptHeaders, protocolVersion);
checkCollectionResponse(response, 3, 0, 5, 0, null, null, null, acceptTypeData);
// #3 pagination: first page, has next (boundary case)
response = invokeResponseHandler(baseUri + "&start=0&count=5", methodDescriptor, buildStatusList(5), acceptTypeData.acceptHeaders, protocolVersion);
//"/test?count=5&start=5&someParam=foo"
final Map<String, String> queryParamsMap3next = new HashMap<String, String>();
queryParamsMap3next.put("count", "5");
queryParamsMap3next.put("start", "5");
queryParamsMap3next.put("someParam", "foo");
final URIDetails expectedURIDetails3next = new URIDetails(protocolVersion, "/test", null, queryParamsMap3next, null);
checkCollectionResponse(response, 5, 0, 5, 1, null, null, expectedURIDetails3next, acceptTypeData);
// #4 pagination: second page, has prev/ext
response = invokeResponseHandler(baseUri + "&start=5&count=5", methodDescriptor, buildStatusList(5), acceptTypeData.acceptHeaders, protocolVersion);
//"/test?count=5&start=0&someParam=foo", "/test?count=5&start=10&someParam=foo",
final Map<String, String> queryParamsMap4prev = new HashMap<String, String>();
queryParamsMap4prev.put("count", "5");
queryParamsMap4prev.put("start", "0");
queryParamsMap4prev.put("someParam", "foo");
final URIDetails expectedURIDetails4prev = new URIDetails(protocolVersion, "/test", null, queryParamsMap4prev, null);
final Map<String, String> queryParamsMap4next = new HashMap<String, String>();
queryParamsMap4next.put("count", "5");
queryParamsMap4next.put("start", "10");
queryParamsMap4next.put("someParam", "foo");
final URIDetails expectedURIDetails4next = new URIDetails(protocolVersion, "/test", null, queryParamsMap4next, null);
checkCollectionResponse(response, 5, 5, 5, 2, null, expectedURIDetails4prev, expectedURIDetails4next, acceptTypeData);
// #5 pagination:last page, has prev
response = invokeResponseHandler(baseUri + "&start=10&count=5", methodDescriptor, buildStatusList(4), acceptTypeData.acceptHeaders, protocolVersion);
//"/test?count=5&start=5&someParam=foo"
final Map<String, String> queryParamsMap5prev = new HashMap<String, String>();
queryParamsMap5prev.put("count", "5");
queryParamsMap5prev.put("start", "5");
queryParamsMap5prev.put("someParam", "foo");
final URIDetails expectedURIDetails5prev = new URIDetails(protocolVersion, "/test", null, queryParamsMap5prev, null);
checkCollectionResponse(response, 4, 10, 5, 1, null, expectedURIDetails5prev, null, acceptTypeData);
response = invokeResponseHandler(baseUri + "&start=10&count=5", methodDescriptor, new BasicCollectionResult<Status>(buildStatusList(4), 15), acceptTypeData.acceptHeaders, protocolVersion);
//"/test?count=5&start=5&someParam=foo", "/test?count=5&start=14&someParam=foo"
final Map<String, String> queryParamsMap6prev = new HashMap<String, String>();
queryParamsMap6prev.put("count", "5");
queryParamsMap6prev.put("start", "5");
queryParamsMap6prev.put("someParam", "foo");
final URIDetails expectedURIDetails6prev = new URIDetails(protocolVersion, "/test", null, queryParamsMap6prev, null);
final Map<String, String> queryParamsMap6next = new HashMap<String, String>();
queryParamsMap6next.put("count", "5");
queryParamsMap6next.put("start", "14");
queryParamsMap6next.put("someParam", "foo");
final URIDetails expectedURIDetails6next = new URIDetails(protocolVersion, "/test", null, queryParamsMap6next, null);
checkCollectionResponse(response, 4, 10, 5, 2, 15, expectedURIDetails6prev, expectedURIDetails6next, acceptTypeData);
response = invokeResponseHandler(baseUri + "&start=10&count=5", methodDescriptor, new BasicCollectionResult<Status>(buildStatusList(4), 14), acceptTypeData.acceptHeaders, protocolVersion);
//"/test?count=5&start=5&someParam=foo"
final Map<String, String> queryParamsMap7prev = new HashMap<String, String>();
queryParamsMap7prev.put("count", "5");
queryParamsMap7prev.put("start", "5");
queryParamsMap7prev.put("someParam", "foo");
final URIDetails expectedURIDetails7prev = new URIDetails(protocolVersion, "/test", null, queryParamsMap7prev, null);
checkCollectionResponse(response, 4, 10, 5, 1, 14, expectedURIDetails7prev, null, acceptTypeData);
}
use of com.linkedin.restli.internal.testutils.URIDetails in project rest.li by linkedin.
the class TestGreetingsClient method testSearchWithPostFilter.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderWithResourceNameDataProvider")
public void testSearchWithPostFilter(RootBuilderWrapper<Long, Greeting> builders, String resourceName, ProtocolVersion protocolVersion) throws RemoteInvocationException {
Request<CollectionResponse<Greeting>> findRequest = builders.findBy("SearchWithPostFilter").paginate(0, 5).build();
CollectionResponse<Greeting> entity = getClient().sendRequest(findRequest).getResponse().getEntity();
CollectionMetadata paging = entity.getPaging();
Assert.assertEquals(paging.getStart().intValue(), 0);
Assert.assertEquals(paging.getCount().intValue(), 5);
// expected to be 4 instead of 5 because of post filter
Assert.assertEquals(entity.getElements().size(), 4);
// to accommodate post filtering, even though 4 are returned, next page should be 5-10.
Link next = paging.getLinks().get(0);
Assert.assertEquals(next.getRel(), "next");
//Query parameter order is non deterministic
//"/" + resourceName + "?count=5&start=5&q=searchWithPostFilter";
final Map<String, String> queryParamsMap = new HashMap<String, String>();
queryParamsMap.put("count", "5");
queryParamsMap.put("start", "5");
queryParamsMap.put("q", "searchWithPostFilter");
final URIDetails uriDetails = new URIDetails(protocolVersion, "/" + resourceName, null, queryParamsMap, null);
URIDetails.testUriGeneration(next.getHref(), uriDetails);
}
use of com.linkedin.restli.internal.testutils.URIDetails in project rest.li by linkedin.
the class TestClientBuilders method encodingEqualsAnd2.
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "encodingEqualsAndKey")
public Object[][] encodingEqualsAnd2() {
//Sample URIs:
//"test/3?foo%26bar%3Dbaz=qux"
//"test/3?foo%26bar%3Dbaz=qux"
final Map<String, String> queryParamsMap = new HashMap<String, String>();
queryParamsMap.put("foo&bar=baz", "qux");
final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "test/3", null, queryParamsMap, null);
final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "test/3", null, queryParamsMap, null);
return new Object[][] { { uriDetails1 }, { uriDetails2 } };
}
use of com.linkedin.restli.internal.testutils.URIDetails in project rest.li by linkedin.
the class TestClientBuilders method subSubResourceBatch.
@DataProvider(name = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "subSubResourceBatch")
public Object[][] subSubResourceBatch() {
//Sample URIs:
//"foo/1/bar/2/baz?ids=1&ids=2"
//"foo/1/bar/2/baz?ids=List(1,2)"
final Set<String> idSet = new HashSet<String>();
idSet.add("1");
idSet.add("2");
final URIDetails uriDetails1 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion(), "foo/1/bar/2/baz", idSet, null, null);
final URIDetails uriDetails2 = new URIDetails(AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion(), "foo/1/bar/2/baz", idSet, null, null);
return new Object[][] { { uriDetails1 }, { uriDetails2 } };
}
Aggregations