use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class MockedResourceResolverImplTest method testQueryResources.
@SuppressWarnings("unchecked")
@Test
public void testQueryResources() throws LoginException {
final int n = 3;
String[] languages = new String[] { FAKE_QUERY_LANGUAGE };
Mockito.when(queryProvider.getSupportedLanguages(Mockito.any(ResolveContext.class))).thenReturn(languages);
Mockito.when(queryProvider.queryResources(Mockito.any(ResolveContext.class), Mockito.any(String.class), Mockito.any(String.class))).thenReturn(buildValueMapCollection(n, "A_").iterator());
final ResourceResolver rr = resourceResolverFactory.getResourceResolver(null);
buildResource("/search/test/withchildren", buildChildResources("/search/test/withchildren"), rr, resourceProvider);
final Iterator<Map<String, Object>> it = rr.queryResources("/search", FAKE_QUERY_LANGUAGE);
final Set<String> toFind = new HashSet<String>();
for (int i = 0; i < n; i++) {
toFind.add("A_" + i);
}
assertTrue("Expecting non-empty result (" + n + ")", it.hasNext());
while (it.hasNext()) {
final Map<String, Object> m = it.next();
toFind.remove(m.get(PATH));
}
assertTrue("Expecting no leftovers (" + n + ") in" + toFind, toFind.isEmpty());
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class ResourceResolverWebConsolePlugin method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
final String test = request.getParameter(ATTR_TEST);
String msg = null;
if (test != null && test.length() > 0) {
ResourceResolver resolver = null;
try {
// prepare the request for the resource resolver
HttpServletRequest helper = new ResolverRequest(request, test);
resolver = resolverFactory.getServiceResourceResolver(this.resolverFactory.getServiceUserAuthenticationInfo("console"));
// map or resolve as instructed
Object result;
if ("Map".equals(request.getParameter(ATTR_SUBMIT))) {
if (helper.getServerName() == null) {
result = resolver.map(helper.getPathInfo());
} else {
result = resolver.map(helper, helper.getPathInfo());
}
} else {
result = resolver.resolve(helper, helper.getPathInfo());
}
// set the result to render the result
msg = result.toString();
} catch (final Throwable t) {
// some error occurred, report it as a result
msg = "Test Failure: " + t;
} finally {
if (resolver != null) {
resolver.close();
}
}
}
// finally redirect
final String path = request.getContextPath() + request.getServletPath() + request.getPathInfo();
final String redirectTo;
if (msg == null) {
redirectTo = path;
} else {
redirectTo = path + '?' + PAR_MSG + '=' + encodeParam(msg) + '&' + PAR_TEST + '=' + encodeParam(test);
}
response.sendRedirect(redirectTo);
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class MockedResourceResolverImplTest method testResourceResolverListChildren.
/**
* Test listing children via the resource resolver listChildren call.
* @throws LoginException
*/
@Test
public void testResourceResolverListChildren() throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
buildResource("/single/test/withchildren", buildChildResources("/single/test/withchildren"), resourceResolver, resourceProvider);
Resource resource = resourceResolver.getResource("/single/test/withchildren");
Assert.assertNotNull(resource);
// test via the resource list children itself, this really just tests this test case.
Iterator<Resource> resourceIterator = resourceResolver.listChildren(resource);
Assert.assertNotNull(resourceResolver);
int i = 0;
while (resourceIterator.hasNext()) {
Assert.assertEquals("m" + i, resourceIterator.next().getName());
i++;
}
Assert.assertEquals(5, i);
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class MockedResourceResolverImplTest method testGetAuthenticatedResolve.
/**
* Test various administrative resource resolvers.
* @throws LoginException
*/
@Test
public void testGetAuthenticatedResolve() throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null);
Assert.assertNotNull(resourceResolver);
Map<String, Object> authenticationInfo = new HashMap<String, Object>();
resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(authenticationInfo);
Assert.assertNotNull(resourceResolver);
}
use of org.apache.sling.api.resource.ResourceResolver in project sling by apache.
the class MockedResourceResolverImplTest method testRelativeResource.
/**
* Test search paths
* @throws LoginException
*/
@Test
public void testRelativeResource() throws LoginException {
ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(null);
Assert.assertNotNull(resourceResolver);
Resource appResource = buildResource("/apps/store/inventory", EMPTY_RESOURCE_LIST, resourceResolver, appsResourceProvider);
Resource libResource = buildResource("/libs/store/catalog", EMPTY_RESOURCE_LIST, resourceResolver, appsResourceProvider);
Resource testResource = resourceResolver.getResource("store/inventory");
Assert.assertEquals(appResource, testResource);
testResource = resourceResolver.getResource("store/catalog");
Assert.assertEquals(libResource, testResource);
}
Aggregations