use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class PathInfoUtilTest method testGetFirstSuffixSegments.
@Test
public void testGetFirstSuffixSegments() {
ResourceResolver resourceResolver = context.resourceResolver();
MockSlingHttpServletRequest request = context.request();
request.setResource(resourceResolver.getResource("/apple/macbookair"));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString("show.test");
requestPathInfo.setExtension("html");
requestPathInfo.setSuffix("first/second");
request.setQueryString("cpu=i7&ghz=2.4");
String expResult = "first";
String result = PathInfoUtil.getFirstSuffixSegment(request);
assertEquals(expResult, result);
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class PathInfoUtilTest method testGetQueryParam_HttpServletRequest_String.
/**
* Test of getQueryParam method, of class PathInfoUtil.
*/
@Test
public void testGetQueryParam_HttpServletRequest_String() {
ResourceResolver resourceResolver = context.resourceResolver();
MockSlingHttpServletRequest request = context.request();
request.setResource(resourceResolver.getResource("/apple/macbookair"));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString("show");
requestPathInfo.setExtension("html");
request.setQueryString("cpu=i7&ghz=2.4");
String key = "ghz";
String expResult = "2.4";
String result = PathInfoUtil.getQueryParam(request, key);
assertEquals(expResult, result);
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class PathInfoUtilTest method testGetSuffixSegment.
/**
* Test of getSuffixSegment method, of class PathInfoUtil.
*/
@Test
public void testGetSuffixSegment() {
ResourceResolver resourceResolver = context.resourceResolver();
MockSlingHttpServletRequest request = context.request();
request.setResource(resourceResolver.getResource("/apple/macbookair"));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString("show.test");
requestPathInfo.setExtension("html");
requestPathInfo.setSuffix("super/simple");
request.setQueryString("cpu=i7&ghz=2.4");
String expResult = "super";
String result = PathInfoUtil.getSuffixSegment(request, 0);
assertEquals(expResult, result);
expResult = "simple";
result = PathInfoUtil.getSuffixSegment(request, 1);
assertEquals(expResult, result);
result = PathInfoUtil.getSuffixSegment(request, -1);
assertNull(result);
result = PathInfoUtil.getSuffixSegment(request, 10);
assertNull(result);
}
use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.
the class PathInfoUtilTest method testGetSuffix.
/**
* Test of getSuffix method, of class PathInfoUtil.
*/
@Test
public void testGetSuffix() {
ResourceResolver resourceResolver = context.resourceResolver();
MockSlingHttpServletRequest request = context.request();
request.setResource(resourceResolver.getResource("/apple/macbookair"));
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setSelectorString("show.test");
requestPathInfo.setExtension("html");
requestPathInfo.setSuffix("super/simple");
request.setQueryString("cpu=i7&ghz=2.4");
String expResult = "super/simple";
String result = PathInfoUtil.getSuffix(request);
assertEquals(expResult, result);
}
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 {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
request.setResource(context.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());
}
Aggregations