本文整理汇总了Java中com.adobe.cq.sightly.WCMBindings类的典型用法代码示例。如果您正苦于以下问题:Java WCMBindings类的具体用法?Java WCMBindings怎么用?Java WCMBindings使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WCMBindings类属于com.adobe.cq.sightly包,在下文中一共展示了WCMBindings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getContainerUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private Container getContainerUnderTest(String resourcePath) {
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Does the test resource " + resourcePath + " exist?");
}
SlingBindings bindings = new SlingBindings();
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
request.setContextPath(CONTEXT_PATH);
request.setResource(resource);
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
bindings.put(SlingBindings.REQUEST, request);
bindings.put(SlingBindings.RESPONSE, response);
Page page = CONTEXT.currentPage(CONTAINING_PAGE);
bindings.put(WCMBindings.CURRENT_PAGE, page);
request.setRequestDispatcherFactory(requestDispatcherFactory);
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(Container.class);
}
示例2: getBreadcrumbUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private Breadcrumb getBreadcrumbUnderTest(String resourcePath, Style style) {
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());
request.setResource(resource);
request.setContextPath("");
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(CURRENT_PAGE));
if (style == null) {
style = mock(Style.class);
when(style.get(any(), any(Object.class))).thenAnswer(
invocation -> invocation.getArguments()[1]
);
}
bindings.put(WCMBindings.CURRENT_STYLE, style);
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(Breadcrumb.class);
}
示例3: getListUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private List getListUnderTest(String resourcePath) {
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Did you forget to defines test resource " + resourcePath + "?");
}
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
request.setResource(resource);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(SlingBindings.REQUEST, request);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
Style style = mock(Style.class);
when(style.get(any(), any(Object.class))).thenAnswer(
invocation -> invocation.getArguments()[1]
);
bindings.put(WCMBindings.CURRENT_STYLE, style);
bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(CURRENT_PAGE));
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(List.class);
}
示例4: getSocialMediaHelperUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
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);
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:18,代码来源:SocialMediaHelperImplTest.java
示例5: getTitleUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private Title getTitleUnderTest(String resourcePath, Style style) {
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(WCMBindings.PROPERTIES, resource.getValueMap());
bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(TEST_PAGE));
if (style == null) {
style = mock(Style.class);
}
bindings.put(WCMBindings.CURRENT_STYLE, style);
request.setResource(resource);
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(Title.class);
}
示例6: getListUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private List getListUnderTest(String resourcePath) {
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Did you forget to defines test resource " + resourcePath + "?");
}
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
request.setResource(resource);
request.setContextPath(CONTEXT_PATH);
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(SlingBindings.REQUEST, request);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
Style style = mock(Style.class);
when(style.get(any(), any(Object.class))).thenAnswer(
invocation -> invocation.getArguments()[1]
);
bindings.put(WCMBindings.CURRENT_STYLE, style);
bindings.put(WCMBindings.CURRENT_PAGE, CONTEXT.pageManager().getPage(CURRENT_PAGE));
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(List.class);
}
示例7: addBindings
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
public void addBindings(Bindings bindings) {
SlingHttpServletRequest request = (SlingHttpServletRequest)bindings.get(BINDING_REQUEST);
if (null != request && null != bindings) {
// get valuemap from bindings, or fall back on Resource#adaptTo(ValueMap)
ValueMap properties = (bindings.containsKey(WCMBindings.PROPERTIES))?
(ValueMap)bindings.get(WCMBindings.PROPERTIES) :
request.getResource().adaptTo(ValueMap.class);
// generate sling:basename qualified i18n ResourceBundle
ResourceBundle baseBundle = request.getResourceBundle(
request.getResource().getResourceType(),
WCMUtil.getLocale(request));
I18nResourceBundle i18n = new I18nResourceBundle(properties, baseBundle);
// apply to bindings for sightly availability
bindings.put(WCMBindings.PROPERTIES, i18n.adaptTo(ValueMap.class));
// cleanup
properties = null;
baseBundle = null;
i18n = null;
}
}
示例8: getTextUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private Text getTextUnderTest(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);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(Text.class);
}
示例9: prepareHiddenFieldForTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private Field prepareHiddenFieldForTest(String resourcePath) {
MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
request.setResource(resource);
Page currentPage = CONTEXT.pageManager().getPage(CONTAINING_PAGE);
SlingBindings slingBindings = new SlingBindings();
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(SlingBindings.RESOURCE, resource);
slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(Field.class);
}
示例10: getImageUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
protected <T> T getImageUnderTest(String resourcePath, Class<T> imageClass) {
Resource resource = CONTEXT.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Does the test resource " + resourcePath + " exist?");
}
ContentPolicyMapping mapping = resource.adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = null;
if (mapping != null) {
contentPolicy = mapping.getPolicy();
}
SlingBindings slingBindings = new SlingBindings();
Style style = null;
if (contentPolicy != null) {
when(contentPolicyManager.getPolicy(resource)).thenReturn(contentPolicy);
style = new MockContentPolicyStyle(contentPolicy);
}
if (style == null) {
style = mock(Style.class);
when(style.get(anyString(), (Object) Matchers.anyObject())).thenAnswer(
invocationOnMock -> invocationOnMock.getArguments()[1]
);
}
slingBindings.put(SlingBindings.RESOURCE, resource);
final MockSlingHttpServletRequest request =
new MockSlingHttpServletRequest(CONTEXT.resourceResolver(), CONTEXT.bundleContext());
request.setContextPath(CONTEXT_PATH);
request.setResource(resource);
Page page = CONTEXT.pageManager().getPage(PAGE);
slingBindings.put(WCMBindings.CURRENT_PAGE, page);
slingBindings.put(WCMBindings.WCM_MODE, new SightlyWCMMode(request));
slingBindings.put(WCMBindings.PAGE_MANAGER, CONTEXT.pageManager());
slingBindings.put(WCMBindings.CURRENT_STYLE, style);
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(imageClass);
}
示例11: getTextUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
protected <T> T getTextUnderTest(Class<T> model, 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());
SlingBindings bindings = new SlingBindings();
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(SlingBindings.REQUEST, request);
bindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
request.setResource(resource);
request.setAttribute(SlingBindings.class.getName(), bindings);
return request.adaptTo(model);
}
示例12: getLanguageNavigationUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private LanguageNavigation getLanguageNavigationUnderTest(String resourcePath) {
Resource resource = AEM_CONTEXT.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Does the test resource " + resourcePath + " exist?");
}
ContentPolicyMapping mapping = resource.adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = null;
if (mapping != null) {
contentPolicy = mapping.getPolicy();
}
final MockSlingHttpServletRequest request =
new MockSlingHttpServletRequest(AEM_CONTEXT.resourceResolver(), AEM_CONTEXT.bundleContext());
request.setContextPath(CONTEXT_PATH);
request.setResource(resource);
Page currentPage = AEM_CONTEXT.pageManager().getContainingPage(resource);
SlingBindings slingBindings = new SlingBindings();
Style currentStyle;
if (contentPolicy != null) {
ContentPolicyManager policyManager = mock(ContentPolicyManager.class);
when(policyManager.getPolicy(resource)).thenReturn(contentPolicy);
currentStyle = new MockContentPolicyStyle(contentPolicy);
} else {
currentStyle = mock(Style.class);
when(currentStyle.get(anyString(), (Object) Matchers.anyObject())).thenAnswer(
invocation -> invocation.getArguments()[1]
);
}
slingBindings.put(SlingBindings.RESOURCE, resource);
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
slingBindings.put(WCMBindings.CURRENT_STYLE, currentStyle);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(LanguageNavigation.class);
}
开发者ID:Adobe-Marketing-Cloud,项目名称:aem-core-wcm-components,代码行数:35,代码来源:LanguageNavigationImplTest.java
示例13: setUp
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
@Before
public void setUp() {
slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class.getName());
slingBindings.put(WCMBindings.CURRENT_STYLE, slingBindings = (SlingBindings) context.request().getAttribute(SlingBindings.class
.getName()));
slingBindings.put(WCMBindings.CURRENT_PAGE, context.currentPage("/content/en/search/page"));
}
示例14: testSearchProperties
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
@Test
public void testSearchProperties() throws Exception {
Resource resource = context.currentResource(TEST_ROOT + "/jcr:content/search");
slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
Search search = context.request().adaptTo(Search.class);
assertEquals(10, search.getResultsSize());
assertEquals(3, search.getSearchTermMinimumLength());
assertEquals("/jcr:content/search", search.getRelativePath());
assertEquals("core/wcm/components/search/v1/search", search.getExportedType());
}
示例15: getNavigationUnderTest
import com.adobe.cq.sightly.WCMBindings; //导入依赖的package包/类
private Navigation getNavigationUnderTest(String resourcePath) {
Resource resource = AEM_CONTEXT.resourceResolver().getResource(resourcePath);
if (resource == null) {
throw new IllegalStateException("Does the test resource " + resourcePath + " exist?");
}
ContentPolicyMapping mapping = resource.adaptTo(ContentPolicyMapping.class);
ContentPolicy contentPolicy = null;
if (mapping != null) {
contentPolicy = mapping.getPolicy();
}
final MockSlingHttpServletRequest request =
new MockSlingHttpServletRequest(AEM_CONTEXT.resourceResolver(), AEM_CONTEXT.bundleContext());
request.setContextPath(CONTEXT_PATH);
request.setResource(resource);
Page currentPage = AEM_CONTEXT.pageManager().getContainingPage(resource);
SlingBindings slingBindings = new SlingBindings();
Style currentStyle;
if (contentPolicy != null) {
when(POLICY_MANAGER.getPolicy(resource)).thenReturn(contentPolicy);
currentStyle = new MockContentPolicyStyle(contentPolicy);
} else {
currentStyle = mock(Style.class);
when(currentStyle.get(anyString(), (Object) Matchers.anyObject())).thenAnswer(
invocation -> invocation.getArguments()[1]
);
}
slingBindings.put(SlingBindings.RESOURCE, resource);
slingBindings.put(WCMBindings.CURRENT_PAGE, currentPage);
slingBindings.put(WCMBindings.PROPERTIES, resource.getValueMap());
slingBindings.put(WCMBindings.CURRENT_STYLE, currentStyle);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
return request.adaptTo(Navigation.class);
}