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;
}
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());
}
}
}
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());
}
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());
}
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);
}
Aggregations