Search in sources :

Example 1 with MockRequestPathInfo

use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class AdaptiveImageServletTest method prepareRequestResponsePair.

private Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> prepareRequestResponsePair(String resourcePath, String selectorString, String extension) {
    final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(aemContext.resourceResolver(), aemContext.bundleContext());
    final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    Resource resource = resourceResolver.getResource(resourcePath);
    request.setResource(resource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSelectorString(selectorString);
    requestPathInfo.setExtension(extension);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(SlingBindings.RESPONSE, response);
    bindings.put(SlingBindings.SLING, aemContext.slingScriptHelper());
    bindings.put(SlingBindings.RESOLVER, resourceResolver);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return new Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse>() {

        @Override
        public MockSlingHttpServletRequest getLeft() {
            return request;
        }

        @Override
        public MockSlingHttpServletResponse getRight() {
            return response;
        }

        @Override
        public MockSlingHttpServletResponse setValue(MockSlingHttpServletResponse value) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Pair(org.apache.commons.lang3.tuple.Pair)

Example 2 with MockRequestPathInfo

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

the class GQLToQueryBuilderConverterTest method addPathFromSuffix.

@Test
public void addPathFromSuffix() {
    Map<String, String> map = new HashMap<>();
    MockSlingHttpServletRequest request = context.request();
    MockRequestPathInfo pathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    pathInfo.setSuffix("/foo");
    GQLToQueryBuilderConverter.addPath(request, map);
    assertThat(map, hasEntry("path", "/foo"));
    assertEquals(1, map.size());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) HashMap(java.util.HashMap) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Test(org.junit.Test)

Example 3 with MockRequestPathInfo

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

the class AssetsFolderPropertiesSupportTest method doGet.

@Test
public void doGet() throws Exception {
    final ValueMap graniteUiFormValues = new ValueMapDecorator(new HashMap<>());
    graniteUiFormValues.put("ootb", "ootb value");
    slingContext.create().resource("/content/dam/do-get/folder", ImmutableMap.<String, Object>builder().put("resource", "resource value").build());
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(slingContext.resourceResolver(), osgiContext.bundleContext());
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setResourcePath("wizard.html");
    requestPathInfo.setSuffix("/content/dam/do-get/folder");
    request.setAttribute("granite.ui.form.values", graniteUiFormValues);
    assetsFolderPropertiesSupport.doGet(request, response);
    ValueMap actual = (ValueMap) request.getAttribute("granite.ui.form.values");
    assertEquals("ootb value", actual.get("ootb", String.class));
    assertEquals("resource value", actual.get("resource", String.class));
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(com.adobe.cq.commerce.common.ValueMapDecorator) Test(org.junit.Test)

Example 4 with MockRequestPathInfo

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

the class ChecksumGeneratorServletTest method testWithNoPath.

@Test
public void testWithNoPath() throws Exception {
    ResourceResolver resourceResolver = MockSling.newResourceResolver(context.bundleContext());
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver, context.bundleContext());
    request.setResource(resourceResolver.getResource(SERVLET_PATH));
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSelectorString(SERVLET_SELECTORS);
    requestPathInfo.setExtension(SERVLET_EXTENSION);
    request.setMethod("GET");
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    servlet.doGet(request, response);
    assertEquals("text/plain;charset=UTF-8", response.getContentType());
    assertEquals("ERROR: At least one path must be specified", response.getOutputAsString());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Test(org.junit.Test)

Example 5 with MockRequestPathInfo

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

the class ExtensionlessRequestWrapperTest method getRequestPathInfo_NullExtension.

@Test
public void getRequestPathInfo_NullExtension() throws Exception {
    request.setResource(context.resourceResolver().getResource("/content/null-extension"));
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setExtension("xyz");
    ExtensionlessRequestWrapper wrapper = new ExtensionlessRequestWrapper(request);
    assertNull(wrapper.getRequestPathInfo().getExtension());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) Test(org.junit.Test)

Aggregations

MockRequestPathInfo (org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo)40 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)37 Test (org.junit.jupiter.api.Test)19 Test (org.junit.Test)16 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)14 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)11 AbstractImageTest (com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)8 Resource (org.apache.sling.api.resource.Resource)5 SlingBindings (org.apache.sling.api.scripting.SlingBindings)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Map (java.util.Map)4 PageImageThumbnail (com.adobe.cq.wcm.core.components.commons.editor.dialog.inherited.PageImageThumbnail)2 Page (com.day.cq.wcm.api.Page)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 ValueMapDecorator (com.adobe.cq.commerce.common.ValueMapDecorator)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashMap (java.util.HashMap)1 Pair (org.apache.commons.lang3.tuple.Pair)1 JSONObject (org.apache.sling.commons.json.JSONObject)1