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()));
}
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()));
}
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()));
}
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("/"));
}
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");
}
Aggregations