use of org.apache.sling.api.resource.ValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class MockContentPolicyMapping method getPolicy.
@Override
public ContentPolicy getPolicy() {
ValueMap valueMap = contentPolicyResource.adaptTo(ValueMap.class);
if (valueMap.containsKey("cq:policy")) {
String policyPath = valueMap.get("cq:policy", StringUtils.EMPTY);
if (StringUtils.isNotEmpty(policyPath)) {
policyPath = "/conf/coretest/settings/wcm/policies/" + policyPath;
Resource policyResource = contentPolicyResource.getResourceResolver().getResource(policyPath);
if (policyResource != null) {
return new MockContentPolicy(policyResource);
}
}
}
return null;
}
use of org.apache.sling.api.resource.ValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class WCMUsePojoBaseTest method getResourceBackedBindings.
/**
* <p>
* Creates a {@link Bindings} map initialised with the following default bindings available to Sightly use objects based on {@link
* WCMUsePojo}:
* </p>
* <ul>
* <li>{@link SlingBindings#RESOURCE}</li>
* <li>{@link SlingBindings#REQUEST}</li>
* <li>{@link SlingBindings#RESPONSE}</li>
* <li>{@link WCMBindings#PROPERTIES}</li>
* <li>{@link WCMBindings#WCM_MODE}</li>
* <li>{@link WCMBindings#PAGE_MANAGER}</li>
* <li>{@link WCMBindings#RESOURCE_PAGE}</li>
* <li>{@link WCMBindings#CURRENT_PAGE}</li>
* <li>{@link WCMBindings#PAGE_PROPERTIES}</li>
* </ul>
*
* @param resourcePath the path to a resource already loaded in the testing context
* @return the bindings map
*/
protected Bindings getResourceBackedBindings(String resourcePath) {
Bindings bindings = getDefaultSlingBindings();
Resource resource = context.resourceResolver().getResource(resourcePath);
if (resource != null) {
ValueMap properties = resource.adaptTo(ValueMap.class);
bindings.put(SlingBindings.RESOURCE, resource);
bindings.put(WCMBindings.PROPERTIES, properties);
bindings.put(WCMBindings.WCM_MODE, new SightlyWCMMode(context.request()));
PageManager pageManager = context.pageManager();
bindings.put(WCMBindings.PAGE_MANAGER, pageManager);
context.request().setResource(resource);
Page resourcePage = pageManager.getContainingPage(resource);
if (resourcePage != null) {
bindings.put(WCMBindings.RESOURCE_PAGE, resourcePage);
bindings.put(WCMBindings.CURRENT_PAGE, resourcePage);
bindings.put(WCMBindings.PAGE_PROPERTIES, properties);
}
} else {
throw new IllegalArgumentException("Cannot find a resource at " + resourcePath);
}
return bindings;
}
use of org.apache.sling.api.resource.ValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class WorkflowModelDataSourceServletTest method testDataSource.
@Test
public void testDataSource() throws Exception {
context.currentResource("/apps/workflowdatasource");
dataSourceServlet = new WorkflowModelDataSourceServlet();
dataSourceServlet.doGet(context.request(), context.response());
DataSource dataSource = (DataSource) context.request().getAttribute(DataSource.class.getName());
assertNotNull(dataSource);
Resource resource = dataSource.iterator().next();
ValueMap valueMap = resource.adaptTo(ValueMap.class);
assertEquals("Workflow Title", valueMap.get("text", String.class));
assertEquals("test/workflow", valueMap.get("value", String.class));
}
use of org.apache.sling.api.resource.ValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImpl method initModel.
//*************** IMPLEMENTATION *******************
@PostConstruct
private void initModel() throws Exception {
ValueMap pageProperties = currentPage.getProperties();
String[] socialMedia = pageProperties.get(PN_SOCIAL_MEDIA, String[].class);
facebookEnabled = ArrayUtils.contains(socialMedia, PV_FACEBOOK);
pinterestEnabled = ArrayUtils.contains(socialMedia, PV_PINTEREST);
socialMediaEnabled = facebookEnabled || pinterestEnabled;
variantPath = pageProperties.get(PN_VARIANT_PATH, String.class);
}
use of org.apache.sling.api.resource.ValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormStructureHelperImplTest method testUpdateformStructure.
@Test
public void testUpdateformStructure() {
Resource resource = resourceResolver.getResource(CONTAINING_PAGE + "/jcr:content/root/responsivegrid/container");
formStructureHelper.updateFormStructure(resource);
ValueMap properties = resource.adaptTo(ValueMap.class);
assertEquals("foundation/components/form/actions/store", properties.get("actionType", String.class));
String action = properties.get("action", String.class);
assertNotNull(action);
assertTrue(action.length() > 0);
}
Aggregations