SearchResultServlet extends SlingSafeMethodsServlet { @Override protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws IOException { Page currentPage = getCurrentPage(request); if (currentPage != null) { Resource searchResource = getSearchContentResource(request, currentPage); List<ListItem> results = getResults(request, searchResource, currentPage); writeJson(results, response); } }    }
@Test public void testSimpleSearch() throws Exception { com.adobe.cq.wcm.core.components.Utils.enableDataLayer(context, true); Resource resource = context.currentResource(TEST_ROOT_EN); when(mockHit.getResource()).thenReturn(resource); 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", "null/content/en/search/page.html", "title", "Page")); validateResponse(context.response(), expected); }
@Test public void testTemplateBasedSearch() throws Exception { com.adobe.cq.wcm.core.components.Utils.enableDataLayer(context, true); Resource resource = context.currentResource(TEST_TEMPLATE_EN); when(mockHit.getResource()).thenReturn(resource); 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", "null/content/en/search/page-template.html", "title", "Page")); validateResponse(context.response(), expected); }