Search in sources :

Example 6 with MockSlingHttpServletRequest

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

the class MediaRangeListTest method testHttpEquivParam.

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

        @Override
        public String getHeader(String name) {
            return name.equals(MediaRangeList.HEADER_ACCEPT) ? "text/plain" : super.getHeader(name);
        }

        @Override
        public String getParameter(String name) {
            return name.equals(MediaRangeList.PARAM_ACCEPT) ? "text/html" : super.getParameter(name);
        }

        @Override
        public Enumeration<String> getHeaderNames() {
            return null;
        }

        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"));
    assertFalse("Contained media type from overridden Accept header", rangeList.contains("text/plain"));
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest)

Example 7 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_invalidLastSuffix.

@Test
public void testAccepts_invalidLastSuffix() throws Exception {
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest("/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + new Random().nextInt() + "/foo", "");
    final boolean result = servlet.accepts(request);
    assertFalse(result);
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) Test(org.junit.Test)

Example 8 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_invalidNamedTransform.

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

Example 9 with MockSlingHttpServletRequest

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

the class NamedTransformImageServletTest method setUp.

@Before
public void setUp() throws Exception {
    servlet = new NamedTransformImageServlet();
    imageTransformers.put(IMAGE_TRANSFORM_RESIZE, resizeImageTransformer);
    imageTransformers.put(IMAGE_TRANSFORM_GREYSCALE, greyscaleImageTransformer);
    namedImageTransformers.put(NAMED_TRANSFORM_FEATURE, featureImageTransformer);
    namedImageTransformers.put(NAMED_TRANSFORM_SMALL, smallImageTransformer);
    mockRequest = new MockSlingHttpServletRequest("/path", "", "transform", NAMED_TRANSFORM_FEATURE + "/" + new Random().nextInt() + "/image.png", "");
    MockitoAnnotations.initMocks(this);
}
Also used : MockSlingHttpServletRequest(org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest) Before(org.junit.Before)

Example 10 with MockSlingHttpServletRequest

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

the class CustomComponentActivatorListServletTest method testCustom.

@Test
public void testCustom() throws Exception {
    CustomComponentActivatorListServlet servlet = new CustomComponentActivatorListServlet();
    servlet.activate(Collections.singletonMap("components", new String[] { "test=my/test/component" }));
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(null, null, null, null, null);
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    servlet.doGet(request, response);
    String result = response.getOutput().toString();
    JSONAssert.assertEquals("{\"components\":[{\"propertyName\":\"test\",\"componentPath\":\"my/test/component\"}]}", 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)

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