use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class HiddenImplTest method prepareHiddenFieldForTest.
private Field prepareHiddenFieldForTest(String resourcePath) {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
request.setResource(resource);
Page currentPage = CONTEXT.pageManager().getPage(CONTAINING_PAGE);
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(SlingBindings.RESOURCE, resource);
slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(Field.class);
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ContainerImplTest method testFormWithCustomAttributesAndFields.
@Test
public void testFormWithCustomAttributesAndFields() {
Resource resource = context.currentResource(FORM1_PATH);
when(formStructureHelperFactory.getFormStructureHelper(resource)).thenReturn(formStructureHelper);
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
slingBindings.put(RESOURCE_PROPERTY, resource);
MockSlingHttpServletRequest request = context.request();
request.setRequestDispatcherFactory(requestDispatcherFactory);
when(requestDispatcherFactory.getRequestDispatcher((Resource) any(), (RequestDispatcherOptions) any())).thenReturn(requestDispatcher);
Container container = request.adaptTo(Container.class);
assertEquals("my-id", container.getId());
assertEquals("my-id", container.getName());
assertEquals("application/x-www-form-urlencoded", container.getEnctype());
assertEquals("GET", container.getMethod());
assertEquals(CONTAINING_PAGE + ".html", container.getAction());
assertEquals("core/wcm/components/form/container/v1/container/new", container.getResourceTypeForDropArea());
assertEquals("/content/we-retail/home", container.getRedirect());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testGIFUploadedToDAM.
@Test
public void testGIFUploadedToDAM() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE6_PATH, "img", "gif");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
servlet.doGet(request, response);
ByteArrayInputStream stream = new ByteArrayInputStream(response.getOutput());
InputStream directStream = this.getClass().getClassLoader().getResourceAsStream("image/Adobe_Systems_logo_and_wordmark.svg.gif");
assertTrue(IOUtils.contentEquals(stream, directStream));
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testDAMAssetCropScalingWithRotation.
@Test
public void testDAMAssetCropScalingWithRotation() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE13_PATH, "img.1440", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
ContentPolicyMapping mapping = request.getResource().adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
when(contentPolicyManager.getPolicy(request.getResource())).thenReturn(contentPolicy);
servlet.doGet(request, response);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(response.getOutput()));
assertEquals("Expected the cropped rectangle to have a 515px width, since the servlet should not perform cropping upscaling.", 515, image.getWidth());
assertEquals("Expected the cropped rectangle to have a 1390px height, since the servlet should not perform cropping upscaling.", 1390, image.getHeight());
}
use of org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class AdaptiveImageServletTest method testDAMAssetCrop.
@Test
public void testDAMAssetCrop() throws Exception {
Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse> requestResponsePair = prepareRequestResponsePair(IMAGE11_PATH, "img.1440", "png");
MockSlingHttpServletRequest request = requestResponsePair.getLeft();
MockSlingHttpServletResponse response = requestResponsePair.getRight();
ContentPolicyMapping mapping = request.getResource().adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = mapping.getPolicy();
when(contentPolicyManager.getPolicy(request.getResource())).thenReturn(contentPolicy);
servlet.doGet(request, response);
BufferedImage image = ImageIO.read(new ByteArrayInputStream(response.getOutput()));
assertEquals("Expected the cropped rectangle to have a 1440px width, since the servlet should not perform cropping upscaling.", 1440, image.getWidth());
assertEquals("Expected the cropped rectangle to have a 1440px height, since the servlet should not perform cropping upscaling.", 1440, image.getHeight());
}
Aggregations