Search in sources :

Example 1 with MockSlingHttpServletResponse

use of org.apache.sling.servlethelpers.MockSlingHttpServletResponse 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 MockSlingHttpServletResponse

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

the class ElementNamesRenderConditionTest method getRenderCondition.

/**
 * Calls the servlet with the specified render conditino resource and returns the resulting render condition.
 */
private RenderCondition getRenderCondition(String name) throws ServletException, IOException {
    // get render condition resource
    ResourceResolver resolver = context.resourceResolver();
    Resource renderCondition = resolver.getResource(RENDERCONDITIONS_PATH + "/" + name);
    // mock the request
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resolver, context.bundleContext());
    request.setResource(renderCondition);
    // call the servlet
    servlet.doGet(request, new MockSlingHttpServletResponse());
    // return the resulting render condition
    return (RenderCondition) request.getAttribute(RenderCondition.class.getName());
}
Also used : RenderCondition(com.adobe.granite.ui.components.rendercondition.RenderCondition) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.servlethelpers.MockSlingHttpServletResponse)

Example 3 with MockSlingHttpServletResponse

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

the class AbstractContentFragmentDataSourceServletTest method getDataSource.

/**
 * Calls the servlet with the specified datasource resource and returns the resulting datasource.
 */
DataSource getDataSource(AbstractContentFragmentDataSourceServlet servlet, String name) throws ServletException, IOException {
    // get datasource resource
    ResourceResolver resolver = context.resourceResolver();
    Resource dataSource = resolver.getResource(DATASOURCES_PATH + "/" + name);
    // mock the request and request resource
    Resource resource = mock(Resource.class);
    when(resource.getChild(Config.DATASOURCE)).thenReturn(dataSource);
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resolver, context.bundleContext());
    request.setResource(resource);
    // call the servlet
    servlet.doGet(request, new MockSlingHttpServletResponse());
    // return the resulting datasource
    return (DataSource) request.getAttribute(DataSource.class.getName());
}
Also used : MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) MockSlingHttpServletResponse(org.apache.sling.servlethelpers.MockSlingHttpServletResponse) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Aggregations

MockSlingHttpServletResponse (org.apache.sling.servlethelpers.MockSlingHttpServletResponse)3 Resource (org.apache.sling.api.resource.Resource)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)2 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)2 DataSource (com.adobe.granite.ui.components.ds.DataSource)1 RenderCondition (com.adobe.granite.ui.components.rendercondition.RenderCondition)1 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)1 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)1 MockSlingHttpServletRequest (org.apache.sling.servlethelpers.MockSlingHttpServletRequest)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1