Search in sources :

Example 81 with Resource

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"));
}
Also used : NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) Test(org.junit.Test)

Example 82 with Resource

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"));
}
Also used : NonExistingResource(org.apache.sling.api.resource.NonExistingResource) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) Test(org.junit.Test)

Example 83 with Resource

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());
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 84 with Resource

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());
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 85 with Resource

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()));
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)1151 Test (org.junit.Test)633 ValueMap (org.apache.sling.api.resource.ValueMap)263 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)164 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)159 Node (javax.jcr.Node)116 HashMap (java.util.HashMap)104 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)99 PersistenceException (org.apache.sling.api.resource.PersistenceException)94 ArrayList (java.util.ArrayList)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)62 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)60 FakeSlingHttpServletRequest (org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest)59 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)55 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)43 Map (java.util.Map)41 InputStream (java.io.InputStream)38 LoginException (org.apache.sling.api.resource.LoginException)37 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)36 Iterator (java.util.Iterator)33