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