use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-cif-components by adobe.
the class ProductPageWithSkuAndUrlKeyTest method testParseSuffixNoSlash.
@Test
public void testParseSuffixNoSlash() {
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());
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project sling-org-apache-sling-pipes by apache.
the class CommandExecutorImplTest method testRawServlet.
String testRawServlet(Map<String, Object> params) throws IOException {
MockSlingHttpServletRequest request = context.request();
MockSlingHttpServletResponse response = context.response();
request.setParameterMap(params);
MockRequestPathInfo pathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
pathInfo.setExtension("json");
request.setMethod("POST");
commands.doPost(request, response);
if (response.getStatus() != 200) {
System.out.println(response.getOutputAsString());
}
assertEquals(200, response.getStatus());
return response.getOutputAsString();
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project sling-org-apache-sling-servlets-resolver by apache.
the class ScriptSelection2Test method prepareRequest.
@NotNull
private SlingHttpServletRequest prepareRequest(@Nullable String method, @NotNull Resource resource, @Nullable String selectorString, @NotNull String extension) {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
if (StringUtils.isEmpty(method)) {
request.setMethod("GET");
} else {
request.setMethod(method);
}
request.setResource(resource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
if (StringUtils.isNotEmpty(selectorString)) {
requestPathInfo.setSelectorString(selectorString);
}
requestPathInfo.setExtension(extension);
return request;
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
the class InheritedFieldTest method testOverridePropWithSuffix.
@Test
void testOverridePropWithSuffix() {
context.currentResource(TEST_APPS + "/brandSlug");
MockSlingHttpServletRequest request = context.request();
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSuffix("/content/test/parent/child");
InheritedField inheritedField = request.adaptTo(InheritedField.class);
if (inheritedField != null) {
assertEquals("Test Slug", inheritedField.getInheritedValue());
assertEquals("Brand Slug", inheritedField.getHeading());
assertNull(inheritedField.getSpecifiedValue());
assertEquals("brandSlug", inheritedField.getProp());
assertEquals("cssClass", inheritedField.getAttrClass());
assertFalse(inheritedField.isOverride());
} else {
fail("can't create inherited field model");
}
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project aem-core-wcm-components by adobe.
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);
}
Aggregations