Search in sources :

Example 11 with Resource

use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class OptionsImplTest method testMulitDropDownOptionsType.

@Test
public void testMulitDropDownOptionsType() throws Exception {
    Resource optionsRes = context.currentResource(CONTENT_ROOT + "/multi-drop-down");
    slingBindings.put(WCMBindings.PROPERTIES, optionsRes.adaptTo(ValueMap.class));
    slingBindings.put(RESOURCE_PROPERTY, optionsRes);
    Options options = context.request().adaptTo(Options.class);
    assertEquals(Type.MULTI_DROP_DOWN, options.getType());
}
Also used : Options(com.adobe.cq.wcm.core.components.models.form.Options) RequestDispatcherOptions(org.apache.sling.api.request.RequestDispatcherOptions) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 12 with Resource

use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class OptionsImplTest method testListAsOptionsSource.

@Test
public void testListAsOptionsSource() {
    Resource optionsRes = context.currentResource(CONTENT_ROOT + "/optionsWithListSource");
    slingBindings.put(WCMBindings.PROPERTIES, optionsRes.adaptTo(ValueMap.class));
    slingBindings.put(RESOURCE_PROPERTY, optionsRes);
    Options options = context.request().adaptTo(Options.class);
    List<OptionItem> optionItems = options.getItems();
    assertNotNull(optionItems);
    assertTrue(optionItems.size() == 2);
    evaluateOptionItem(optionItems.get(0), "list-item1-name", "list-item1-value", true, false);
    evaluateOptionItem(optionItems.get(1), "list-item2-name", "list-item2-value", false, true);
}
Also used : Options(com.adobe.cq.wcm.core.components.models.form.Options) RequestDispatcherOptions(org.apache.sling.api.request.RequestDispatcherOptions) OptionItem(com.adobe.cq.wcm.core.components.models.form.OptionItem) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 13 with Resource

use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class OptionsImplTest method setUpMockDataSource.

private void setUpMockDataSource() {
    Resource dataSourceResource = context.resourceResolver().getResource(CONTENT_ROOT + "/dataDatasource/datasource/items");
    SimpleDataSource dataSource = new SimpleDataSource(dataSourceResource.listChildren());
    context.request().setAttribute(DataSource.class.getName(), dataSource);
}
Also used : SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) Resource(org.apache.sling.api.resource.Resource) SimpleDataSource(com.adobe.granite.ui.components.ds.SimpleDataSource) DataSource(com.adobe.granite.ui.components.ds.DataSource)

Example 14 with Resource

use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class BreadcrumbImplTest method testGetHideCurrent.

@Test
public void testGetHideCurrent() throws Exception {
    Resource resource = context.currentResource(CURRENT_PAGE + "/jcr:content/header/breadcrumb-hide-current");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    underTest = context.request().adaptTo(Breadcrumb.class);
    checkBreadcrumbConsistency(new String[] { "Women" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Breadcrumb(com.adobe.cq.wcm.core.components.models.Breadcrumb) Test(org.junit.Test)

Example 15 with Resource

use of org.apache.sling.api.resource.Resource in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class BreadcrumbImplTest method testStyleBasedBreadcrumb.

@Test
public void testStyleBasedBreadcrumb() throws Exception {
    Resource resource = context.currentResource(CURRENT_PAGE + "/jcr:content/header/breadcrumb-style-based");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    Style style = mock(Style.class);
    when(style.get(BreadcrumbImpl.PN_START_LEVEL, BreadcrumbImpl.PROP_START_LEVEL_DEFAULT)).thenReturn(3);
    when(style.get(BreadcrumbImpl.PN_HIDE_CURRENT, BreadcrumbImpl.PROP_SHOW_HIDDEN_DEFAULT)).thenReturn(false);
    when(style.get(BreadcrumbImpl.PN_SHOW_HIDDEN, BreadcrumbImpl.PROP_SHOW_HIDDEN_DEFAULT)).thenReturn(false);
    slingBindings.put(WCMBindings.CURRENT_STYLE, style);
    underTest = context.request().adaptTo(Breadcrumb.class);
    checkBreadcrumbConsistency(new String[] { "Devi Sleeveless Shirt" });
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) Style(com.day.cq.wcm.api.designer.Style) Breadcrumb(com.adobe.cq.wcm.core.components.models.Breadcrumb) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)1569 Test (org.junit.Test)695 ValueMap (org.apache.sling.api.resource.ValueMap)338 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)260 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)164 HashMap (java.util.HashMap)160 Node (javax.jcr.Node)151 ArrayList (java.util.ArrayList)137 ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)119 PersistenceException (org.apache.sling.api.resource.PersistenceException)114 Test (org.junit.jupiter.api.Test)72 Map (java.util.Map)70 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)70 HttpServletRequest (javax.servlet.http.HttpServletRequest)62 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)60 FakeSlingHttpServletRequest (org.apache.sling.launchpad.testservices.exported.FakeSlingHttpServletRequest)59 LoginException (org.apache.sling.api.resource.LoginException)58 RepositoryException (javax.jcr.RepositoryException)54 Calendar (java.util.Calendar)50 Session (javax.jcr.Session)49