Search in sources :

Example 1 with SimpleConfig

use of org.apache.sling.caconfig.it.example.SimpleConfig in project sling by apache.

the class AdaptToConfigClassIT method testExistingConfig.

@Test
public void testExistingConfig() throws Exception {
    resourceBuilder.resource(CONFIG_PATH + "/sling:configs/org.apache.sling.caconfig.it.example.SimpleConfig", "stringParam", "value1", "intParam", 123, "boolParam", true).resource(PAGE_PATH, "sling:configRef", CONFIG_PATH);
    Resource resourcePage1 = resourceResolver.getResource(PAGE_PATH);
    SimpleConfig config = resourcePage1.adaptTo(ConfigurationBuilder.class).as(SimpleConfig.class);
    assertNotNull(config);
    assertEquals("value1", config.stringParam());
    assertEquals(123, (int) config.intParam());
    assertEquals(true, config.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 2 with SimpleConfig

use of org.apache.sling.caconfig.it.example.SimpleConfig in project sling by apache.

the class ConfigurationManagerIT method testWriteConfigCollection.

@Test
public void testWriteConfigCollection() throws Exception {
    // write configuration data via configuration manager
    Map<String, Object> values1 = new HashMap<>();
    values1.put("stringParam", "valueA");
    values1.put("stringParamDefault", "valueB");
    Map<String, Object> values2 = new HashMap<>();
    values2.put("intParam", 55);
    values2.put("boolParam", true);
    List<ConfigurationPersistData> items = new ArrayList<>();
    items.add(new ConfigurationPersistData(values1).collectionItemName("item1"));
    items.add(new ConfigurationPersistData(values2).collectionItemName("item2"));
    configManager.persistConfigurationCollection(resourcePage1, CONFIG_NAME, new ConfigurationCollectionPersistData(items));
    resourceResolver.commit();
    // read config via configuration resolver
    Collection<SimpleConfig> config = configResolver.get(resourcePage1).asCollection(SimpleConfig.class);
    assertEquals(2, config.size());
    Iterator<SimpleConfig> configIterator = config.iterator();
    SimpleConfig config1 = configIterator.next();
    SimpleConfig config2 = configIterator.next();
    assertEquals("valueA", config1.stringParam());
    assertEquals("valueB", config1.stringParamDefault());
    assertEquals(55, (int) config2.intParam());
    assertEquals(true, config2.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) HashMap(java.util.HashMap) ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) ConfigurationCollectionPersistData(org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with SimpleConfig

use of org.apache.sling.caconfig.it.example.SimpleConfig in project sling by apache.

the class ConfigurationResolverConfigClassIT method testExistingConfig.

@Test
public void testExistingConfig() throws Exception {
    resourceBuilder.resource(CONFIG_PATH + "/sling:configs/test", "stringParam", "value1", "intParam", 123, "boolParam", true).resource(PAGE_PATH, "sling:configRef", CONFIG_PATH);
    Resource resourcePage1 = resourceResolver.getResource(PAGE_PATH);
    ConfigurationResolver configResolver = teleporter.getService(ConfigurationResolver.class);
    SimpleConfig config = configResolver.get(resourcePage1).name("test").as(SimpleConfig.class);
    assertNotNull(config);
    assertEquals("value1", config.stringParam());
    assertEquals("defValue", config.stringParamDefault());
    assertEquals(123, (int) config.intParam());
    assertEquals(true, config.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) Resource(org.apache.sling.api.resource.Resource) ConfigurationResolver(org.apache.sling.caconfig.ConfigurationResolver) Test(org.junit.Test)

Example 4 with SimpleConfig

use of org.apache.sling.caconfig.it.example.SimpleConfig in project sling by apache.

the class ConfigurationResolverConfigClassIT method testNonExistingConfig.

@Test
public void testNonExistingConfig() throws Exception {
    Resource resourcePage1 = resourceBuilder.resource(PAGE_PATH).getCurrentParent();
    ConfigurationResolver configResolver = teleporter.getService(ConfigurationResolver.class);
    SimpleConfig config = configResolver.get(resourcePage1).name("test").as(SimpleConfig.class);
    assertNotNull(config);
    assertNull(config.stringParam());
    assertEquals("defValue", config.stringParamDefault());
    assertEquals(0, config.intParam());
    assertEquals(false, config.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) Resource(org.apache.sling.api.resource.Resource) ConfigurationResolver(org.apache.sling.caconfig.ConfigurationResolver) Test(org.junit.Test)

Example 5 with SimpleConfig

use of org.apache.sling.caconfig.it.example.SimpleConfig in project sling by apache.

the class AdaptToConfigClassIT method testNonExistingConfig.

@Test
public void testNonExistingConfig() throws Exception {
    Resource resourcePage1 = resourceBuilder.resource(PAGE_PATH).getCurrentParent();
    SimpleConfig config = resourcePage1.adaptTo(ConfigurationBuilder.class).as(SimpleConfig.class);
    assertNotNull(config);
    assertNull(config.stringParam());
    assertEquals(0, config.intParam());
    assertEquals(false, config.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.it.example.SimpleConfig) ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) Resource(org.apache.sling.api.resource.Resource) 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