use of org.apache.sling.api.resource.Resource in project sling by apache.
the class MockedResourceResolverImplTest method buildMappingResource.
@SuppressWarnings("unchecked")
private Resource buildMappingResource(String path, ResourceProvider<?> provider, ResourceResolver resourceResolver) {
List<Resource> localHostAnyList = new ArrayList<Resource>();
localHostAnyList.add(buildResource(path + "/http/example.com.80/cgi-bin", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "/scripts"));
localHostAnyList.add(buildResource(path + "/http/example.com.80/gateway", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "http://gbiv.com"));
localHostAnyList.add(buildResource(path + "/http/example.com.80/stories", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "/anecdotes/$1"));
List<Resource> mappingChildren = new ArrayList<Resource>();
mappingChildren.add(buildResource(path + "/http/example.com.80", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:redirect", "http://www.example.com/"));
mappingChildren.add(buildResource(path + "/http/www.example.com.80", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:internalRedirect", "/example"));
mappingChildren.add(buildResource(path + "/http/any_example.com.80", EMPTY_RESOURCE_LIST, resourceResolver, provider, "sling:match", ".+\\.example\\.com\\.80", "sling:redirect", "http://www.example.com/"));
mappingChildren.add(buildResource(path + "/http/localhost_any", localHostAnyList, resourceResolver, provider, "sling:match", "localhost\\.\\d*", "sling:internalRedirect", "/content"));
Resource etcMapResource = buildResource(path + "/http", mappingChildren);
Mockito.when(provider.getResource(Mockito.any(ResolveContext.class), Mockito.eq(path), Mockito.any(ResourceContext.class), Mockito.any(Resource.class))).thenReturn(etcMapResource);
return etcMapResource;
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class MockedResourceResolverImplTest method testRelativeResource.
/**
* Test search paths
* @throws LoginException
*/
@Test
public void testRelativeResource() throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
Assert.assertNotNull(resourceResolver);
Resource appResource = buildResource("/apps/store/inventory", EMPTY_RESOURCE_LIST, resourceResolver, appsResourceProvider);
Resource libResource = buildResource("/libs/store/catalog", EMPTY_RESOURCE_LIST, resourceResolver, appsResourceProvider);
Resource testResource = resourceResolver.getResource("store/inventory");
Assert.assertEquals(appResource, testResource);
testResource = resourceResolver.getResource("store/catalog");
Assert.assertEquals(libResource, testResource);
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceDecorationTest method NonExistentIsDecorated.
@Test
public void NonExistentIsDecorated() {
final Resource r = resolver.resolve("/foo");
assertDecorated(r);
assertExistent(r, false);
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceDecorationTest method listChildrenDecorates.
@Test
public void listChildrenDecorates() {
final Resource testVar = resolver.resolve("/var");
assertDecorated(resolver.listChildren(testVar), 3);
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class AuthenticatedResourceProviderTest method testGetParent.
@Test
public void testGetParent() {
final Resource child = mock(Resource.class);
when(child.getPath()).thenReturn("/parent/child");
final Resource parent = mock(Resource.class);
when(parent.getPath()).thenReturn("/parent");
when(this.resourceProvider.getParent(this.resolveContext, child)).thenReturn(parent);
assertEquals("/parent", this.src.getParent(child).getPath());
}
Aggregations