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