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