use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class HelperTestBase method makeRequest.
protected MockSlingHttpServletRequest makeRequest(String method, String selectors, String extension) {
final MockSlingHttpServletRequest result = new MockSlingHttpServletRequest(resourcePath, selectors, extension, null, null);
result.setMethod(method);
result.setResourceResolver(resourceResolver);
result.setResource(resource);
return result;
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class ScriptSelectionTest method assertScript.
/** Given a list of available scripts and the request method, selectors
* and extension, check that the expected script is selected.
* The resource type is foo:bar, set by HelperTestBase
*
* @param method the HTTP method of the simulated request
* @param selectors the selectors of the simulated request
* @param extension the extension of the simulated request
* @param scripts the list of scripts that would be available in the repository
* @param expectedScript the script that we expect to be selected
*/
protected void assertScript(String method, String selectors, String extension, String[] scripts, String expectedScript) {
// Add given scripts to our mock resource resolver
for (String script : scripts) {
final MockResource r = new MockResource(resourceResolver, script, "nt:file");
resourceResolver.addResource(r);
}
// Create mock request and get scripts from ResourceCollector
final MockSlingHttpServletRequest req = makeRequest(method, selectors, extension);
final ResourceCollector u = ResourceCollector.create(req, null, new String[] { "html" });
final Collection<Resource> s = u.getServlets(req.getResourceResolver());
if (expectedScript == null) {
assertFalse("No script must be found", s.iterator().hasNext());
} else {
// Verify that the expected script is the first in the list of candidates
assertTrue("A script must be found", s.iterator().hasNext());
final String scriptPath = s.iterator().next().getPath();
assertEquals("First script is the expected one", expectedScript, scriptPath);
}
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class RedirectServletTest method toRedirect.
private static String toRedirect(String basePath, String selectors, String extension, String suffix, String queryString, String targetPath) {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(basePath, selectors, extension, suffix, queryString, basePath, TEST_SCHEME, TEST_HOST, TEST_PORT, "");
request.setResourceResolver(new MockResourceResolver());
return RedirectServlet.toRedirectPath(targetPath, request);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class SlingServletResolverTest method testAcceptsRequest.
@Test
public void testAcceptsRequest() {
MockSlingHttpServletRequest secureRequest = new MockSlingHttpServletRequest(SERVLET_PATH, null, SERVLET_EXTENSION, null, null);
secureRequest.setResourceResolver(mockResourceResolver);
secureRequest.setSecure(true);
Servlet result = servletResolver.resolveServlet(secureRequest);
assertEquals("Did not resolve to correct servlet", servlet, result);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class SlingPostServletTest method testGetJsonResponse.
public void testGetJsonResponse() {
MockSlingHttpServletRequest req = new MockSlingHttpServlet3Request(null, null, null, null, null) {
@Override
public String getHeader(String name) {
return name.equals(MediaRangeList.HEADER_ACCEPT) ? "application/json" : super.getHeader(name);
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
return null;
}
};
PostResponse result = servlet.createPostResponse(req);
assertTrue(result instanceof JSONResponse);
}
Aggregations