Search in sources :

Example 1 with MockRequestPathInfo

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

the class YouTubeImplTest method getYouTubeUnderTest.

private YouTubeImpl getYouTubeUnderTest(String resourcePath, Page page) {
    Resource resource = context.resourceResolver().getResource(resourcePath);
    if (resource == null) {
        throw new IllegalStateException("Did you forget to define test resource " + resourcePath + "?");
    }
    MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
    SlingBindings bindings = new SlingBindings();
    bindings.put(SlingBindings.RESOURCE, resource);
    bindings.put(SlingBindings.REQUEST, request);
    bindings.put(WCMBindingsConstants.NAME_CURRENT_PAGE, page);
    bindings.put(WCMBindingsConstants.NAME_COMPONENT_CONTEXT, componentContext);
    bindings.put(WCMBindingsConstants.NAME_PROPERTIES, resource.getValueMap());
    ((MockRequestPathInfo) request.getRequestPathInfo()).setResourcePath(resourcePath);
    request.setResource(resource);
    request.setAttribute(SlingBindings.class.getName(), bindings);
    ModelFactory modelFactory = context.getService(ModelFactory.class);
    YouTubeImpl youTubeImpl = (YouTubeImpl) modelFactory.createModel(request, YouTube.class);
    return youTubeImpl;
}
Also used : SlingBindings(org.apache.sling.api.scripting.SlingBindings) MockRequestPathInfo(org.apache.sling.servlethelpers.MockRequestPathInfo) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) Resource(org.apache.sling.api.resource.Resource) ModelFactory(org.apache.sling.models.factory.ModelFactory) YouTube(com.adobe.cq.wcm.core.components.models.embeddable.YouTube)

Aggregations

YouTube (com.adobe.cq.wcm.core.components.models.embeddable.YouTube)1 Resource (org.apache.sling.api.resource.Resource)1 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1 ModelFactory (org.apache.sling.models.factory.ModelFactory)1 MockRequestPathInfo (org.apache.sling.servlethelpers.MockRequestPathInfo)1 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)1