Search in sources :

Example 1 with MockSlingHttpServletRequest

use of org.apache.sling.servlethelpers.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class CoreFormHandlingServletTest method testDoPost.

@Test
public void testDoPost() throws Exception {
    SlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver());
    SlingHttpServletResponse response = new MockSlingHttpServletResponse();
    servlet.doPost(request, response);
    verify(formsHandlingServletHelper).doPost(request, response);
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) MockSlingHttpServletResponse(org.apache.sling.servlethelpers.MockSlingHttpServletResponse) MockSlingHttpServletRequest(org.apache.sling.servlethelpers.MockSlingHttpServletRequest) MockSlingHttpServletResponse(org.apache.sling.servlethelpers.MockSlingHttpServletResponse) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) MockSlingHttpServletRequest(org.apache.sling.servlethelpers.MockSlingHttpServletRequest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with MockSlingHttpServletRequest

use of org.apache.sling.servlethelpers.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class DefaultPathProcessorTest method testSanitizeInternalLik.

@Test
void testSanitizeInternalLik() {
    DefaultPathProcessor underTest = context.registerService(new DefaultPathProcessor());
    String path = "#internal";
    MockSlingHttpServletRequest request = context.request();
    assertEquals(path, underTest.sanitize(path, request));
    path = PATH + path;
    assertEquals(path, underTest.sanitize(path, request));
    path = "?request=value";
    assertEquals(path, underTest.sanitize(path, request));
    path = PATH + path;
    assertEquals(path, underTest.sanitize(path, request));
    path = "/some space#internal";
    assertEquals("/some%20space#internal", underTest.sanitize(path, request));
}
Also used : MockSlingHttpServletRequest(org.apache.sling.servlethelpers.MockSlingHttpServletRequest) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 3 with MockSlingHttpServletRequest

use of org.apache.sling.servlethelpers.MockSlingHttpServletRequest in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class DefaultPathProcessorTest method testMappingWithException.

@Test
void testMappingWithException() {
    ResourceResolver resourceResolver = mock(ResourceResolver.class);
    when(resourceResolver.map(any(SlingHttpServletRequest.class), anyString())).thenThrow(IllegalStateException.class);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver);
    DefaultPathProcessor underTest = localContext.registerService(new DefaultPathProcessor());
    assertEquals(PATH, underTest.map(PATH, request));
}
Also used : MockSlingHttpServletRequest(org.apache.sling.servlethelpers.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) MockSlingHttpServletRequest(org.apache.sling.servlethelpers.MockSlingHttpServletRequest) Test(org.junit.jupiter.api.Test)

Aggregations

MockSlingHttpServletRequest (org.apache.sling.servlethelpers.MockSlingHttpServletRequest)3 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 Test (org.junit.jupiter.api.Test)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 MockSlingHttpServletResponse (org.apache.sling.servlethelpers.MockSlingHttpServletResponse)1 Test (org.junit.Test)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1