Search in sources :

Example 6 with SimpleConfig

use of org.apache.sling.caconfig.it.example.SimpleConfig 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());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) HashMap(java.util.HashMap) ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) Test(org.junit.Test)

Aggregations

SimpleConfig (org.apache.sling.caconfig.it.example.SimpleConfig)6 Test (org.junit.Test)6 Resource (org.apache.sling.api.resource.Resource)4 HashMap (java.util.HashMap)2 ConfigurationBuilder (org.apache.sling.caconfig.ConfigurationBuilder)2 ConfigurationResolver (org.apache.sling.caconfig.ConfigurationResolver)2 ConfigurationPersistData (org.apache.sling.caconfig.spi.ConfigurationPersistData)2 ArrayList (java.util.ArrayList)1 ConfigurationCollectionPersistData (org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData)1