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.");
}
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());
}
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);
}
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<>());
}
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<>());
}
Aggregations