use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class MockContextAwareConfig method writeConfiguration.
/**
* Writes configuration parameters using the primary configured persistence
* provider.
* @param context Sling context
* @param contextPath Configuration id
* @param configName Config name
* @param values Configuration values
*/
public static void writeConfiguration(SlingContextImpl context, String contextPath, String configName, Map<String, Object> values) {
ConfigurationManager configManager = context.getService(ConfigurationManager.class);
Resource contextResource = context.resourceResolver().getResource(contextPath);
configManager.persistConfiguration(contextResource, configName, new ConfigurationPersistData(values));
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class MockContextAwareConfig method writeConfigurationCollection.
/**
* Writes a collection of configuration parameters using the primary
* configured persistence provider.
* @param context Sling context
* @param contextPath Configuration id
* @param configName Config name
* @param values Configuration values
*/
public static void writeConfigurationCollection(SlingContextImpl context, String contextPath, String configName, Collection<Map<String, Object>> values) {
ConfigurationManager configManager = context.getService(ConfigurationManager.class);
Resource contextResource = context.resourceResolver().getResource(contextPath);
List<ConfigurationPersistData> items = new ArrayList<>();
int index = 0;
for (Map<String, Object> map : values) {
items.add(new ConfigurationPersistData(map).collectionItemName("item" + (index++)));
}
configManager.persistConfigurationCollection(contextResource, configName, new ConfigurationCollectionPersistData(items));
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class ConfigurationManagerIT method testWriteConfig.
@Test
public void testWriteConfig() throws Exception {
// write configuration data via configuration manager
Map<String, Object> values = new HashMap<>();
values.put("stringParam", "valueA");
values.put("stringParamDefault", "valueB");
values.put("intParam", 55);
values.put("boolParam", true);
configManager.persistConfiguration(resourcePage1, CONFIG_NAME, new ConfigurationPersistData(values));
resourceResolver.commit();
// read config via configuration resolver
SimpleConfig config = configResolver.get(resourcePage1).as(SimpleConfig.class);
assertNotNull(config);
assertEquals("valueA", config.stringParam());
assertEquals("valueB", config.stringParamDefault());
assertEquals(55, (int) config.intParam());
assertEquals(true, config.boolParam());
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class ConfigurationPersistenceStrategyMultiplexerImplTest method testWithDefaultStrategy.
@Test
public void testWithDefaultStrategy() {
context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy());
assertSame(resource1, underTest.getResource(resource1));
assertEquals(resource1.getPath(), underTest.getResourcePath(resource1.getPath()));
assertTrue(underTest.persistConfiguration(context.resourceResolver(), "/conf/test1", new ConfigurationPersistData(resource1.getValueMap())));
assertTrue(underTest.persistConfigurationCollection(context.resourceResolver(), "/conf/testCol", new ConfigurationCollectionPersistData(ImmutableList.of(new ConfigurationPersistData(resource1.getValueMap()).collectionItemName(resource1.getName()), new ConfigurationPersistData(resource2.getValueMap()).collectionItemName(resource2.getName())))));
assertTrue(underTest.deleteConfiguration(context.resourceResolver(), "/conf/test1"));
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class ConfigurationPersistenceStrategyMultiplexerImplTest method testWithNoStrategies.
@Test
public void testWithNoStrategies() {
assertNull(underTest.getResource(resource1));
assertNull(underTest.getResourcePath(resource1.getPath()));
assertFalse(underTest.persistConfiguration(context.resourceResolver(), "/conf/test1", new ConfigurationPersistData(resource1.getValueMap())));
assertFalse(underTest.persistConfigurationCollection(context.resourceResolver(), "/conf/testCol", new ConfigurationCollectionPersistData(ImmutableList.of(new ConfigurationPersistData(resource1.getValueMap()).collectionItemName(resource1.getName()), new ConfigurationPersistData(resource2.getValueMap()).collectionItemName(resource2.getName())))));
assertFalse(underTest.deleteConfiguration(context.resourceResolver(), "/conf/test1"));
}
Aggregations