Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Storing component configurations

Mikołaj Mański edited this page Jul 15, 2016 · 3 revisions

Storing component configurations

ComponentConfigurer is class responsible for setting values in the component dialogs basing on data tables. The concept is to pass component configuration in one object using one Gherkin sentence. Data table must contain every detail of the configuration:

  • tab - name of tab in AemDialog where field is placed,
  • type - type of the field in AemDialog,
  • label - label of the field in AemDialog,
  • value - desired value of the field in AemDialog.

Example:

#...
And I configure component using following data
|   tab   |   type   | label | value |
| General | dropdown | Style | none  |
|   ...   |   ...    |  ...  |  ...  |
#...

Available types and values

Type Value
checkbox TRUE/FALSE
text field Any string
drop down Option label
rich text Any string
radio group Option label
text area Any string
pathfield Path to node based on the nodes displayed in Select Path window: /node1/node2/node3
tags Tag location in Tag window in following format: Namespace: Tag1/Tag2/Tag3

Steps implementation

@Inject
private ComponentConfigurerFactory componentConfigurerFactory;
//...
@And("^I configure component using my component configuration data$")
public void I_configure_component_using_my_component_configuration_data(List<ConfigurationEntry> config) {
    componentConfigurerFactory.create(aemDialog).configureDialog(config);
}

Alternative methods of creating component configurations

Sometimes instead of writing data tables in the feature file:

Given my component configuration data is:
            | tab     | type                     | label                  | value               |
            | General | text area                | Text Area              | textarea            |
            | Tab1    | text field               | Text Field             | textfield           |
            | Tab1    | pathfield                | Pathfield              | Node1/Node2/Node3   |
            | Tab2    | dropdown                 | Dropdown               | dropdown            |

we want to simply state something like:

Given I configure my component with "valid" configuration data

Two utilities were added to allow such steps defined easily: ComponentConfigBuilder and JsonToComponentConfig.

ComponentConfigBuilder

To create the configuration in the code, it is possible to use ComponentConfigBuilder. It is a utility based on the Builder pattern, to obtain the configuration invoke the build() method. The default tab is assumed to be "General" - to change the tab for set of fields, use setTab().

Example of usage

List<ConfigurationEntry> config = new ComponentConfigBuilder()
             .addTextArea("Text Area", "textarea")
             .setTab("Tab1")
             .addTextField("Text Field", "textfield")
             .addPathfield("Pathfield", "Node1/Node2/Node3")
             .setTab("Tab2")
             .addDropdown("Dropdown", "dropdown")
             .setTab("Tab3")
             .addCheckbox("Checkbox", "TRUE")
             .setTab("Tab4")
             .addRichText("Rich Text", "richtext")
             .addTags("Tags", "Namespace:Tag1/Tag2")
             .addRadioGroup("Radio Group", "radiogroup")
             .addItemInMultifield("Multifield", 1, DialogFields.RADIO_GROUP, "Radio Group", "radiogroup")
             .addItemInFieldset("Fieldset", DialogFields.RADIO_GROUP, "Radio Group", "radiogroup")
             .build();

JSON configurations

Alternatively, to not keep the configurations for components in the code, we can provide them in JSON files and read in step definitions using JsonToComponentConfig utility. It assumes that configurations are located under /resources/component-configs/ path.

Example of usage

 {
  "component": "Component",
  "name": "Example",
  "config": [
    {
      "tab": "General",
      "type": "text area",
      "label": "Text Area",
      "value": "textarea"
    },
    {
      "tab": "Tab1",
      "type": "text field",
      "label": "Text Field",
      "value": "textfield"
    },
    {
      "tab": "Tab1",
      "type": "pathfield",
      "label": "Pathfield",
      "value": "Node1/Node2/Node3"
    },
    {
      "tab": "Tab2",
      "type": "dropdown",
      "label": "Dropdown",
      "value": "dropdown"
    }
  ]
}

Step definition:

@When("^I use the \"([^\"]*)\" configuration from JSON$")
public void I_use_the_configuration_from_JSON(String configName) {
    ComponentConfig config = new JsonToComponentConfig().readConfig(configName);
    scenarioContext.add(configName, config.getConfig());
}

Complex fields

For complex fields handling information please refer to:

Getting started with Bobcat

  1. Getting started

AEM Related Features

  1. Authoring tutorial - Classic
  1. AEM Classic Authoring Advanced usage
  1. Authoring tutorial - Touch UI
Clone this wiki locally