Search in sources :

Example 11 with MockSlingHttpServletRequest

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);
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse) Test(org.junit.Test)

Example 12 with MockSlingHttpServletRequest

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());
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.commons.testing.sling.MockSlingHttpServletResponse) Test(org.junit.Test)

Example 13 with MockSlingHttpServletRequest

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"));
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest)

Example 14 with MockSlingHttpServletRequest

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);
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) HttpServlet(javax.servlet.http.HttpServlet) Servlet(javax.servlet.Servlet) OptingServlet(org.apache.sling.api.servlets.OptingServlet) Test(org.junit.Test)

Example 15 with MockSlingHttpServletRequest

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;
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) MockResource(org.apache.sling.commons.testing.sling.MockResource)

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