Search in sources :

Example 1 with Resource

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

the class ListImplTest method testOrderByModificationDate.

@Test
public void testOrderByModificationDate() throws Exception {
    Resource resource = context.currentResource("/content/list/listTypes/staticOrderByModificationDateListType");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    List list = context.request().adaptTo(List.class);
    checkListConsistency(list, new String[] { "Page 2", "Page 1" });
}
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) List(com.adobe.cq.wcm.core.components.models.List) Test(org.junit.Test)

Example 2 with Resource

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

the class ListImplTest method testTagsListType.

@Test
public void testTagsListType() throws Exception {
    Resource resource = context.currentResource("/content/list/listTypes/tagsListType");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    List list = context.request().adaptTo(List.class);
    assertEquals(1, list.getItems().size());
}
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) List(com.adobe.cq.wcm.core.components.models.List) Test(org.junit.Test)

Example 3 with Resource

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

the class OptionsImplTest method testCheckboxOptionsType.

@Test
public void testCheckboxOptionsType() throws Exception {
    Resource optionsRes = context.currentResource(CONTENT_ROOT + "/checkbox");
    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();
    assertEquals("name1", options.getName());
    assertEquals("jcr:title1", options.getTitle());
    assertEquals("helpMessage1", options.getHelpMessage());
    assertEquals(Type.CHECKBOX, options.getType());
    assertNotNull(optionItems);
    assertTrue(optionItems.size() == 3);
    // test the first option item
    OptionItem item = optionItems.get(0);
    evaluateOptionItem(item, "t1", "v1", true, true);
    item = optionItems.get(1);
    evaluateOptionItem(item, "t2", "v2", true, false);
    item = optionItems.get(2);
    evaluateOptionItem(item, "t3", "v3", false, false);
}
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 4 with Resource

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

the class OptionsImplTest method testLocalAsOptionsSource.

@Test
public void testLocalAsOptionsSource() {
    Resource optionsRes = context.currentResource(CONTENT_ROOT + "/optionsWithLocalSource");
    slingBindings.put(WCMBindings.PROPERTIES, optionsRes.adaptTo(ValueMap.class));
    slingBindings.put(RESOURCE_PROPERTY, optionsRes);
    Options options = context.request().adaptTo(Options.class);
    assertEquals(Type.CHECKBOX, options.getType());
    String id = "form-options" + "-" + String.valueOf(Math.abs(optionsRes.getPath().hashCode() - 1));
    assertEquals(id, options.getId());
    assertEquals("local-name", options.getName());
    assertEquals("local-title", options.getTitle());
    assertEquals("local-helpMessage", options.getHelpMessage());
    List<OptionItem> optionItems = options.getItems();
    assertNotNull(optionItems);
    assertTrue(optionItems.size() == 2);
    evaluateOptionItem(optionItems.get(0), "local-item1-name", "local-item1-value", true, false);
    evaluateOptionItem(optionItems.get(1), "local-item2-name", "local-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 5 with Resource

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

the class ListImplTest method testSearchListType.

@Test
public void testSearchListType() throws Exception {
    SearchResult searchResult = mock(SearchResult.class);
    Hit hit = mock(Hit.class);
    when(mockSimpleSearch.getResult()).thenReturn(searchResult);
    when(searchResult.getHits()).thenReturn(Collections.singletonList(hit));
    Resource contentResource = context.currentResource("/content/list/pages/page_1/jcr:content");
    when(hit.getResource()).thenReturn(contentResource);
    Resource resource = context.currentResource("/content/list/listTypes/searchListType");
    slingBindings.put(WCMBindings.PROPERTIES, resource.adaptTo(ValueMap.class));
    slingBindings.put(WCMBindings.CURRENT_STYLE, new MockStyle(resource));
    List list = context.request().adaptTo(List.class);
    assertEquals(1, list.getItems().size());
}
Also used : Hit(com.day.cq.search.result.Hit) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) MockStyle(com.adobe.cq.wcm.core.components.context.MockStyle) SearchResult(com.day.cq.search.result.SearchResult) List(com.adobe.cq.wcm.core.components.models.List) 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