use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class ExtensionlessRequestWrapperTest method getRequestPathInfo_HasExtension.
@Test
public void getRequestPathInfo_HasExtension() throws Exception {
request.setResource(context.resourceResolver().getResource("/content/has-extension"));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setExtension("xyz");
ExtensionlessRequestWrapper wrapper = new ExtensionlessRequestWrapper(request);
assertEquals("xyz", wrapper.getRequestPathInfo().getExtension());
}
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());
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class QrCodeServletTest method doGet.
@Test
public void doGet() throws Exception {
request.setResource(requestResource);
when(externalizer.publishLink(request.getResourceResolver(), "/content/externalize-me.html")).thenReturn("http://www.example.com/content/externalize-me.html");
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix("/content/externalize-me.html");
// requestPathInfo.setExtension("json");
qrCodeServlet.doGet(request, response);
JSONObject actual = new JSONObject(response.getOutputAsString());
assertEquals(HttpServletResponse.SC_OK, response.getStatus());
assertEquals(true, actual.getBoolean("enabled"));
assertEquals("http://www.example.com/content/externalize-me.html", actual.getString("publishURL"));
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
the class PageImageThumbnailTest method testPageImageThumbnailWithSuffix.
@Test
void testPageImageThumbnailWithSuffix() {
context.currentResource(RESOURCE);
MockSlingHttpServletRequest request = context.request();
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix(RESOURCE);
requestPathInfo.setResourcePath(RESOURCE);
PageImageThumbnail pageImageThumbnail = request.adaptTo(PageImageThumbnail.class);
if (pageImageThumbnail != null) {
assertEquals("featured image alt", pageImageThumbnail.getAlt(), "getAlt()");
assertEquals("/content/page/_jcr_content/_cq_featuredimage.coreimg.png", pageImageThumbnail.getSrc(), "getSrc()");
assertEquals("/content/page/jcr:content/root/responsivegrid/image", pageImageThumbnail.getComponentPath(), "getComponentPath()");
assertEquals("/content/page/jcr:content/root/responsivegrid/image", pageImageThumbnail.getConfigPath(), "getConfigPath()");
assertEquals("/content/page", pageImageThumbnail.getCurrentPagePath(), "getCurrentPagePath()");
} else {
fail("can't create page image thumnbail model");
}
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
the class EditorTest method getItemsEditor.
private Editor getItemsEditor(String suffix) {
// get the carousel component node resource
Resource resource = context.resourceResolver().getResource(CAROUSEL_PATH);
// prepare the request object
final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
// set the suffix
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix(suffix);
// define the bindings
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(SlingBindings.RESOURCE, resource);
if (resource != null) {
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
}
slingBindings.put(WCMBindings.PAGE_MANAGER, context.pageManager());
request.setAttribute(SlingBindings.class.getName(), slingBindings);
// adapt to the class to test
return request.adaptTo(Editor.class);
}
Aggregations