Search in sources :

Example 1 with ConfigurationBuilder

use of org.apache.sling.caconfig.ConfigurationBuilder in project sling by apache.

the class ConfigurationResolverAdaptableTest method testAdaptToConfigurationBuilder.

@Test
public void testAdaptToConfigurationBuilder() {
    context.build().resource("/conf/content/site1/sling:configs/sampleName");
    // make sure not endless loop occurs
    ConfigurationBuilder model = underTest.get(site1Page1).name("sampleName").asAdaptable(ConfigurationBuilder.class);
    assertNull(model);
}
Also used : ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) Test(org.junit.Test)

Example 2 with ConfigurationBuilder

use of org.apache.sling.caconfig.ConfigurationBuilder in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class PageImpl method getHtmlPageItems.

@Override
@NotNull
public List<HtmlPageItem> getHtmlPageItems() {
    if (htmlPageItems == null) {
        htmlPageItems = new LinkedList<>();
        ConfigurationBuilder configurationBuilder = configurationResolver.get(resource);
        HtmlPageItemsConfig config = configurationBuilder.as(HtmlPageItemsConfig.class);
        for (HtmlPageItemConfig itemConfig : config.items()) {
            HtmlPageItem item = new HtmlPageItemImpl(StringUtils.defaultString(config.prefixPath()), itemConfig);
            if (item.getElement() != null) {
                htmlPageItems.add(item);
            }
        }
        // Support the former node structure: see com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig
        if (htmlPageItems.isEmpty()) {
            Resource configResource = configurationResourceResolver.getResource(resource, "sling:configs", HtmlPageItemsConfig.class.getName());
            if (configResource != null) {
                ValueMap properties = configResource.getValueMap();
                for (Resource child : configResource.getChildren()) {
                    HtmlPageItem item = new HtmlPageItemImpl(properties.get(HtmlPageItemsConfig.PN_PREFIX_PATH, StringUtils.EMPTY), child);
                    if (item.getElement() != null) {
                        htmlPageItems.add(item);
                    }
                }
            }
        }
    }
    return htmlPageItems;
}
Also used : ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) HtmlPageItemsConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig) HtmlPageItemConfig(com.adobe.cq.wcm.core.components.config.HtmlPageItemConfig) HtmlPageItem(com.adobe.cq.wcm.core.components.models.HtmlPageItem) ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ConfigurationBuilder

use of org.apache.sling.caconfig.ConfigurationBuilder in project aem-core-wcm-components by Adobe-Marketing-Cloud.

the class Utils method enableDataLayer.

/**
 * Sets the data layer context aware configuration of the AEM test context to enabled/disabled
 *
 * @param context The AEM test context
 * @param enabled {@code true} to enable the data layer, {@code false} to disable it
 */
public static void enableDataLayer(AemContext context, boolean enabled) {
    ConfigurationBuilder builder = Mockito.mock(ConfigurationBuilder.class);
    DataLayerConfig dataLayerConfig = Mockito.mock(DataLayerConfig.class);
    lenient().when(dataLayerConfig.enabled()).thenReturn(enabled);
    lenient().when(builder.as(DataLayerConfig.class)).thenReturn(dataLayerConfig);
    context.registerAdapter(Resource.class, ConfigurationBuilder.class, builder);
}
Also used : ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) DataLayerConfig(com.adobe.cq.wcm.core.components.internal.DataLayerConfig)

Example 4 with ConfigurationBuilder

use of org.apache.sling.caconfig.ConfigurationBuilder in project sling by apache.

the class ConfigurationBuilderAdapterFactoryTest method testGetAdapter.

@Test
public void testGetAdapter() {
    ConfigurationBuilder cfgBuilder = site1Page1.adaptTo(ConfigurationBuilder.class);
    SimpleConfig cfg = cfgBuilder.as(SimpleConfig.class);
    assertEquals("configValue1", cfg.stringParam());
    assertEquals(111, cfg.intParam());
    assertEquals(true, cfg.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) Test(org.junit.Test)

Aggregations

ConfigurationBuilder (org.apache.sling.caconfig.ConfigurationBuilder)4 Test (org.junit.Test)2 HtmlPageItemConfig (com.adobe.cq.wcm.core.components.config.HtmlPageItemConfig)1 HtmlPageItemsConfig (com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig)1 DataLayerConfig (com.adobe.cq.wcm.core.components.internal.DataLayerConfig)1 HtmlPageItem (com.adobe.cq.wcm.core.components.models.HtmlPageItem)1 Resource (org.apache.sling.api.resource.Resource)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 SimpleConfig (org.apache.sling.caconfig.example.SimpleConfig)1 NotNull (org.jetbrains.annotations.NotNull)1