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;
}
Aggregations