Search in sources :

Example 1 with ValueMap

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;
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource)

Example 2 with ValueMap

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;
}
Also used : PageManager(com.day.cq.wcm.api.PageManager) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Page(com.day.cq.wcm.api.Page) SightlyWCMMode(com.adobe.cq.sightly.SightlyWCMMode) Bindings(javax.script.Bindings) SlingBindings(org.apache.sling.api.scripting.SlingBindings) SimpleBindings(javax.script.SimpleBindings) WCMBindings(com.adobe.cq.sightly.WCMBindings)

Example 3 with ValueMap

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));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) DataSource(com.adobe.granite.ui.components.ds.DataSource) Test(org.junit.Test)

Example 4 with ValueMap

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);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) PostConstruct(javax.annotation.PostConstruct)

Example 5 with ValueMap

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);
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

ValueMap (org.apache.sling.api.resource.ValueMap)278 Resource (org.apache.sling.api.resource.Resource)205 Test (org.junit.Test)160 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)59 HashMap (java.util.HashMap)54 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)44 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)26 Map (java.util.Map)21 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)21 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)20 RewriterResponse (org.apache.sling.security.impl.ContentDispositionFilter.RewriterResponse)20 Expectations (org.jmock.Expectations)20 ArrayList (java.util.ArrayList)18 PersistenceException (org.apache.sling.api.resource.PersistenceException)17 Calendar (java.util.Calendar)16 Date (java.util.Date)15 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)12 InputStream (java.io.InputStream)11 Node (javax.jcr.Node)11