Search in sources :

Example 86 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceResolverControlTest method copy_sameProvider.

/**
     * Verifies copying resources between the same ResourceProvider
     *
     * @throws PersistenceException persistence exception
     */
@Test
public void copy_sameProvider() throws PersistenceException {
    when(subProvider.copy(mockContext(), Mockito.eq("/some/path/object"), Mockito.eq("/some/path/new"))).thenReturn(true);
    configureResourceAt(subProvider, "/some/path/new/object");
    configureResourceAt(subProvider, "/some/path/new");
    Resource resource = crp.copy(context, "/some/path/object", "/some/path/new");
    assertThat(resource, not(nullValue()));
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 87 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceResolverControlTest method listChildren_lowerLevel.

/**
     * Verifies listing the children at a level below the root
     */
@Test
public void listChildren_lowerLevel() {
    Resource root = crp.getResource(context, "/some", 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(1));
    assertThat("Resource at /some/path", all.get("/some/path"), not(nullValue()));
}
Also used : HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 88 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceResolverControlTest method move_sameProvider.

/**
     * Verifies moving resources between the same ResourceProvider
     *
     * @throws PersistenceException persistence exception
     */
@Test
public void move_sameProvider() throws PersistenceException {
    when(subProvider.move(mockContext(), Mockito.eq("/some/path/object"), Mockito.eq("/some/path/new"))).thenReturn(true);
    configureResourceAt(subProvider, "/some/path/new/object");
    configureResourceAt(subProvider, "/some/path/new");
    Resource resource = crp.move(context, "/some/path/object", "/some/path/new");
    assertThat(resource, not(nullValue()));
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 89 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceResolverControlTest method getParent_found.

/**
     * Verifies that the existing parent of a resource is found
     */
@Test
public void getParent_found() {
    Resource parent = crp.getParent(context, ResourceUtil.getParent(somethingResource.getPath()), somethingResource);
    assertThat(parent, notNullValue());
    assertThat("parent.path", parent.getPath(), equalTo("/"));
}
Also used : Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 90 with Resource

use of org.apache.sling.api.resource.Resource in project sling by apache.

the class ResourceResolverImplTest method testIsResourceCyclicHierarchyDirect.

@Test(expected = SlingException.class)
public void testIsResourceCyclicHierarchyDirect() {
    final PathBasedResourceResolverImpl resolver = getPathBasedResourceResolver();
    /**
         * prepare resource type hierarchy
         * /types/1  <---+
         *  +- /types/2 -+
         */
    resolver.add(new SyntheticResourceWithSupertype(resolver, "/types/1", "/types/component", "/types/2"));
    resolver.add(new SyntheticResourceWithSupertype(resolver, "/types/2", "/types/component", "/types/1"));
    Resource resource = resolver.add(new SyntheticResource(resolver, "/resourceT1", "/types/1"));
    assertTrue(resolver.isResourceType(resource, "/types/1"));
    assertTrue(resolver.isResourceType(resource, "/types/2"));
    // this should throw a SlingException when detecting the cyclic hierarchy
    resolver.isResourceType(resource, "/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)

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