Search in sources :

Example 26 with MockRequestPathInfo

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

the class PageImageThumbnailTest method testPageImageThumbnailWithNonExistingResource.

@Test
void testPageImageThumbnailWithNonExistingResource() {
    MockSlingHttpServletRequest request = context.request();
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix(RESOURCE1);
    PageImageThumbnail pageImageThumbnail = request.adaptTo(PageImageThumbnail.class);
    if (pageImageThumbnail != null) {
        assertNull(pageImageThumbnail.getAlt(), "getAlt()");
        assertNull(pageImageThumbnail.getSrc(), "getSrc()");
    }
}
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 27 with MockRequestPathInfo

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

the class AdaptiveImageServletTest method testImageWithMissingLastModifiedSuffix.

@Test
void testImageWithMissingLastModifiedSuffix() throws Exception {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE19_PATH, "coreimg.800", "png");
    MockSlingHttpServletRequest request = requestResponsePair.getLeft();
    MockSlingHttpServletResponse response = requestResponsePair.getRight();
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("");
    servlet.doGet(request, response);
    Assertions.assertEquals(302, response.getStatus(), "Expected a 302 response code.");
    Assertions.assertEquals(CONTEXT_PATH + "/content/test/jcr%3acontent/root/image19.coreimg.800.png/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 28 with MockRequestPathInfo

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

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 29 with MockRequestPathInfo

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

the class AdaptiveImageServletTest method testInvalidSuffix.

@Test
void testInvalidSuffix() throws IOException {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE3_PATH, "img.600", "png");
    MockSlingHttpServletRequest request = requestResponsePair.getLeft();
    MockRequestPathInfo rpi = (MockRequestPathInfo) request.getRequestPathInfo();
    rpi.setSuffix("/random");
    MockSlingHttpServletResponse response = requestResponsePair.getRight();
    servlet.doGet(request, response);
    Assertions.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
    rpi.setSuffix("/1");
    servlet.doGet(request, response);
    Assertions.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
    rpi.setSuffix("/1.");
    servlet.doGet(request, response);
    Assertions.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatus());
}
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 30 with MockRequestPathInfo

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

the class AdaptiveImageServletTest method testWithNoImageNameFromTemplate.

@Test
void testWithNoImageNameFromTemplate() 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, "") + "/1490005239000.png");
    servlet.doGet(request, response);
    Assertions.assertEquals(200, response.getStatus(), "Expected a 200 response code.");
}
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)

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