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, String selectorString, String extension) {
final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(aemContext.resourceResolver(), aemContext.bundleContext());
final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
Resource resource = resourceResolver.getResource(resourcePath);
request.setResource(resource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString(selectorString);
requestPathInfo.setExtension(extension);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.REQUEST, request);
bindings.put(SlingBindings.RESPONSE, response);
bindings.put(SlingBindings.SLING, aemContext.slingScriptHelper());
bindings.put(SlingBindings.RESOLVER, resourceResolver);
request.setAttribute(SlingBindings.class.getName(), bindings);
return new Pair<MockSlingHttpServletRequest, MockSlingHttpServletResponse>() {
@Override
public MockSlingHttpServletRequest getLeft() {
return request;
}
@Override
public MockSlingHttpServletResponse getRight() {
return response;
}
@Override
public MockSlingHttpServletResponse setValue(MockSlingHttpServletResponse value) {
throw new UnsupportedOperationException();
}
};
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class GQLToQueryBuilderConverterTest method addPathFromSuffix.
@Test
public void addPathFromSuffix() {
Map<String, String> map = new HashMap<>();
MockSlingHttpServletRequest request = context.request();
MockRequestPathInfo pathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
pathInfo.setSuffix("/foo");
GQLToQueryBuilderConverter.addPath(request, map);
assertThat(map, hasEntry("path", "/foo"));
assertEquals(1, map.size());
}
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));
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class ChecksumGeneratorServletTest method testWithNoPath.
@Test
public void testWithNoPath() throws Exception {
ResourceResolver resourceResolver = MockSling.newResourceResolver(context.bundleContext());
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver, context.bundleContext());
request.setResource(resourceResolver.getResource(SERVLET_PATH));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString(SERVLET_SELECTORS);
requestPathInfo.setExtension(SERVLET_EXTENSION);
request.setMethod("GET");
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
servlet.doGet(request, response);
assertEquals("text/plain;charset=UTF-8", response.getContentType());
assertEquals("ERROR: At least one path must be specified", response.getOutputAsString());
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class ExtensionlessRequestWrapperTest method getRequestPathInfo_NullExtension.
@Test
public void getRequestPathInfo_NullExtension() throws Exception {
request.setResource(context.resourceResolver().getResource("/content/null-extension"));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setExtension("xyz");
ExtensionlessRequestWrapper wrapper = new ExtensionlessRequestWrapper(request);
assertNull(wrapper.getRequestPathInfo().getExtension());
}
Aggregations