@Test public void doAction_textPresent() throws AecuException, IOException { actionSpy.doAction(resource); }
@Override public String doAction(Resource resource) throws PersistenceException, AecuException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { throw new AecuException("Unable to find a page for resource " + resource.getPath()); } String successMessage = "Correct page rendering for " + page.getPath(); RequestResponseFactory requestResponseFactory = context.getRequestResponseFactory(); SlingRequestProcessor requestProcessor = context.getSlingRequestProcessor(); String requestPath = page.getPath() + ".html"; HttpServletRequest req = requestResponseFactory.createRequest(HttpConstants.METHOD_GET, requestPath); WCMMode.DISABLED.toRequest(req); MockHttpServletResponse resp = createResponse(); try { requestProcessor.processRequest(req, resp, context.getResolver()); if (resp.getStatus() != statusCode) { throw new AecuException(requestPath + " returned " + resp.getStatus() + " instead of " + statusCode); } String html = resp.getOutput().toString(); if (StringUtils.isNotBlank(textPresent) && !html.contains(textPresent)) { throw new AecuException(requestPath + " did not include " + textPresent); } if (StringUtils.isNotBlank(textNotPresent) && html.contains(textNotPresent)) { throw new AecuException(requestPath + " did include " + textNotPresent); } } catch (ServletException | IOException e) { throw new PersistenceException("Unable to render " + requestPath); } return successMessage; }
RenderPageAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException, AecuException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { throw new AecuException("Unable to find a page for resource " + resource.getPath()); } String successMessage = "Correct page rendering for " + page.getPath(); RequestResponseFactory requestResponseFactory = context.getRequestResponseFactory(); SlingRequestProcessor requestProcessor = context.getSlingRequestProcessor(); String requestPath = page.getPath() + ".html"; HttpServletRequest req = requestResponseFactory.createRequest(HttpConstants.METHOD_GET, requestPath); WCMMode.DISABLED.toRequest(req); MockHttpServletResponse resp = createResponse(); try { requestProcessor.processRequest(req, resp, context.getResolver()); if (resp.getStatus() != statusCode) { throw new AecuException(requestPath + " returned " + resp.getStatus() + " instead of " + statusCode); } String html = resp.getOutput().toString(); if (StringUtils.isNotBlank(textPresent) && !html.contains(textPresent)) { throw new AecuException(requestPath + " did not include " + textPresent); } if (StringUtils.isNotBlank(textNotPresent) && html.contains(textNotPresent)) { throw new AecuException(requestPath + " did include " + textNotPresent); } } catch (ServletException | IOException e) { throw new PersistenceException("Unable to render " + requestPath); } return successMessage; } }
RenderPageAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException, AecuException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { throw new AecuException("Unable to find a page for resource " + resource.getPath()); } String successMessage = "Correct page rendering for " + page.getPath(); RequestResponseFactory requestResponseFactory = context.getRequestResponseFactory(); SlingRequestProcessor requestProcessor = context.getSlingRequestProcessor(); String requestPath = page.getPath() + ".html"; HttpServletRequest req = requestResponseFactory.createRequest(HttpConstants.METHOD_GET, requestPath); WCMMode.DISABLED.toRequest(req); MockHttpServletResponse resp = createResponse(); try { requestProcessor.processRequest(req, resp, context.getResolver()); if (resp.getStatus() != statusCode) { throw new AecuException(requestPath + " returned " + resp.getStatus() + " instead of " + statusCode); } String html = resp.getOutput().toString(); if (StringUtils.isNotBlank(textPresent) && !html.contains(textPresent)) { throw new AecuException(requestPath + " did not include " + textPresent); } if (StringUtils.isNotBlank(textNotPresent) && html.contains(textNotPresent)) { throw new AecuException(requestPath + " did include " + textNotPresent); } } catch (ServletException | IOException e) { throw new PersistenceException("Unable to render " + requestPath); } return successMessage; } RenderPageAction(BindingContext context, int statusCode, String textPresent, String textNotPresent); }
RenderPageAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException, AecuException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { throw new AecuException("Unable to find a page for resource " + resource.getPath()); } String successMessage = "Correct page rendering for " + page.getPath(); RequestResponseFactory requestResponseFactory = context.getRequestResponseFactory(); SlingRequestProcessor requestProcessor = context.getSlingRequestProcessor(); String requestPath = page.getPath() + ".html"; HttpServletRequest req = requestResponseFactory.createRequest(HttpConstants.METHOD_GET, requestPath); WCMMode.DISABLED.toRequest(req); MockHttpServletResponse resp = createResponse(); try { requestProcessor.processRequest(req, resp, context.getResolver()); if (resp.getStatus() != statusCode) { throw new AecuException(requestPath + " returned " + resp.getStatus() + " instead of " + statusCode); } String html = resp.getOutput().toString(); if (StringUtils.isNotBlank(textPresent) && !html.contains(textPresent)) { throw new AecuException(requestPath + " did not include " + textPresent); } if (StringUtils.isNotBlank(textNotPresent) && html.contains(textNotPresent)) { throw new AecuException(requestPath + " did include " + textNotPresent); } } catch (ServletException | IOException e) { throw new PersistenceException("Unable to render " + requestPath); } return successMessage; } RenderPageAction(BindingContext context, int statusCode, String textPresent, String textNotPresent); @Override String doAction(Resource resource); }
RenderPageAction implements Action { @Override public String doAction(Resource resource) throws PersistenceException, AecuException { Page page = context.getPageManager().getContainingPage(resource); if (page == null) { throw new AecuException("Unable to find a page for resource " + resource.getPath()); } String successMessage = "Correct page rendering for " + page.getPath(); RequestResponseFactory requestResponseFactory = context.getRequestResponseFactory(); SlingRequestProcessor requestProcessor = context.getSlingRequestProcessor(); String requestPath = page.getPath() + ".html"; HttpServletRequest req = requestResponseFactory.createRequest(HttpConstants.METHOD_GET, requestPath); WCMMode.DISABLED.toRequest(req); MockHttpServletResponse resp = createResponse(); try { requestProcessor.processRequest(req, resp, context.getResolver()); if (resp.getStatus() != statusCode) { throw new AecuException(requestPath + " returned " + resp.getStatus() + " instead of " + statusCode); } String html = resp.getOutput().toString(); if (StringUtils.isNotBlank(textPresent) && !html.contains(textPresent)) { throw new AecuException(requestPath + " did not include " + textPresent); } if (StringUtils.isNotBlank(textNotPresent) && html.contains(textNotPresent)) { throw new AecuException(requestPath + " did include " + textNotPresent); } } catch (ServletException | IOException e) { throw new PersistenceException("Unable to render " + requestPath); } return successMessage; } RenderPageAction(BindingContext context, int statusCode, String textPresent, String textNotPresent); @Override String doAction(Resource resource);  }