use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ComponentFilesImplTest method getComponentFilesUnderTest.
private ComponentFiles getComponentFilesUnderTest(String path, Map<String, Object> attributes) {
Resource resource = context.currentResource(path);
if (resource != null) {
if (attributes != null) {
SlingBindings slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
slingBindings.put(entry.getKey(), entry.getValue());
}
context.request().setAttribute(SlingBindings.class.getName(), slingBindings);
}
context.request().setResource(resource);
return context.request().adaptTo(ComponentFiles.class);
}
return null;
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class NavigationImplTest method getNavigationUnderTest.
protected Navigation getNavigationUnderTest(String resourcePath) {
Utils.enableDataLayer(context, true);
context.currentResource(resourcePath);
MockSlingHttpServletRequest request = context.request();
request.setContextPath("/core");
Component component = mock(Component.class);
when(component.getResourceType()).thenReturn(resourceType);
SlingBindings slingBindings = (SlingBindings) request.getAttribute(SlingBindings.class.getName());
slingBindings.put(WCMBindings.COMPONENT, component);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(Navigation.class);
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class OptionsImplTest method getOptionsUnderTest.
private Options getOptionsUnderTest(String resourcePath) {
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());
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
request.setResource(resource);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(SlingBindings.REQUEST, request);
bindings.put(SlingBindings.RESOLVER, context.resourceResolver());
bindings.put(SlingBindings.RESPONSE, response);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setAttribute(SlingBindings.class.getName(), bindings);
request.setRequestDispatcherFactory(new MockRequestDispatcherFactory() {
@Override
public RequestDispatcher getRequestDispatcher(String s, RequestDispatcherOptions requestDispatcherOptions) {
return null;
}
@Override
public RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions requestDispatcherOptions) {
return new MockRequestDispatcher(requestDispatcherOptions);
}
});
return request.adaptTo(Options.class);
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ButtonImplTest method getButtonUnderTest.
private Button getButtonUnderTest(String resourcePath) {
Resource resource = context.resourceResolver().getResource(resourcePath);
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
request.setResource(resource);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(Button.class);
}
use of org.apache.sling.api.scripting.SlingBindings in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImplTest method getSocialMediaHelperUnderTest.
private SocialMediaHelper getSocialMediaHelperUnderTest(String pagePath) {
Resource currentResource = context.resourceResolver().getResource(pagePath);
Page currentPage = currentResource.adaptTo(Page.class);
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(context.resourceResolver(), context.bundleContext());
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
request.setContextPath(CONTEXT_PATH);
request.setResource(currentResource);
MockRequestPathInfo requestPathInfo = (MockRequestPathInfo) request.getRequestPathInfo();
requestPathInfo.setExtension(EXTENSION);
requestPathInfo.setResourcePath(currentResource.getPath());
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(SlingBindings.RESOLVER, context.resourceResolver());
slingBindings.put(SlingBindings.RESPONSE, response);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(SocialMediaHelper.class);
}
Aggregations