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 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");
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class PageImageThumbnailTest method testPageImageThumbnailWithNonExistingResource.
@Test
void testPageImageThumbnailWithNonExistingResource() {
MockSlingHttpServletRequest request = context.request();
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix(RESOURCE1);
PageImageThumbnail pageImageThumbnail = request.adaptTo(PageImageThumbnail.class);
if (pageImageThumbnail != null) {
assertNull(pageImageThumbnail.getAlt(), "getAlt()");
assertNull(pageImageThumbnail.getSrc(), "getSrc()");
}
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class AssetsFolderPropertiesSupportTest method doGet.
@Test
public void doGet() throws Exception {
final ValueMap graniteUiFormValues = new ValueMapDecorator(new HashMap<>());
graniteUiFormValues.put("ootb", "ootb value");
slingContext.create().resource("/content/dam/do-get/folder", ImmutableMap.<String, Object>builder().put("resource", "resource value").build());
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(slingContext.resourceResolver(), osgiContext.bundleContext());
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setResourcePath("wizard.html");
requestPathInfo.setSuffix("/content/dam/do-get/folder");
request.setAttribute("granite.ui.form.values", graniteUiFormValues);
assetsFolderPropertiesSupport.doGet(request, response);
ValueMap actual = (ValueMap) request.getAttribute("granite.ui.form.values");
assertEquals("ootb value", actual.get("ootb", String.class));
assertEquals("resource value", actual.get("resource", String.class));
}
Aggregations