Search in sources :

Example 26 with ConfigurationMetadata

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());
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 27 with ConfigurationMetadata

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));
}
Also used : ConfigurationData(org.apache.sling.caconfig.management.ConfigurationData) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 28 with ConfigurationMetadata

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());
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 29 with ConfigurationMetadata

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());
}
Also used : ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 30 with ConfigurationMetadata

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);
}
Also used : ConfigurationMetadataProvider(org.apache.sling.caconfig.spi.ConfigurationMetadataProvider) 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