Search in sources :

Example 21 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_HasExtension.

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

Example 22 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)

Example 23 with MockRequestPathInfo

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

the class QrCodeServletTest method doGet.

@Test
public void doGet() throws Exception {
    request.setResource(requestResource);
    when(externalizer.publishLink(request.getResourceResolver(), "/content/externalize-me.html")).thenReturn("http://www.example.com/content/externalize-me.html");
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("/content/externalize-me.html");
    // requestPathInfo.setExtension("json");
    qrCodeServlet.doGet(request, response);
    JSONObject actual = new JSONObject(response.getOutputAsString());
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    assertEquals(true, actual.getBoolean("enabled"));
    assertEquals("http://www.example.com/content/externalize-me.html", actual.getString("publishURL"));
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) JSONObject(org.apache.sling.commons.json.JSONObject) Test(org.junit.Test)

Example 24 with MockRequestPathInfo

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

the class PageImageThumbnailTest method testPageImageThumbnailWithSuffix.

@Test
void testPageImageThumbnailWithSuffix() {
    context.currentResource(RESOURCE);
    MockSlingHttpServletRequest request = context.request();
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix(RESOURCE);
    requestPathInfo.setResourcePath(RESOURCE);
    PageImageThumbnail pageImageThumbnail = request.adaptTo(PageImageThumbnail.class);
    if (pageImageThumbnail != null) {
        assertEquals("featured image alt", pageImageThumbnail.getAlt(), "getAlt()");
        assertEquals("/content/page/_jcr_content/_cq_featuredimage.coreimg.png", pageImageThumbnail.getSrc(), "getSrc()");
        assertEquals("/content/page/jcr:content/root/responsivegrid/image", pageImageThumbnail.getComponentPath(), "getComponentPath()");
        assertEquals("/content/page/jcr:content/root/responsivegrid/image", pageImageThumbnail.getConfigPath(), "getConfigPath()");
        assertEquals("/content/page", pageImageThumbnail.getCurrentPagePath(), "getCurrentPagePath()");
    } else {
        fail("can't create page image thumnbail model");
    }
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) PageImageThumbnail(com.adobe.cq.wcm.core.components.commons.editor.dialog.inherited.PageImageThumbnail) Test(org.junit.jupiter.api.Test)

Example 25 with MockRequestPathInfo

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

the class EditorTest method getItemsEditor.

private Editor getItemsEditor(String suffix) {
    // get the carousel component node resource
    Resource resource = context.resourceResolver().getResource(CAROUSEL_PATH);
    // prepare the request object
    final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
    // set the suffix
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix(suffix);
    // define the bindings
    SlingBindings slingBindings = new SlingBindings();
    slingBindings.put(SlingBindings.RESOURCE, resource);
    if (resource != null) {
        slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    }
    slingBindings.put(WCMBindings.PAGE_MANAGER, context.pageManager());
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    // adapt to the class to test
    return request.adaptTo(Editor.class);
}
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) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource)

Aggregations

MockRequestPathInfo (org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo)91 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)59 Test (org.junit.Test)45 Test (org.junit.jupiter.api.Test)38 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)24 ProductUrlFormat (com.adobe.cq.commerce.core.components.services.urls.ProductUrlFormat)23 AbstractImageTest (com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)16 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 Map (java.util.Map)8 Resource (org.apache.sling.api.resource.Resource)8 SlingBindings (org.apache.sling.api.scripting.SlingBindings)8 CategoryUrlFormat (com.adobe.cq.commerce.core.components.services.urls.CategoryUrlFormat)4 PageImageThumbnail (com.adobe.cq.wcm.core.components.commons.editor.dialog.inherited.PageImageThumbnail)4 Page (com.day.cq.wcm.api.Page)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 CloudConfigurationList (com.adobe.acs.commons.cloudconfig.CloudConfigurationList)2 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CloudConfiguration (com.adobe.acs.commons.cloudconfig.CloudConfiguration)1