use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverImplTest method testIsResourceTypeWithPaths.
@Test
public void testIsResourceTypeWithPaths() {
final PathBasedResourceResolverImpl resolver = getPathBasedResourceResolver();
/**
* prepare resource type hierarchy
* /types/1
* +- /types/2
* +- /types/3
*/
resolver.add(new SyntheticResourceWithSupertype(resolver, "/types/1", "/types/component", "/types/2"));
resolver.add(new SyntheticResourceWithSupertype(resolver, "/types/2", "/types/component", "/types/3"));
resolver.add(new SyntheticResource(resolver, "/types/3", "/types/component"));
Resource resourceT1 = resolver.add(new SyntheticResource(resolver, "/resourceT1", "/types/1"));
Resource resourceT2 = resolver.add(new SyntheticResource(resolver, "/resourceT2", "/types/2"));
Resource resourceT3 = resolver.add(new SyntheticResource(resolver, "/resourceT3", "/types/3"));
assertTrue(resolver.isResourceType(resourceT1, "/types/1"));
assertTrue(resolver.isResourceType(resourceT1, "/types/2"));
assertTrue(resolver.isResourceType(resourceT1, "/types/3"));
assertFalse(resolver.isResourceType(resourceT1, "/types/component"));
assertFalse(resolver.isResourceType(resourceT1, "/types/unknown"));
assertFalse(resolver.isResourceType(resourceT2, "/types/1"));
assertTrue(resolver.isResourceType(resourceT2, "/types/2"));
assertTrue(resolver.isResourceType(resourceT2, "/types/3"));
assertFalse(resolver.isResourceType(resourceT2, "/types/component"));
assertFalse(resolver.isResourceType(resourceT2, "/types/unknown"));
assertFalse(resolver.isResourceType(resourceT3, "/types/1"));
assertFalse(resolver.isResourceType(resourceT3, "/types/2"));
assertTrue(resolver.isResourceType(resourceT3, "/types/3"));
assertFalse(resolver.isResourceType(resourceT3, "/types/component"));
assertFalse(resolver.isResourceType(resourceT3, "/types/unknown"));
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverImplTest method testIsResourceTypeWithMixedAbsoluteAndRelativePaths.
/**
* @see <a href="https://issues.apache.org/jira/browse/SLING-6327">SLING-6327</a>
*/
@Test
public void testIsResourceTypeWithMixedAbsoluteAndRelativePaths() {
final PathBasedResourceResolverImpl resolver = getPathBasedResourceResolver(new String[] { "/apps/", "/libs/" });
Resource resourceT1 = resolver.add(new SyntheticResource(resolver, "/resourceT1", "types/1"));
Resource resourceT2 = resolver.add(new SyntheticResource(resolver, "/resourceT2", "/apps/types/2"));
Resource resourceT3 = resolver.add(new SyntheticResource(resolver, "/resourceT3", "/libs/types/3"));
Resource resourceT4 = resolver.add(new SyntheticResource(resolver, "/resourceT3", "/someprefix/types/4"));
assertTrue(resolver.isResourceType(resourceT1, "/libs/types/1"));
assertTrue(resolver.isResourceType(resourceT1, "/apps/types/1"));
assertTrue(resolver.isResourceType(resourceT1, "types/1"));
assertTrue(resolver.isResourceType(resourceT2, "/apps/types/2"));
assertTrue(resolver.isResourceType(resourceT2, "types/2"));
assertTrue(resolver.isResourceType(resourceT2, "/libs/types/2"));
assertTrue(resolver.isResourceType(resourceT3, "/apps/types/3"));
assertTrue(resolver.isResourceType(resourceT3, "types/3"));
assertTrue(resolver.isResourceType(resourceT3, "/libs/types/3"));
assertFalse(resolver.isResourceType(resourceT4, "/apps/types/4"));
assertFalse(resolver.isResourceType(resourceT4, "types/4"));
assertFalse(resolver.isResourceType(resourceT4, "/libs/types/4"));
assertTrue(resolver.isResourceType(resourceT4, "/someprefix/types/4"));
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverMangleNamespacesTest method testUnmangleNoSession.
@Test
public void testUnmangleNoSession() {
activeSession = null;
final Resource r = rr.resolve(null, "http://example.com/path/_with_mangling");
assertEquals("/http://example.com/path/_with_mangling", r.getPath());
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverMangleNamespacesTest method testUnmanglePath.
@Test
public void testUnmanglePath() {
final Resource r = rr.resolve(null, "/example.com/path/_with_mangling");
assertEquals("/example.com/path/with:mangling", r.getPath());
}
use of org.apache.sling.api.resource.Resource in project sling by apache.
the class ResourceResolverControlTest method listChildren_root.
/**
* Verifies that listing the children at root lists both the synthetic and the 'real' children
*/
@Test
public void listChildren_root() {
Resource root = crp.getResource(context, "/", null, null, false);
Iterator<Resource> children = crp.listChildren(context, root);
Map<String, Resource> all = new HashMap<String, Resource>();
while (children.hasNext()) {
Resource child = children.next();
all.put(child.getPath(), child);
}
assertThat(all.entrySet(), Matchers.hasSize(2));
assertThat("Resource at /something", all.get("/something"), not(nullValue()));
assertThat("Resource at /some", all.get("/some"), not(nullValue()));
}
Aggregations