Search in sources :

Example 11 with MockRequestPathInfo

use of org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo in project acs-aem-commons by Adobe-Consulting-Services.

the class CloudConfigurationListImplTest method valid.

@SuppressWarnings("unchecked")
@Test
public void valid() throws IOException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) context.request().getRequestPathInfo();
    requestPathInfo.setSuffix("/apps/core/wcm/templates/marketocloudconfig");
    CloudConfigurationList list = new CloudConfigurationListImpl(context.request());
    assertNotNull(list);
    Field field = list.getClass().getDeclaredField("configs");
    field.setAccessible(true);
    assertNotNull(field.get(list));
    CloudConfiguration config = new CloudConfigurationImpl(context.resourceResolver().getResource("/conf/test"));
    ((List<CloudConfiguration>) field.get(list)).add(config);
    assertNotNull(list.getCloudConfigurations());
    assertEquals(1, list.getCloudConfigurations().size());
    config = list.getCloudConfigurations().get(0);
    assertNotNull(config);
    assertEquals("/conf/test", config.getItemPath());
    assertEquals("/", config.getConfigPath());
}
Also used : Field(java.lang.reflect.Field) MockRequestPathInfo(org.apache.sling.testing.mock.sling.servlet.MockRequestPathInfo) CloudConfigurationList(com.adobe.acs.commons.cloudconfig.CloudConfigurationList) CloudConfiguration(com.adobe.acs.commons.cloudconfig.CloudConfiguration) CloudConfigurationList(com.adobe.acs.commons.cloudconfig.CloudConfigurationList) List(java.util.List) Test(org.junit.Test)

Example 12 with MockRequestPathInfo

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

Example 13 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 testGetSelector.

/**
 * Test of getSelector method, of class PathInfoUtil.
 */
@Test
public void testGetSelector() {
    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");
    request.setQueryString("cpu=i7&ghz=2.4");
    String expResult = "show";
    String result = PathInfoUtil.getSelector(request, 0);
    assertEquals(expResult, result);
    expResult = "test";
    result = PathInfoUtil.getSelector(request, 1);
    assertEquals(expResult, result);
    result = PathInfoUtil.getSelector(request, -1);
    assertNull(result);
    result = PathInfoUtil.getSelector(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 14 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 testGetLastSuffixSegments.

@Test
public void testGetLastSuffixSegments() {
    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/third");
    request.setQueryString("cpu=i7&ghz=2.4");
    String expResult = "third";
    String result = PathInfoUtil.getLastSuffixSegment(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 15 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 testGetSuffixSegments.

@Test
public void testGetSuffixSegments() {
    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 = new String[] { "super", "simple" };
    String[] result = PathInfoUtil.getSuffixSegments(request);
    assertArrayEquals(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)

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