Search in sources :

Example 56 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, long lastModifiedDate, String selectorString, String requestExtension, String suffixExtension) {
    final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
    final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    Resource resource = resourceResolver.getResource(resourcePath);
    request.setResource(resource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("/" + lastModifiedDate + "." + suffixExtension);
    requestPathInfo.setSelectorString(selectorString);
    requestPathInfo.setExtension(requestExtension);
    requestPathInfo.setResourcePath(resourcePath);
    request.setContextPath(CONTEXT_PATH);
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(SlingBindings.RESPONSE, response);
    bindings.put(SlingBindings.SLING, context.slingScriptHelper());
    bindings.put(SlingBindings.RESOLVER, resourceResolver);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    return new RequestResponsePair(request, response);
}
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)

Example 57 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 testImageFromTemplateStructureNodeOldLastModifiedInfo.

@Test
void testImageFromTemplateStructureNodeOldLastModifiedInfo() throws IOException {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(PAGE, "coreimg", "png");
    MockSlingHttpServletRequest request = requestResponsePair.getLeft();
    MockSlingHttpServletResponse response = requestResponsePair.getRight();
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix(TEMPLATE_IMAGE_PATH.replace(TEMPLATE_PATH, "") + "/1490005238000.png");
    servlet.doGet(request, response);
    Assertions.assertEquals(302, response.getStatus(), "Expected a 302 response code.");
    Assertions.assertEquals(CONTEXT_PATH + "/content/test.coreimg.png/structure/jcr%3acontent/root/image_template/1490005239000.png", response.getHeader("Location"), "Expected redirect location with correct last modified suffix");
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Test(org.junit.jupiter.api.Test) AbstractImageTest(com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)

Example 58 with MockRequestPathInfo

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

the class SocialMediaHelperImplTest method getSocialMediaHelperUnderTest.

private SocialMediaHelper getSocialMediaHelperUnderTest(String pagePath) {
    Resource currentResource = CONTEXT.resourceResolver().getResource(pagePath);
    Page currentPage = currentResource.adaptTo(Page.class);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
    MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
    request.setContextPath(CONTEXT_PATH);
    request.setResource(currentResource);
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setExtension(EXTENSION);
    requestPathInfo.setResourcePath(currentResource.getPath());
    SlingBindings slingBindings = new SlingBindings();
    slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
    slingBindings.put(SlingBindings.RESOLVER, CONTEXT.resourceResolver());
    slingBindings.put(SlingBindings.RESPONSE, response);
    request.setAttribute(SlingBindings.class.getName(), slingBindings);
    return request.adaptTo(SocialMediaHelper.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) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Page(com.day.cq.wcm.api.Page)

Example 59 with MockRequestPathInfo

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

the class ProductPageWithSkuAndUrlPathTest method testParseNoSuffix.

@Test
public void testParseNoSuffix() {
    MockRequestPathInfo pathInfo = new MockRequestPathInfo();
    pathInfo.setResourcePath("/page/path");
    ProductUrlFormat.Params parameters = subject.parse(pathInfo, null);
    assertEquals("/page/path", parameters.getPage());
    assertNull(parameters.getSku());
    assertNull(parameters.getUrlKey());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) ProductUrlFormat(com.adobe.cq.commerce.core.components.services.urls.ProductUrlFormat) Test(org.junit.Test)

Example 60 with MockRequestPathInfo

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

the class ProductPageWithSkuAndUrlPathTest method testParseSuffixOnlySku.

@Test
public void testParseSuffixOnlySku() {
    MockRequestPathInfo pathInfo = new MockRequestPathInfo();
    pathInfo.setResourcePath("/page/path");
    pathInfo.setSuffix("/foo-bar.html");
    ProductUrlFormat.Params parameters = subject.parse(pathInfo, null);
    assertEquals("/page/path", parameters.getPage());
    assertEquals("foo-bar", parameters.getSku());
    assertNull(parameters.getUrlKey());
    assertNull(parameters.getUrlPath());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) ProductUrlFormat(com.adobe.cq.commerce.core.components.services.urls.ProductUrlFormat) Test(org.junit.Test)

Aggregations

MockRequestPathInfo (org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo)93 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)61 Test (org.junit.Test)45 Test (org.junit.jupiter.api.Test)38 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)25 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