Search in sources :

Example 16 with ConfigurationMetadata

use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.

the class ConfigurationManagerImplTest method testGetConfigurationMetadata_Nested_SubList.

@Test
public void testGetConfigurationMetadata_Nested_SubList() {
    ConfigurationMetadata configMetadataSubList = underTest.getConfigurationMetadata(getConfigResolvePath(CONFIG_NESTED_NAME) + "/propSubList");
    assertNotNull(configMetadataSubList);
    assertEquals("propSubList", configMetadataSubList.getName());
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 17 with ConfigurationMetadata

use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.

the class ConfigurationMetadataProviderMultiplexerImplTest method testWithTwoProviders.

@Test
public void testWithTwoProviders() {
    registerConfigurationMetadataProvider("test1");
    registerConfigurationMetadataProvider("test2");
    SortedSet<String> configNames = underTest.getConfigurationNames();
    assertEquals(ImmutableSortedSet.of("test1", "test2"), configNames);
    ConfigurationMetadata configMetadata = underTest.getConfigurationMetadata("test1");
    assertEquals("test1", configMetadata.getName());
    configMetadata = underTest.getConfigurationMetadata("test2");
    assertEquals("test2", configMetadata.getName());
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 18 with ConfigurationMetadata

use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.

the class ConfigurationManagerImplTest method testGetConfigurationMetadata_Nested.

@Test
public void testGetConfigurationMetadata_Nested() {
    ConfigurationMetadata configMetadata = underTest.getConfigurationMetadata(CONFIG_NESTED_NAME);
    assertNotNull(configMetadata);
    assertEquals(CONFIG_NESTED_NAME, configMetadata.getName());
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 19 with ConfigurationMetadata

use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.

the class ConfigurationMetadataProviderIT method testConfigurationMetadata.

@Test
public void testConfigurationMetadata() {
    ConfigurationMetadataProvider underTest = teleporter.getService(ConfigurationMetadataProvider.class);
    ConfigurationMetadata configMetadata = underTest.getConfigurationMetadata(SimpleConfig.class.getName());
    assertNotNull(configMetadata);
    assertEquals(SimpleConfig.class.getName(), configMetadata.getName());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) ConfigurationMetadataProvider(org.apache.sling.caconfig.spi.ConfigurationMetadataProvider) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 20 with ConfigurationMetadata

use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.

the class ConfigurationBuilderImpl method applyDefaultValues.

/**
     * Apply default values from configuration metadata (where no real data is present).
     * @param props Properties
     * @param configName Configuration name
     * @return null if no default values found, or a new map with added default properties.
     */
private Map<String, Object> applyDefaultValues(Map<String, Object> props, String configName) {
    ConfigurationMetadata metadata = configurationMetadataProvider.getConfigurationMetadata(configName);
    if (metadata == null) {
        // probably a configuration list - remove item name from end
        if (StringUtils.contains(configName, "/")) {
            String partialConfigName = StringUtils.substringBeforeLast(configName, "/");
            metadata = configurationMetadataProvider.getConfigurationMetadata(partialConfigName);
        }
        if (metadata == null) {
            return null;
        }
    }
    Map<String, Object> updatedMap = new HashMap<>();
    for (PropertyMetadata<?> propertyMetadata : metadata.getPropertyMetadata().values()) {
        if (propertyMetadata.getDefaultValue() != null) {
            updatedMap.put(propertyMetadata.getName(), propertyMetadata.getDefaultValue());
        }
    }
    if (updatedMap.isEmpty()) {
        return null;
    }
    updatedMap.putAll(props);
    return updatedMap;
}
Also used : HashMap(java.util.HashMap) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)

Aggregations

ConfigurationMetadata (org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)33 Test (org.junit.Test)17 PropertyMetadata (org.apache.sling.caconfig.spi.metadata.PropertyMetadata)9 Before (org.junit.Before)5 AnnotationClassParser.buildConfigurationMetadata (org.apache.sling.caconfig.impl.metadata.AnnotationClassParser.buildConfigurationMetadata)4 ConfigurationData (org.apache.sling.caconfig.management.ConfigurationData)4 ConfigurationMetadataProvider (org.apache.sling.caconfig.spi.ConfigurationMetadataProvider)3 HashMap (java.util.HashMap)2 ResettableIterator (org.apache.commons.collections.ResettableIterator)2 ListIteratorWrapper (org.apache.commons.collections.iterators.ListIteratorWrapper)2 Resource (org.apache.sling.api.resource.Resource)2 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 SortedSet (java.util.SortedSet)1 Configuration (org.apache.sling.caconfig.annotation.Configuration)1 Property (org.apache.sling.caconfig.annotation.Property)1 AllTypesConfig (org.apache.sling.caconfig.example.AllTypesConfig)1