use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method prepareRequestResponsePair.
private Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> prepareRequestResponsePair(String resourcePath, long lastModifiedDate, String selectorString, String requestExtension, String suffixExtension) {
final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
Resource resource = resourceResolver.getResource(resourcePath);
request.setResource(resource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix("/" + lastModifiedDate + "." + suffixExtension);
requestPathInfo.setSelectorString(selectorString);
requestPathInfo.setExtension(requestExtension);
requestPathInfo.setResourcePath(resourcePath);
request.setContextPath(CONTEXT_PATH);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.REQUEST, request);
bindings.put(SlingBindings.RESPONSE, response);
bindings.put(SlingBindings.SLING, context.slingScriptHelper());
bindings.put(SlingBindings.RESOLVER, resourceResolver);
request.setAttribute(SlingBindings.class.getName(), bindings);
return new RequestResponsePair(request, response);
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testImageFromTemplateStructureNodeOldLastModifiedInfo.
@Test
void testImageFromTemplateStructureNodeOldLastModifiedInfo() 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, "") + "/1490005238000.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");
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
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-cif-components by adobe.
the class ProductPageWithSkuAndUrlPathTest method testParseNoSuffix.
@Test
public void testParseNoSuffix() {
MockRequestPathInfo pathInfo = new MockRequestPathInfo();
pathInfo.setResourcePath("/page/path");
ProductUrlFormat.Params parameters = subject.parse(pathInfo, null);
assertEquals("/page/path", parameters.getPage());
assertNull(parameters.getSku());
assertNull(parameters.getUrlKey());
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-cif-components by adobe.
the class ProductPageWithSkuAndUrlPathTest method testParseSuffixOnlySku.
@Test
public void testParseSuffixOnlySku() {
MockRequestPathInfo pathInfo = new MockRequestPathInfo();
pathInfo.setResourcePath("/page/path");
pathInfo.setSuffix("/foo-bar.html");
ProductUrlFormat.Params parameters = subject.parse(pathInfo, null);
assertEquals("/page/path", parameters.getPage());
assertEquals("foo-bar", parameters.getSku());
assertNull(parameters.getUrlKey());
assertNull(parameters.getUrlPath());
}
Aggregations