use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationMetadata.
@Test
public void testGetConfigurationMetadata() {
ConfigurationMetadata configMetadata = underTest.getConfigurationMetadata(CONFIG_NAME);
assertNotNull(configMetadata);
assertEquals(CONFIG_NAME, configMetadata.getName());
}
use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationNested.
@Test
public void testGetConfigurationNested() {
ConfigurationData configData = underTest.getConfiguration(contextResourceLevel2, CONFIG_NESTED_NAME);
assertNotNull(configData);
// root level
assertEquals(ImmutableSet.of("prop1", "propSub", "propSubList", "prop4"), configData.getPropertyNames());
assertEquals("value1", configData.getValues().get("prop1", String.class));
assertEquals("value1", configData.getEffectiveValues().get("prop1", String.class));
assertTrue(configData.getValues().get("prop4", false));
assertTrue(configData.getEffectiveValues().get("prop4", false));
assertEquals(ConfigurationMetadata.class, configData.getValueInfo("propSub").getPropertyMetadata().getType());
assertEquals(ConfigurationMetadata[].class, configData.getValueInfo("propSubList").getPropertyMetadata().getType());
// propSub
ConfigurationData subData = configData.getValues().get("propSub", ConfigurationData.class);
ConfigurationData subDataEffective = configData.getEffectiveValues().get("propSub", ConfigurationData.class);
assertNotNull(subData);
assertNotNull(subDataEffective);
assertTrue(ConfigurationData.class.isAssignableFrom(configData.getValueInfo("propSub").getValue().getClass()));
assertTrue(ConfigurationData.class.isAssignableFrom(configData.getValueInfo("propSub").getEffectiveValue().getClass()));
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getValue().getClass()));
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getEffectiveValue().getClass()));
assertNull(subData.getValues().get("prop1", String.class));
assertEquals("propSubValue1", subData.getEffectiveValues().get("prop1", String.class));
assertFalse(subData.getValues().get("prop4", false));
assertTrue(subData.getEffectiveValues().get("prop4", false));
// propSub/propSubLevel2
ConfigurationData subDataLevel2 = subData.getValues().get("propSubLevel2", ConfigurationData.class);
ConfigurationData subDataLevel2Effective = subData.getEffectiveValues().get("propSubLevel2", ConfigurationData.class);
assertNotNull(subDataLevel2);
assertNotNull(subDataLevel2Effective);
assertTrue(ConfigurationData.class.isAssignableFrom(subData.getValueInfo("propSubLevel2").getValue().getClass()));
assertTrue(ConfigurationData.class.isAssignableFrom(subData.getValueInfo("propSubLevel2").getEffectiveValue().getClass()));
assertNull(subDataLevel2.getValues().get("prop1", String.class));
assertEquals("propSubLevel2Value1", subDataLevel2.getEffectiveValues().get("prop1", String.class));
assertFalse(subDataLevel2.getValues().get("prop4", false));
assertTrue(subDataLevel2.getEffectiveValues().get("prop4", false));
// propSubList
ConfigurationData[] subListData = configData.getValues().get("propSubList", ConfigurationData[].class);
ConfigurationData[] subListDataEffective = configData.getEffectiveValues().get("propSubList", ConfigurationData[].class);
assertNotNull(subListData);
assertNotNull(subListDataEffective);
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getValue().getClass()));
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getEffectiveValue().getClass()));
assertEquals(2, subListData.length);
assertEquals("propSubListValue1.1", subListData[0].getValues().get("prop1", String.class));
assertEquals("propSubListValue1.1", subListData[0].getEffectiveValues().get("prop1", String.class));
assertEquals("propSubListValue1.2", subListData[1].getValues().get("prop1", String.class));
assertEquals("propSubListValue1.2", subListData[1].getEffectiveValues().get("prop1", String.class));
ConfigurationData subListDataItem1Sub = subListData[0].getValues().get("propSub", ConfigurationData.class);
ConfigurationData subListDataItem1SubEffecive = subListData[0].getEffectiveValues().get("propSub", ConfigurationData.class);
assertNotNull(subListDataItem1Sub);
assertNotNull(subListDataItem1SubEffecive);
assertNull(subListDataItem1Sub.getValues().get("prop1", String.class));
assertEquals("propSubList1_proSubValue1", subListDataItem1Sub.getEffectiveValues().get("prop1", String.class));
assertFalse(subListDataItem1Sub.getValues().get("prop4", false));
assertTrue(subListDataItem1Sub.getEffectiveValues().get("prop4", false));
}
use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationMetadata_Nested_SubList_SubLevel2.
@Test
public void testGetConfigurationMetadata_Nested_SubList_SubLevel2() throws Exception {
// delete resource already existing in test fixture to test with non-existing resource but existing collection item as parent
context.resourceResolver().delete(context.resourceResolver().getResource(getConfigResolvePath(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath(getConfigResolvePath("/conf/test/sling:configs/" + CONFIG_NESTED_NAME) + "/propSubList") + "/item1") + "/propSub")));
ConfigurationMetadata subListDataItem1SubLevel2 = underTest.getConfigurationMetadata(getConfigResolvePath(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath(getConfigResolvePath(CONFIG_NESTED_NAME) + "/propSubList") + "/item1") + "/propSub") + "/propSubLevel2");
assertNotNull(subListDataItem1SubLevel2);
assertEquals("propSubLevel2", subListDataItem1SubLevel2.getName());
}
use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationMetadata_Nested_Sub.
@Test
public void testGetConfigurationMetadata_Nested_Sub() {
ConfigurationMetadata configMetadataSub = underTest.getConfigurationMetadata(getConfigResolvePath(CONFIG_NESTED_NAME) + "/propSub");
assertNotNull(configMetadataSub);
assertEquals("propSub", configMetadataSub.getName());
}
use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationMetadataPrinter method printConfiguration.
@Override
public void printConfiguration(PrintWriter pw, ServiceReference<ConfigurationMetadataProvider> serviceReference, BundleContext bundleContext) {
ConfigurationMetadataProvider service = bundleContext.getService(serviceReference);
for (String configName : service.getConfigurationNames()) {
ConfigurationMetadata metadata = service.getConfigurationMetadata(configName);
pw.print(INDENT);
pw.print(BULLET);
pw.println(metadata.getName());
for (PropertyMetadata<?> property : metadata.getPropertyMetadata().values()) {
pw.print(INDENT_2);
pw.print(BULLET);
pw.print(property.getName());
pw.print("(");
pw.print(property.getType().getSimpleName());
pw.print(")");
if (property.getDefaultValue() != null) {
pw.print(" = ");
printValue(pw, property.getDefaultValue());
}
pw.println();
}
}
bundleContext.ungetService(serviceReference);
}
Aggregations