use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestResourceContext method testResourceContextGetProjectionMaskWithSyntax.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "projectionMaskWithSyntax")
public void testResourceContextGetProjectionMaskWithSyntax(ProtocolVersion version, String stringUri) throws Exception {
URI uri = URI.create(stringUri);
Map<String, String> headers = new HashMap<>(1);
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
ResourceContext context = new ResourceContextImpl(new PathKeysImpl(), new MockRequest(uri, headers), new RequestContext());
final MaskTree entityMask = context.getProjectionMask();
// "{d={$*={f=1, e=1}}, b={$*={c=1}}, a={$*=1}}"
final DataMap expectedEntityMap = new DataMap();
final DataMap aMap = new DataMap();
aMap.put(FilterConstants.WILDCARD, 1);
expectedEntityMap.put("a", aMap);
final DataMap bMap = new DataMap();
final DataMap bWildcardMap = new DataMap();
bWildcardMap.put("c", 1);
bMap.put(FilterConstants.WILDCARD, bWildcardMap);
expectedEntityMap.put("b", bMap);
final DataMap dMap = new DataMap();
final DataMap dWildcardMap = new DataMap();
dWildcardMap.put("f", 1);
dWildcardMap.put("e", 1);
dMap.put(FilterConstants.WILDCARD, dWildcardMap);
expectedEntityMap.put("d", dMap);
Assert.assertEquals(entityMask.getDataMap(), expectedEntityMap, "The generated DataMap for the MaskTree should be correct");
final MaskTree metadataMask = context.getMetadataProjectionMask();
// "{baz={$*={a=1}}, foo={$*={b=1, c=1, a=1}}, bar={$*=1}}"
final DataMap expectedMetadataMap = new DataMap();
final DataMap barMap = new DataMap();
barMap.put(FilterConstants.WILDCARD, 1);
expectedMetadataMap.put("bar", barMap);
final DataMap fooWilcardMap = new DataMap();
fooWilcardMap.put("b", 1);
fooWilcardMap.put("a", 1);
fooWilcardMap.put("c", 1);
final DataMap fooMap = new DataMap();
fooMap.put(FilterConstants.WILDCARD, fooWilcardMap);
expectedMetadataMap.put("foo", fooMap);
final DataMap bazWildcardMap = new DataMap();
bazWildcardMap.put("a", 1);
final DataMap bazMap = new DataMap();
bazMap.put(FilterConstants.WILDCARD, bazWildcardMap);
expectedMetadataMap.put("baz", bazMap);
Assert.assertEquals(metadataMask.getDataMap(), expectedMetadataMap, "The generated DataMap for the MaskTree should be correct");
final MaskTree pagingMask = context.getPagingProjectionMask();
// "{total=1, count=1, links={$*={rel=1}}}"
final DataMap expectedPagingMap = new DataMap();
expectedPagingMap.put("total", 1);
expectedPagingMap.put("count", 1);
final DataMap linksWildcardMap = new DataMap();
linksWildcardMap.put("rel", 1);
final DataMap linksMap = new DataMap();
linksMap.put(FilterConstants.WILDCARD, linksWildcardMap);
expectedPagingMap.put("links", linksMap);
Assert.assertEquals(pagingMask.getDataMap(), expectedPagingMap, "The generated DataMap for the MaskTree should be correct");
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestResourceContext method testResourceContextWithQueryParamsGetProjectionMaskWithMaskSyntax.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "queryParamsProjectionMaskWithSyntax")
public void testResourceContextWithQueryParamsGetProjectionMaskWithMaskSyntax(ProtocolVersion version, String stringUri) throws Exception {
URI uri = URI.create(stringUri);
Map<String, String> headers = new HashMap<>(1);
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
ResourceContext context = new ResourceContextImpl(new PathKeysImpl(), new MockRequest(uri, headers), new RequestContext());
// Assert.assertEquals(mask.toString(), "{location={longitude=1, latitude=1}, locale=1, state=1}");
final MaskTree entityMask = context.getProjectionMask();
final DataMap expectedEntityMap = new DataMap();
expectedEntityMap.put("locale", 1);
expectedEntityMap.put("state", 1);
final DataMap locationMap = new DataMap();
locationMap.put("longitude", 1);
locationMap.put("latitude", 1);
expectedEntityMap.put("location", locationMap);
Assert.assertEquals(entityMask.getDataMap(), expectedEntityMap, "The generated DataMap for the MaskTree should be correct");
// "{region=1, profile={weight=1, height=1}, city=1}"
final MaskTree metadataMask = context.getMetadataProjectionMask();
final DataMap expectedMetadataMap = new DataMap();
expectedMetadataMap.put("city", 1);
expectedMetadataMap.put("region", 1);
final DataMap profileMap = new DataMap();
profileMap.put("weight", 1);
profileMap.put("height", 1);
expectedMetadataMap.put("profile", profileMap);
Assert.assertEquals(metadataMask.getDataMap(), expectedMetadataMap, "The generated DataMap for the MaskTree should be correct");
// Note the lack of a test with paging here. This is because paging (CollectionMetadata) has a LinkArray which
// requires a wildcard path spec in the URI. That behavior is inconsistent with the other projections in this test,
// therefore it will be included in the subsequent test.
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestResourceContext method testResourceContextURIDecoding.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "uriDecoding")
public void testResourceContextURIDecoding(ProtocolVersion version, String stringUri) throws Exception {
URI uri = URI.create(stringUri);
Map<String, String> headers = new HashMap<>(1);
headers.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), new MockRequest(uri, headers), new RequestContext());
final MaskTree entityMask = context.getProjectionMask();
// "{baz=1, foo=1, bar=1}"
final DataMap expectedEntityMap = new DataMap();
expectedEntityMap.put("baz", 1);
expectedEntityMap.put("foo", 1);
expectedEntityMap.put("bar", 1);
Assert.assertEquals(entityMask.getDataMap(), expectedEntityMap, "The generated DataMap for the MaskTree should be correct");
final MaskTree metadataMask = context.getMetadataProjectionMask();
// "{region=1, city=1}"
final DataMap expectedmetadataMap = new DataMap();
expectedmetadataMap.put("region", 1);
expectedmetadataMap.put("city", 1);
Assert.assertEquals(metadataMask.getDataMap(), expectedmetadataMap, "The generated DataMap for the MaskTree should be correct");
final MaskTree pagingMask = context.getPagingProjectionMask();
// "{start=1, links=1}"
final DataMap expectedPagingMap = new DataMap();
expectedPagingMap.put("start", 1);
expectedPagingMap.put("links", 1);
Assert.assertEquals(pagingMask.getDataMap(), expectedPagingMap, "The generated DataMap for the MaskTree should be correct");
DataMap parameters = context.getParameters();
DataMap expectedParameters = new DataMap();
expectedParameters.put("fields", "foo,bar,baz");
expectedParameters.put("metadataFields", "city,region");
expectedParameters.put("pagingFields", "start,links");
expectedParameters.put("q", "test");
DataMap testParam = new DataMap();
DataList aValue = new DataList();
aValue.add("b");
aValue.add("c");
aValue.add("d");
testParam.put("a", aValue);
expectedParameters.put("testParam", testParam);
Assert.assertEquals(parameters, expectedParameters);
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsCollectionDelete.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsCollectionEntity")
public void testRoutingDetailsCollectionDelete(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(StatusCollectionResource.class);
_router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
RestRequest request = createRequest(uri, "DELETE", version);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
ResourceMethodDescriptor resourceMethodDescriptor = _router.process(context);
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.DELETE);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), StatusCollectionResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "delete");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Long.class });
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "statuses");
PathKeys keys = context.getPathKeys();
assertEquals(keys.getAsLong("statusID"), Long.valueOf(1));
assertNull(keys.getAsString("foo"));
}
use of com.linkedin.restli.internal.server.ResourceContextImpl in project rest.li by linkedin.
the class TestRestLiRouting method testRoutingDetailsSimpleUpdate.
@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "routingDetailsSimple")
public void testRoutingDetailsSimpleUpdate(ProtocolVersion version, String uri) throws Exception {
Map<String, ResourceModel> pathRootResourceMap = buildResourceModels(TrendingResource.class);
_router = new RestLiRouter(pathRootResourceMap, new RestLiConfig());
RestRequest request = createRequest(uri, "PUT", version);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
ResourceMethodDescriptor resourceMethodDescriptor = _router.process(context);
assertNotNull(resourceMethodDescriptor);
assertEquals(resourceMethodDescriptor.getType(), ResourceMethod.UPDATE);
assertNull(resourceMethodDescriptor.getActionName());
assertNull(resourceMethodDescriptor.getFinderName());
assertEquals(resourceMethodDescriptor.getMethod().getDeclaringClass(), TrendingResource.class);
assertEquals(resourceMethodDescriptor.getMethod().getName(), "update");
assertEquals(resourceMethodDescriptor.getMethod().getParameterTypes(), new Class<?>[] { Trending.class });
assertEquals(resourceMethodDescriptor.getResourceModel().getName(), "trending");
PathKeys keys = context.getPathKeys();
assertNull(keys.getBatchIds());
}
Aggregations