Search in sources :

Example 1 with ConfigurationResolver

use of org.apache.sling.caconfig.ConfigurationResolver in project sling by apache.

the class ConfigurationResolverValueMapIT method testNonExistingConfig.

@Test
public void testNonExistingConfig() throws Exception {
    Resource resourcePage1 = resourceBuilder.resource(PAGE_PATH).getCurrentParent();
    ConfigurationResolver configResolver = teleporter.getService(ConfigurationResolver.class);
    ValueMap props = configResolver.get(resourcePage1).name("test").asValueMap();
    assertNotNull(props);
    assertNull(props.get("stringParam", String.class));
    assertEquals(0, (int) props.get("intParam", 0));
    assertEquals(false, props.get("boolParam", false));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ConfigurationResolver(org.apache.sling.caconfig.ConfigurationResolver) Test(org.junit.Test)

Example 2 with ConfigurationResolver

use of org.apache.sling.caconfig.ConfigurationResolver 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 3 with ConfigurationResolver

use of org.apache.sling.caconfig.ConfigurationResolver 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 4 with ConfigurationResolver

use of org.apache.sling.caconfig.ConfigurationResolver in project sling by apache.

the class ConfigurationResolverValueMapIT 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);
    ValueMap props = configResolver.get(resourcePage1).name("test").asValueMap();
    assertNotNull(props);
    assertEquals("value1", props.get("stringParam", String.class));
    assertEquals(123, (int) props.get("intParam", 0));
    assertEquals(true, props.get("boolParam", false));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) Resource(org.apache.sling.api.resource.Resource) ConfigurationResolver(org.apache.sling.caconfig.ConfigurationResolver) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)4 ConfigurationResolver (org.apache.sling.caconfig.ConfigurationResolver)4 Test (org.junit.Test)4 ValueMap (org.apache.sling.api.resource.ValueMap)2 SimpleConfig (org.apache.sling.caconfig.it.example.SimpleConfig)2