Search in sources :

Example 16 with MockSlingHttpServletRequest

use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.

the class JsonRendererServletTest method getJSON.

private String getJSON(String path, String depth) throws Throwable {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(path, depth, ".json", null, null);
    request.setMethod("GET");
    request.setResourceResolver(resolver);
    request.setResource(resolver.getResource(path));
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    JsonRendererServlet servlet = new JsonRendererServlet(1000);
    PrivateAccessor.invoke(servlet, "doGet", new Class[] { SlingHttpServletRequest.class, SlingHttpServletResponse.class }, new Object[] { request, response });
    return response.getOutput().toString();
}
Also used : JsonRendererServlet(org.apache.sling.servlets.get.impl.helpers.JsonRendererServlet) MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse)

Example 17 with MockSlingHttpServletRequest

use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.

the class RedirectServletTest method testEmptyPath.

public void testEmptyPath() {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/", null, null, null, null, "", TEST_SCHEME, TEST_HOST, TEST_PORT, "/webapp");
    request.setResourceResolver(new MockResourceResolver());
    String path = RedirectServlet.toRedirectPath("/index.html", request);
    assertEqualsUri("/webapp/index.html", path, false);
    request = new MockSlingHttpServletRequest("/", null, null, null, null, "/", TEST_SCHEME, TEST_HOST, TEST_PORT, "/webapp");
    request.setResourceResolver(new MockResourceResolver());
    path = RedirectServlet.toRedirectPath("/index.html", request);
    assertEqualsUri("/webapp/index.html", path, false);
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) MockResourceResolver(org.apache.sling.commons.testing.sling.MockResourceResolver)

Example 18 with MockSlingHttpServletRequest

use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.

the class NamedTransformImageServletTest method testAccepts_multipleTransforms.

@Test
public void testAccepts_multipleTransforms() throws Exception {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + NAMED_TRANSFORM_SMALL + "/image.png", "");
    final boolean result = servlet.accepts(request);
    assertTrue(result);
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) Test(org.junit.Test)

Example 19 with MockSlingHttpServletRequest

use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.

the class OptionsServletTest method testWithNoType.

@Test
public void testWithNoType() throws Exception {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/apps/acs-commons/components/utilities/designer/clientlibsmanager/options", null, "json", null, null);
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    servlet.doGet(request, response);
    assertEquals("application/json", response.getContentType());
    assertEquals("[]", response.getOutput().toString());
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse) Test(org.junit.Test)

Example 20 with MockSlingHttpServletRequest

use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.

the class OptionsServletTest method testWithNormalType.

@Test
public void testWithNormalType() throws Exception {
    Map<String, ClientLibrary> libraries = new HashMap<String, ClientLibrary>();
    String jsOnlyCategory1 = RandomStringUtils.randomAlphanumeric(5);
    String jsOnlyCategory2 = RandomStringUtils.randomAlphanumeric(5);
    String bothCategory1 = RandomStringUtils.randomAlphanumeric(5);
    String bothCategory2 = RandomStringUtils.randomAlphanumeric(5);
    addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js" }, new String[] { jsOnlyCategory1, jsOnlyCategory2 });
    addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js" }, new String[] { jsOnlyCategory2 });
    addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js", "css" }, new String[] { bothCategory1, bothCategory2 });
    addLibrary(libraries, RandomStringUtils.random(10), new String[] { "js", "css" }, new String[] { bothCategory2 });
    when(manager.getLibraries()).thenReturn(libraries);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/apps/acs-commons/components/utilities/designer/clientlibsmanager/options", "js", "json", null, null);
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    servlet.doGet(request, response);
    assertEquals("application/json", response.getContentType());
    JSONArray array = new JSONArray(response.getOutput().toString());
    assertEquals(4, array.length());
}
Also used : ClientLibrary(com.adobe.granite.ui.clientlibs.ClientLibrary) HashMap(java.util.HashMap) MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) JSONArray(org.apache.sling.commons.json.JSONArray) MockSlingHttpServletResponse(org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse) Test(org.junit.Test)

Aggregations

MockSlingHttpServletRequest (org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest)20 Test (org.junit.Test)10 MockSlingHttpServletResponse (org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse)6 Servlet (javax.servlet.Servlet)2 HttpServlet (javax.servlet.http.HttpServlet)2 OptingServlet (org.apache.sling.api.servlets.OptingServlet)2 MockResource (org.apache.sling.commons.testing.sling.MockResource)2 MockResourceResolver (org.apache.sling.commons.testing.sling.MockResourceResolver)2 ClientLibrary (com.adobe.granite.ui.clientlibs.ClientLibrary)1 HashMap (java.util.HashMap)1 Resource (org.apache.sling.api.resource.Resource)1 JSONArray (org.apache.sling.commons.json.JSONArray)1 JsonRendererServlet (org.apache.sling.servlets.get.impl.helpers.JsonRendererServlet)1 JSONResponse (org.apache.sling.servlets.post.JSONResponse)1 PostResponse (org.apache.sling.servlets.post.PostResponse)1 MockSlingHttpServlet3Request (org.apache.sling.servlets.post.impl.helper.MockSlingHttpServlet3Request)1 Before (org.junit.Before)1