use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
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);
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
the class SearchResultServletTest method testXFTemplateSearch.
@Test
public void testXFTemplateSearch() throws Exception {
setUpQueryBuilder();
com.adobe.cq.wcm.core.components.Utils.enableDataLayer(context, true);
context.currentResource(TEST_XF_TEMPLATE_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.
@Test
public void testSimpleSearch() throws Exception {
setUpQueryBuilder();
com.adobe.cq.wcm.core.components.Utils.enableDataLayer(context, true);
context.currentResource(TEST_ROOT_EN);
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());
List<Map<String, String>> expected = ImmutableList.of(ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/page.html", "title", "Page", "id", "search-0dc87a6d22-item-2290228025"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/page2.html", "title", "Page2", "id", "search-0dc87a6d22-item-ad3d190367"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/page-template.html", "title", "Page3", "id", "search-0dc87a6d22-item-1abc47fffe"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/xf-page.html", "title", "XF Page", "id", "search-0dc87a6d22-item-2246ed81a7"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/xf-page-template.html", "title", "XF Page Template", "id", "search-0dc87a6d22-item-7345474d48"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search.html", "title", "Search", "id", "search-0dc87a6d22-item-04a609b18b"));
validateResponse(context.response(), expected);
verify(this.spyResolver, atLeastOnce()).close();
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
the class AdaptiveImageServletTest method testWithNoImageNameResourceTypeImage.
@Test
void testWithNoImageNameResourceTypeImage() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE26_PATH, "coreimg.800", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
context.contentPolicyMapping(ImageImpl.RESOURCE_TYPE, "allowedRenditionWidths", new String[] { "800" });
requestPathInfo.setSuffix("/1494867377756.png");
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
Assertions.assertEquals(200, response.getStatus(), "Expected a 200 response code.");
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
the class AdaptiveImageServletTest method testImageFromTemplateStructureNodeNoLastModifiedInfo.
@Test
void testImageFromTemplateStructureNodeNoLastModifiedInfo() 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, "") + ".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");
}
Aggregations