Search in sources :

Example 16 with MockRequestPathInfo

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);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 17 with MockRequestPathInfo

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);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 18 with MockRequestPathInfo

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);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 19 with MockRequestPathInfo

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);
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 20 with MockRequestPathInfo

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());
}
Also used : MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse) Test(org.junit.Test)

Aggregations

MockRequestPathInfo (org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo)91 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)59 Test (org.junit.Test)45 Test (org.junit.jupiter.api.Test)38 MockSlingHttpServletResponse (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletResponse)24 ProductUrlFormat (com.adobe.cq.commerce.core.components.services.urls.ProductUrlFormat)23 AbstractImageTest (com.adobe.cq.wcm.core.components.internal.models.v1.AbstractImageTest)16 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)10 ImmutableMap (com.google.common.collect.ImmutableMap)8 Map (java.util.Map)8 Resource (org.apache.sling.api.resource.Resource)8 SlingBindings (org.apache.sling.api.scripting.SlingBindings)8 CategoryUrlFormat (com.adobe.cq.commerce.core.components.services.urls.CategoryUrlFormat)4 PageImageThumbnail (com.adobe.cq.wcm.core.components.commons.editor.dialog.inherited.PageImageThumbnail)4 Page (com.day.cq.wcm.api.Page)3 ValueMap (org.apache.sling.api.resource.ValueMap)3 CloudConfigurationList (com.adobe.acs.commons.cloudconfig.CloudConfigurationList)2 BufferedImage (java.awt.image.BufferedImage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 CloudConfiguration (com.adobe.acs.commons.cloudconfig.CloudConfiguration)1