use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.
the class CustomComponentActivatorListServletTest method testDefault.
@Test
public void testDefault() throws Exception {
CustomComponentActivatorListServlet servlet = new CustomComponentActivatorListServlet();
servlet.activate(Collections.emptyMap());
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(null, null, null, null, null);
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
servlet.doGet(request, response);
String result = response.getOutput().toString();
JSONAssert.assertEquals(DEFAULT_RESULT, result, JSONCompareMode.NON_EXTENSIBLE);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project acs-aem-commons by Adobe-Consulting-Services.
the class OptionsServletTest method testWithBadType.
@Test
public void testWithBadType() throws Exception {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/apps/acs-commons/components/utilities/designer/clientlibsmanager/options", "html", "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 sling by apache.
the class MediaRangeListTest method testInvalidJdkAcceptHeader.
public void testInvalidJdkAcceptHeader() {
//This header is sent by Java client which make use of URLConnection on Oracle JDK
//See acceptHeader at http://hg.openjdk.java.net/jdk6/jdk6-gate/jdk/file/tip/src/share/classes/sun/net/www/protocol/http/HttpURLConnection.java
//To support such case the MediaRange parser has to be made bit linient
final String invalidHeader = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
MockSlingHttpServletRequest req = new MockSlingHttpServlet3Request(null, null, null, null, null) {
@Override
public String getHeader(String name) {
return name.equals(MediaRangeList.HEADER_ACCEPT) ? invalidHeader : super.getHeader(name);
}
public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
return null;
}
};
MediaRangeList rangeList = new MediaRangeList(req);
assertTrue("Did not contain media type from query param", rangeList.contains("text/html"));
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class SlingServletResolverTest method testIgnoreRequest.
@Test
public void testIgnoreRequest() {
MockSlingHttpServletRequest insecureRequest = new MockSlingHttpServletRequest(SERVLET_PATH, null, SERVLET_EXTENSION, null, null);
insecureRequest.setResourceResolver(mockResourceResolver);
insecureRequest.setSecure(false);
Servlet result = servletResolver.resolveServlet(insecureRequest);
assertTrue("Did not ignore unwanted request", result.getClass() != MockSlingRequestHandlerServlet.class);
}
use of org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest in project sling by apache.
the class RequestUtilTest method getMockRequest.
protected SlingHttpServletRequest getMockRequest(final long modificationTime, final long ifModifiedSince) {
final String resourcePath = "foo";
final MockSlingHttpServletRequest r = new MockSlingHttpServletRequest(resourcePath, null, null, null, null) {
@Override
public long getDateHeader(String name) {
return ifModifiedSince;
}
};
final String path = "/foo/node";
final MockResource mr = new MockResource(null, path, null) {
};
mr.getResourceMetadata().setModificationTime(modificationTime);
r.setResource(mr);
return r;
}
Aggregations