Search in sources :

Example 31 with MockRequestPathInfo

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

the class AdaptiveImageServletTest method testImageFromTemplateStructureNode.

@Test
void testImageFromTemplateStructureNode() throws IOException {
    Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(PAGE, "img", "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.");
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(response.getOutput());
    BufferedImage image = ImageIO.read(byteArrayInputStream);
    Dimension expectedDimension = new Dimension(ADAPTIVE_IMAGE_SERVLET_DEFAULT_RESIZE_WIDTH, ADAPTIVE_IMAGE_SERVLET_DEFAULT_RESIZE_WIDTH);
    Dimension actualDimension = new Dimension(image.getWidth(), image.getHeight());
    Assertions.assertEquals(expectedDimension, actualDimension, "Expected image rendered at requested size.");
    Assertions.assertEquals("image/png", response.getContentType(), "Expected a PNG image.");
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.jupiter.api.Test) AbstractImageTest(com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)

Example 32 with MockRequestPathInfo

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

the class DownloadServletTest method tesNotModifiedResponseForResource.

@Test
void tesNotModifiedResponseForResource() throws Exception {
    MockSlingHttpServletRequest request = context.request();
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("Download_Test_PDF.pdf");
    context.currentResource(PDF_FILE_PATH + "/file");
    request.setHeader("If-Modified-Since", "Fri, 19 Oct 2018 19:24:07 GMT");
    downloadServlet.doGet(request, context.response());
    assertEquals(304, context.response().getStatus());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 33 with MockRequestPathInfo

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

the class SearchResultServletTest method testXFSearch.

@Test
public void testXFSearch() throws Exception {
    setUpQueryBuilder();
    com.adobe.cq.wcm.core.components.Utils.enableDataLayer(context, true);
    context.currentResource(TEST_XF_PAGE_EN);
    MockSlingHttpServletRequest request = context.request();
    request.setQueryString(SearchResultServlet.PARAM_FULLTEXT + "=found");
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("jcr:content/search");
    underTest.doGet(request, context.response());
    List<Map<String, String>> expected = ImmutableList.of(ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/xf-page/searched-tree/found-01.html", "title", "Found 01", "id", "search-1f0d0a33b1-item-7ae4fa6340"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/xf-page/searched-tree/found-02.html", "title", "Found 02", "id", "search-1f0d0a33b1-item-05b6f78858"));
    validateResponse(context.response(), expected);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.jupiter.api.Test)

Example 34 with MockRequestPathInfo

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

the class SearchResultServletTest method testSimpleSearch_tooShortQuery.

@Test
public void testSimpleSearch_tooShortQuery() throws Exception {
    context.currentResource(TEST_ROOT_EN);
    MockSlingHttpServletRequest request = context.request();
    request.setQueryString(SearchResultServlet.PARAM_FULLTEXT + "=yo");
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("jcr:content/search");
    underTest.doGet(request, context.response());
    validateResponse(context.response(), new ArrayList<>());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Test(org.junit.jupiter.api.Test)

Example 35 with MockRequestPathInfo

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

the class SearchResultServletTest method testSimpleSearch_noPath.

@Test
public void testSimpleSearch_noPath() throws Exception {
    setUpQueryBuilder();
    context.currentResource(TEST_ROOT_DE);
    MockSlingHttpServletRequest request = context.request();
    request.setQueryString(SearchResultServlet.PARAM_FULLTEXT + "=yod");
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
    requestPathInfo.setSuffix("jcr:content/search");
    underTest.doGet(request, context.response());
    validateResponse(context.response(), new ArrayList<>());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Test(org.junit.jupiter.api.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