Search in sources :

Example 1 with MockSlingHttpServletRequest

use of 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);
    return result;
Also used : MockSlingHttpServletRequest(

Example 2 with MockSlingHttpServletRequest

use of 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");
    // 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);
Also used : MockSlingHttpServletRequest( MockResource( Resource( MockResource(

Example 3 with MockSlingHttpServletRequest

use of 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);
Also used : MockSlingHttpServletRequest( MockResourceResolver(

Example 4 with MockSlingHttpServletRequest

use of in project sling by apache.

the class SlingServletResolverTest method testAcceptsRequest.

public void testAcceptsRequest() {
    MockSlingHttpServletRequest secureRequest = new MockSlingHttpServletRequest(SERVLET_PATH, null, SERVLET_EXTENSION, null, null);
    Servlet result = servletResolver.resolveServlet(secureRequest);
    assertEquals("Did not resolve to correct servlet", servlet, result);
Also used : MockSlingHttpServletRequest( HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) OptingServlet( Test(org.junit.Test)

Example 5 with MockSlingHttpServletRequest

use of in project sling by apache.

the class SlingPostServletTest method testGetJsonResponse.

public void testGetJsonResponse() {
    MockSlingHttpServletRequest req = new MockSlingHttpServlet3Request(null, null, null, null, null) {

        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);
Also used : MockSlingHttpServlet3Request( MockSlingHttpServletRequest( JSONResponse( PostResponse(


MockSlingHttpServletRequest ( Test (org.junit.Test)10 MockSlingHttpServletResponse ( Servlet (javax.servlet.Servlet)2 HttpServlet (javax.servlet.http.HttpServlet)2 OptingServlet ( MockResource ( MockResourceResolver ( ClientLibrary (com.adobe.granite.ui.clientlibs.ClientLibrary)1 HashMap (java.util.HashMap)1 Resource ( JSONArray ( JsonRendererServlet ( JSONResponse ( PostResponse ( MockSlingHttpServlet3Request ( Before (org.junit.Before)1