Search in sources :

Example 1 with OptionItem

use of com.adobe.cq.wcm.core.components.models.form.OptionItem 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 2 with OptionItem

use of com.adobe.cq.wcm.core.components.models.form.OptionItem 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 3 with OptionItem

use of com.adobe.cq.wcm.core.components.models.form.OptionItem 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 4 with OptionItem

use of com.adobe.cq.wcm.core.components.models.form.OptionItem in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class OptionsImplTest method testOptionsDefaultAttributes.

@Test
public void testOptionsDefaultAttributes() {
    Resource optionsRes = context.currentResource(CONTENT_ROOT + "/optionsDefault");
    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(null, options.getName());
    assertEquals(null, options.getValue());
    assertEquals(null, options.getTitle());
    assertEquals(null, options.getHelpMessage());
    List<OptionItem> optionItems = options.getItems();
    assertNotNull(optionItems);
    assertTrue(optionItems.size() == 0);
}
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 OptionItem

use of com.adobe.cq.wcm.core.components.models.form.OptionItem in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class OptionsImplTest method testDatasourceAsOptionsSource.

@Test
public void testDatasourceAsOptionsSource() {
    setUpMockRequestDispatcher();
    Resource optionsRes = context.currentResource(CONTENT_ROOT + "/optionsWithDatasourceSource");
    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), "datasource-item1-name", "datasource-item1-value", true, false);
    evaluateOptionItem(optionItems.get(1), "datasource-item2-name", "datasource-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)

Aggregations

OptionItem (com.adobe.cq.wcm.core.components.models.form.OptionItem)6 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)6 Resource (org.apache.sling.api.resource.Resource)6 Options (com.adobe.cq.wcm.core.components.models.form.Options)5 ValueMap (org.apache.sling.api.resource.ValueMap)5 Test (org.junit.Test)5 SimpleDataSource (com.adobe.granite.ui.components.ds.SimpleDataSource)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ChildResource (org.apache.sling.models.annotations.injectorspecific.ChildResource)1