Search in sources :

Example 6 with ConfigurationMetadata

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

the class ConfigurationManagerImpl method getConfigurationMetadata.

@Override
public ConfigurationMetadata getConfigurationMetadata(String configName) {
    ConfigNameUtil.ensureValidConfigName(configName);
    ConfigurationMetadata metadata = configurationMetadataProvider.getConfigurationMetadata(configName);
    if (metadata != null) {
        log.trace("+ Configuration metadata found for: {}", configName);
        return metadata;
    }
    // if no metadata found with direct match try to resolve nested configuration metadata references
    for (String partialConfigName : ConfigNameUtil.getAllPartialConfigNameVariations(configName)) {
        ConfigurationMetadata partialConfigMetadata = getConfigurationMetadata(partialConfigName);
        if (partialConfigMetadata != null) {
            ConfigurationMetadata nestedConfigMetadata = getNestedConfigurationMetadata(partialConfigMetadata, configName, partialConfigName);
            if (nestedConfigMetadata != null) {
                log.trace("+ Nested configuration metadata found for: {}", configName);
                return nestedConfigMetadata;
            }
        }
    }
    log.trace("- No configuration metadata found for: {}", configName);
    return null;
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata)

Example 7 with ConfigurationMetadata

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

the class AnnotationClassParserTest method testBuildConfigurationMetadata_Nested.

@Test
public void testBuildConfigurationMetadata_Nested() {
    ConfigurationMetadata metadata = buildConfigurationMetadata(NestedConfig.class);
    assertEquals(NestedConfig.class.getName(), metadata.getName());
    Collection<PropertyMetadata<?>> propertyMetadataList = metadata.getPropertyMetadata().values();
    assertEquals(4, propertyMetadataList.size());
    for (PropertyMetadata<?> propertyMetadata : propertyMetadataList) {
        if (StringUtils.equals(propertyMetadata.getName(), "stringParam")) {
            assertEquals(String.class, propertyMetadata.getType());
        } else if (StringUtils.equals(propertyMetadata.getName(), "subConfig")) {
            assertEquals(ConfigurationMetadata.class, propertyMetadata.getType());
            ConfigurationMetadata subConfigMetadata = propertyMetadata.getConfigurationMetadata();
            assertEquals("subConfig", subConfigMetadata.getName());
            assertEquals(3, subConfigMetadata.getPropertyMetadata().size());
        } else if (StringUtils.equals(propertyMetadata.getName(), "subListConfig")) {
            assertEquals(ConfigurationMetadata[].class, propertyMetadata.getType());
            ConfigurationMetadata subListConfigMetadata = propertyMetadata.getConfigurationMetadata();
            assertEquals("subListConfig", subListConfigMetadata.getName());
            assertEquals(2, subListConfigMetadata.getPropertyMetadata().size());
        } else if (StringUtils.equals(propertyMetadata.getName(), "subConfigWithoutAnnotation")) {
            assertEquals(ConfigurationMetadata.class, propertyMetadata.getType());
            ConfigurationMetadata subConfigWithoutAnnotationMetadata = propertyMetadata.getConfigurationMetadata();
            assertEquals("subConfigWithoutAnnotation", subConfigWithoutAnnotationMetadata.getName());
            assertEquals(1, subConfigWithoutAnnotationMetadata.getPropertyMetadata().size());
        } else {
            fail("Unexpected property name: " + propertyMetadata.getName());
        }
    }
}
Also used : PropertyMetadata(org.apache.sling.caconfig.spi.metadata.PropertyMetadata) NestedConfig(org.apache.sling.caconfig.example.NestedConfig) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) AnnotationClassParser.buildConfigurationMetadata(org.apache.sling.caconfig.impl.metadata.AnnotationClassParser.buildConfigurationMetadata) Test(org.junit.Test)

Example 8 with ConfigurationMetadata

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

the class AnnotationClassParserTest method testBuildConfigurationMetadata_List.

@Test
public void testBuildConfigurationMetadata_List() {
    ConfigurationMetadata metadata = buildConfigurationMetadata(ListConfig.class);
    assertEquals(ListConfig.class.getName(), metadata.getName());
    assertTrue(metadata.isCollection());
}
Also used : ListConfig(org.apache.sling.caconfig.example.ListConfig) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) AnnotationClassParser.buildConfigurationMetadata(org.apache.sling.caconfig.impl.metadata.AnnotationClassParser.buildConfigurationMetadata) Test(org.junit.Test)

Example 9 with ConfigurationMetadata

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

the class AnnotationClassParserTest method testBuildConfigurationMetadata_Simple.

@Test
public void testBuildConfigurationMetadata_Simple() {
    ConfigurationMetadata metadata = buildConfigurationMetadata(MetadataSimpleConfig.class);
    assertEquals("simpleConfig", metadata.getName());
    assertEquals("Simple configuration", metadata.getLabel());
    assertEquals("This is a configuration example with additional metadata.", metadata.getDescription());
    assertEquals(ImmutableMap.of("param1", "value1", "param2", "123"), metadata.getProperties());
    assertFalse(metadata.isCollection());
    List<PropertyMetadata<?>> propertyMetadataList = ImmutableList.copyOf(metadata.getPropertyMetadata().values());
    assertEquals(3, propertyMetadataList.size());
    PropertyMetadata<?> stringParam = propertyMetadataList.get(0);
    assertEquals("String Param", stringParam.getLabel());
    assertEquals("Enter strings here.", stringParam.getDescription());
    assertEquals(ImmutableMap.of("p1", "v1"), stringParam.getProperties());
    assertNull(stringParam.getDefaultValue());
    PropertyMetadata<?> intParam = propertyMetadataList.get(1);
    assertEquals("Integer Param", intParam.getLabel());
    assertNull(intParam.getDescription());
    assertTrue(intParam.getProperties().isEmpty());
    assertEquals(5, intParam.getDefaultValue());
    PropertyMetadata<?> boolParam = propertyMetadataList.get(2);
    assertNull(boolParam.getLabel());
    assertNull(boolParam.getDescription());
    assertTrue(boolParam.getProperties().isEmpty());
    assertNull(boolParam.getDefaultValue());
}
Also used : PropertyMetadata(org.apache.sling.caconfig.spi.metadata.PropertyMetadata) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) AnnotationClassParser.buildConfigurationMetadata(org.apache.sling.caconfig.impl.metadata.AnnotationClassParser.buildConfigurationMetadata) Test(org.junit.Test)

Example 10 with ConfigurationMetadata

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

the class ConfigurationMetadataProviderMultiplexerImplTest method testWithNoProvider.

@Test
public void testWithNoProvider() {
    SortedSet<String> configNames = underTest.getConfigurationNames();
    assertTrue(configNames.isEmpty());
    ConfigurationMetadata configMetadata = underTest.getConfigurationMetadata("test1");
    assertNull(configMetadata);
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

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