Search in sources :

Example 1 with ResourceWrapper

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

the class ResourceResolverWrapperTest method testCreate.

@Test
public void testCreate() throws Exception {
    final Resource parent = mock(Resource.class);
    final String name = "aName";
    @SuppressWarnings("serial") final Map<String, Object> properties = new HashMap<String, Object>() {

        {
            put("jcr:primaryType", "nt:unstructured");
        }
    };
    final Resource expected = mock(Resource.class);
    when(expected.getParent()).thenReturn(parent);
    when(expected.getName()).thenReturn(name);
    when(wrappedResolver.create(parent, name, properties)).thenReturn(expected);
    final Resource result = underTest.create(parent, name, properties);
    assertTrue(result instanceof ResourceWrapper);
    assertEquals(parent, result.getParent());
    assertEquals(name, result.getName());
    verify(wrappedResolver).create(parent, name, properties);
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) HashMap(java.util.HashMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 2 with ResourceWrapper

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

the class ResourceResolverWrapperTest method testMove.

@Test
public void testMove() throws Exception {
    final String source = "source";
    final String destination = "destination";
    final Resource expected = mock(Resource.class);
    when(expected.getPath()).thenReturn(destination);
    when(wrappedResolver.move(source, destination)).thenReturn(expected);
    final Resource result = underTest.move(source, destination);
    assertTrue(result instanceof ResourceWrapper);
    assertEquals(underTest, result.getResourceResolver());
    assertEquals(destination, result.getPath());
    verify(wrappedResolver).move(source, destination);
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 3 with ResourceWrapper

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

the class ResourceResolverWrapperTest method testResolve1.

@Test
public void testResolve1() throws Exception {
    final Resource resource = mock(Resource.class);
    when(resource.getPath()).thenReturn(PATH);
    when(wrappedResolver.resolve(PATH)).thenReturn(resource);
    final Resource result = underTest.resolve(PATH);
    assertTrue(result instanceof ResourceWrapper);
    assertEquals(underTest, result.getResourceResolver());
    assertEquals(resource.getPath(), result.getPath());
    verify(wrappedResolver).resolve(PATH);
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 4 with ResourceWrapper

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

the class ResourceResolverWrapperTest method testListChildren.

@Test
public void testListChildren() throws Exception {
    final Resource parent = mock(Resource.class);
    final List<Resource> children = new ArrayList<>(1);
    final Resource child = mock(Resource.class);
    when(child.getPath()).thenReturn(PATH);
    children.add(child);
    when(wrappedResolver.listChildren(parent)).thenAnswer(new Answer<Iterator<Resource>>() {

        @Override
        public Iterator<Resource> answer(InvocationOnMock invocationOnMock) throws Throwable {
            return children.iterator();
        }
    });
    int index = 0;
    Iterator<Resource> wrappedIterator = underTest.listChildren(parent);
    assertTrue(wrappedIterator instanceof IteratorWrapper);
    while (wrappedIterator.hasNext()) {
        Resource result = wrappedIterator.next();
        assertTrue(result instanceof ResourceWrapper);
        assertEquals(PATH, result.getPath());
        index++;
    }
    assertEquals(1, index);
    verify(wrappedResolver).listChildren(parent);
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Resource(org.apache.sling.api.resource.Resource) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 5 with ResourceWrapper

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

the class ResourceResolverWrapperTest method testFindResources.

@Test
public void testFindResources() throws Exception {
    final List<Resource> children = new ArrayList<>(1);
    final Resource child = mock(Resource.class);
    when(child.getPath()).thenReturn(PATH);
    children.add(child);
    when(wrappedResolver.findResources(QUERY, LANGUAGE)).thenAnswer(new Answer<Iterator<Resource>>() {

        @Override
        public Iterator<Resource> answer(InvocationOnMock invocationOnMock) throws Throwable {
            return children.iterator();
        }
    });
    int index = 0;
    final Iterator<Resource> wrappedIterator = underTest.findResources(QUERY, LANGUAGE);
    assertTrue(wrappedIterator instanceof IteratorWrapper);
    while (wrappedIterator.hasNext()) {
        Resource result = wrappedIterator.next();
        assertTrue(result instanceof ResourceWrapper);
        assertEquals(PATH, result.getPath());
        index++;
    }
    assertEquals(1, index);
    verify(wrappedResolver).findResources(QUERY, LANGUAGE);
}
Also used : ResourceWrapper(org.apache.sling.api.resource.ResourceWrapper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) Resource(org.apache.sling.api.resource.Resource) Iterator(java.util.Iterator) Test(org.junit.Test)

Aggregations

ResourceWrapper (org.apache.sling.api.resource.ResourceWrapper)20 Resource (org.apache.sling.api.resource.Resource)19 Test (org.junit.Test)15 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Style (com.day.cq.wcm.api.designer.Style)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Node (javax.jcr.Node)1 RepositoryException (javax.jcr.RepositoryException)1 ResourceMetadata (org.apache.sling.api.resource.ResourceMetadata)1 Test (org.junit.jupiter.api.Test)1