use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SearchResultServletTest method testTemplateBasedSearch.
@Test
public void testTemplateBasedSearch() throws Exception {
setUpQueryBuilder();
com.adobe.cq.wcm.core.components.Utils.enableDataLayer(context, true);
context.currentResource(TEST_TEMPLATE_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-ea349504cd-item-2290228025"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/page2.html", "title", "Page2", "id", "search-ea349504cd-item-ad3d190367"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/page-template.html", "title", "Page3", "id", "search-ea349504cd-item-1abc47fffe"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/xf-page.html", "title", "XF Page", "id", "search-ea349504cd-item-2246ed81a7"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search/xf-page-template.html", "title", "XF Page Template", "id", "search-ea349504cd-item-7345474d48"), ImmutableMap.of("url", CONTEXT_PATH + "/content/en/search.html", "title", "Search", "id", "search-ea349504cd-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-Marketing-Cloud.
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<>());
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
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-Marketing-Cloud.
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.");
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
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());
}
Aggregations