Search in sources :

Example 11 with ConfigurationMetadata

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

the class ConfigurationMetadataProviderMultiplexerImplTest method testWithOneProvider.

@Test
public void testWithOneProvider() {
    registerConfigurationMetadataProvider("test1", "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 12 with ConfigurationMetadata

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

the class CAConfigInventoryPrinterTest method setUp.

@Before
public void setUp() {
    context.registerService(ConfigurationMetadataProvider.class, configurationMetadataProvider);
    context.registerService(ConfigurationOverrideProvider.class, configurationOverrideProvider);
    ConfigurationTestUtils.registerConfigurationResolver(context);
    underTest = context.registerInjectActivateService(new CAConfigInventoryPrinter());
    ConfigurationMetadata configMetadata = new ConfigurationMetadata(SAMPLE_CONFIG_NAME, ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValue"), new PropertyMetadata<>("prop2", String.class), new PropertyMetadata<>("prop3", 5)), false);
    when(configurationMetadataProvider.getConfigurationMetadata(SAMPLE_CONFIG_NAME)).thenReturn(configMetadata);
    when(configurationMetadataProvider.getConfigurationNames()).thenReturn(ImmutableSortedSet.of(SAMPLE_CONFIG_NAME));
    when(configurationOverrideProvider.getOverrideStrings()).thenReturn(ImmutableList.of(SAMPLE_OVERRIDE_STRING));
}
Also used : PropertyMetadata(org.apache.sling.caconfig.spi.metadata.PropertyMetadata) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Before(org.junit.Before)

Example 13 with ConfigurationMetadata

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

the class ConfigurationManagerImplTest method setUp.

@Before
public void setUp() {
    context.registerService(ConfigurationMetadataProvider.class, configurationMetadataProvider);
    ConfigurationTestUtils.registerConfigurationResolver(context, "configBucketNames", getAlternativeBucketNames());
    underTest = context.registerInjectActivateService(new ConfigurationManagerImpl());
    contextResource = context.create().resource("/content/test", PROPERTY_CONFIG_REF, "/conf/test");
    contextResourceLevel2 = context.create().resource("/content/test/level2", PROPERTY_CONFIG_REF, "/conf/test/level2");
    contextResourceLevel3 = context.create().resource("/content/test/level2/level3", PROPERTY_CONFIG_REF, "/conf/test/level2/level3");
    contextResourceNoConfig = context.create().resource("/content/testNoConfig", PROPERTY_CONFIG_REF, "/conf/testNoConfig");
    context.create().resource(getConfigResolvePath("/conf/test/sling:configs/" + CONFIG_NAME), "prop1", "value1", "prop4", true);
    context.create().resource(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/sling:configs/" + CONFIG_COL_NAME) + "/1"), "prop1", "value1");
    context.create().resource(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/sling:configs/" + CONFIG_COL_NAME) + "/2"), "prop4", true);
    // test fixture with resource collection inheritance on level 2
    context.create().resource(getConfigCollectionParentResolvePath("/conf/test/level2/sling:configs/" + CONFIG_COL_NAME), PROPERTY_CONFIG_COLLECTION_INHERIT, true);
    context.create().resource(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/level2/sling:configs/" + CONFIG_COL_NAME) + "/1"), "prop1", "value1_level2");
    // test fixture with property inheritance and resource collection inheritance on level 3
    context.create().resource(getConfigResolvePath("/conf/test/level2/level3/sling:configs/" + CONFIG_NAME), "prop4", false, "prop5", "value5_level3", PROPERTY_CONFIG_PROPERTY_INHERIT, true);
    context.create().resource(getConfigCollectionParentResolvePath("/conf/test/level2/level3/sling:configs/" + CONFIG_COL_NAME), PROPERTY_CONFIG_COLLECTION_INHERIT, true);
    context.create().resource(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/level2/level3/sling:configs/" + CONFIG_COL_NAME) + "/1"), "prop4", false, "prop5", "value5_level3", PROPERTY_CONFIG_PROPERTY_INHERIT, true);
    // test fixture nested configuration
    context.create().resource(getConfigResolvePath("/conf/test/level2/sling:configs/" + CONFIG_NESTED_NAME), "prop1", "value1", "prop4", true);
    context.create().resource(getConfigResolvePath(getConfigResolvePath("/conf/test/sling:configs/" + CONFIG_NESTED_NAME) + "/propSub"), "prop1", "propSubValue1", "prop4", true);
    context.create().resource(getConfigResolvePath(getConfigResolvePath(getConfigResolvePath("/conf/test/sling:configs/" + CONFIG_NESTED_NAME) + "/propSub") + "/propSubLevel2"), "prop1", "propSubLevel2Value1", "prop4", true);
    context.create().resource(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath(getConfigResolvePath("/conf/test/level2/sling:configs/" + CONFIG_NESTED_NAME) + "/propSubList") + "/item1"), "prop1", "propSubListValue1.1");
    context.create().resource(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath(getConfigResolvePath("/conf/test/level2/sling:configs/" + CONFIG_NESTED_NAME) + "/propSubList") + "/item2"), "prop1", "propSubListValue1.2");
    context.create().resource(getConfigResolvePath(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath(getConfigResolvePath("/conf/test/sling:configs/" + CONFIG_NESTED_NAME) + "/propSubList") + "/item1") + "/propSub"), "prop1", "propSubList1_proSubValue1", "prop4", true);
    // config metadata singleton config
    ConfigurationMetadata configMetadata = new ConfigurationMetadata(CONFIG_NAME, ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValue"), new PropertyMetadata<>("prop2", String.class), new PropertyMetadata<>("prop3", 5)), false);
    when(configurationMetadataProvider.getConfigurationMetadata(CONFIG_NAME)).thenReturn(configMetadata);
    // config metadata config collection
    ConfigurationMetadata configColMetadata = new ConfigurationMetadata(CONFIG_COL_NAME, ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValue"), new PropertyMetadata<>("prop2", String.class), new PropertyMetadata<>("prop3", 5)), true);
    when(configurationMetadataProvider.getConfigurationMetadata(CONFIG_COL_NAME)).thenReturn(configColMetadata);
    // config metadata nested config
    /*
         * testConfigNested
         *  |
         *  +- propSub
         *  |   |
         *  |   +- propSubLevel2
         *  |
         *  +- propSubList
         *      |
         *      +- <collection>
         *          |
         *          +- propSub
         *              |
         *              +- propSubLevel2
         */
    ConfigurationMetadata propSubLevel2Metadata = new ConfigurationMetadata("propSubLevel2", ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValueLevel2")), false);
    ConfigurationMetadata propSubMetadata = new ConfigurationMetadata("propSub", ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValue"), new PropertyMetadata<>("prop2", String.class), new PropertyMetadata<>("prop3", 5), new PropertyMetadata<>("propSubLevel2", ConfigurationMetadata.class).configurationMetadata(propSubLevel2Metadata)), false);
    ConfigurationMetadata propSubListMetadata = new ConfigurationMetadata("propSubList", ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValueSubList"), new PropertyMetadata<>("propSub", ConfigurationMetadata.class).configurationMetadata(propSubMetadata)), true);
    ConfigurationMetadata configNestedMetadata = new ConfigurationMetadata(CONFIG_NESTED_NAME, ImmutableList.<PropertyMetadata<?>>of(new PropertyMetadata<>("prop1", "defValue"), new PropertyMetadata<>("propSub", ConfigurationMetadata.class).configurationMetadata(propSubMetadata), new PropertyMetadata<>("propSubList", ConfigurationMetadata[].class).configurationMetadata(propSubListMetadata)), false);
    when(configurationMetadataProvider.getConfigurationMetadata(CONFIG_NESTED_NAME)).thenReturn(configNestedMetadata);
    when(configurationMetadataProvider.getConfigurationNames()).thenReturn(ImmutableSortedSet.of(CONFIG_NAME, CONFIG_COL_NAME, CONFIG_NESTED_NAME));
}
Also used : PropertyMetadata(org.apache.sling.caconfig.spi.metadata.PropertyMetadata) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Before(org.junit.Before)

Example 14 with ConfigurationMetadata

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

the class ConfigurationManagerImplTest method testGetConfigurationNested_NoConfigResource.

@Test
public void testGetConfigurationNested_NoConfigResource() {
    ConfigurationData configData = underTest.getConfiguration(contextResourceNoConfig, CONFIG_NESTED_NAME);
    assertNotNull(configData);
    assertEquals(ImmutableSet.of("prop1", "propSub", "propSubList"), configData.getPropertyNames());
    assertNull(configData.getValues().get("prop1", String.class));
    assertEquals("defValue", configData.getEffectiveValues().get("prop1", String.class));
    assertEquals(ConfigurationMetadata.class, configData.getValueInfo("propSub").getPropertyMetadata().getType());
    assertEquals(ConfigurationMetadata[].class, configData.getValueInfo("propSubList").getPropertyMetadata().getType());
    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("defValue", subData.getEffectiveValues().get("prop1", String.class));
    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(0, subListData.length);
}
Also used : ConfigurationData(org.apache.sling.caconfig.management.ConfigurationData) ConfigurationMetadata(org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 15 with ConfigurationMetadata

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

the class ConfigurationManagerImplTest method testGetConfigurationMetadata_Nested_SubList_Sub.

@Test
public void testGetConfigurationMetadata_Nested_SubList_Sub() 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 subListDataItem1Sub = underTest.getConfigurationMetadata(getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath(getConfigResolvePath(CONFIG_NESTED_NAME) + "/propSubList") + "/item1") + "/propSub");
    assertNotNull(subListDataItem1Sub);
    assertEquals("propSub", subListDataItem1Sub.getName());
}
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