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