Search in sources :

Example 16 with SimpleConfig

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

the class ConfigurationBuilderAdapterFactoryTest method testGetAdapter.

@Test
public void testGetAdapter() {
    ConfigurationBuilder cfgBuilder = site1Page1.adaptTo(ConfigurationBuilder.class);
    SimpleConfig cfg = cfgBuilder.as(SimpleConfig.class);
    assertEquals("configValue1", cfg.stringParam());
    assertEquals(111, cfg.intParam());
    assertEquals(true, cfg.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) ConfigurationBuilder(org.apache.sling.caconfig.ConfigurationBuilder) Test(org.junit.Test)

Example 17 with SimpleConfig

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

the class ConfigurationResolverCustomPersistenceTest method testConfig_SimpleWithName.

@Test
public void testConfig_SimpleWithName() {
    context.build().resource("/conf/content/site1/settings/sampleName/jcr:content", "stringParam", "configValue1.1", "intParam", 1111, "boolParam", true);
    SimpleConfig cfg = underTest.get(site1Page1).name("sampleName").as(SimpleConfig.class);
    assertEquals("configValue1.1", cfg.stringParam());
    assertEquals(1111, cfg.intParam());
    assertEquals(true, cfg.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) Test(org.junit.Test)

Example 18 with SimpleConfig

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

the class ConfigurationResolverCustomPersistence2Test method testConfig_Nested.

@Test
public void testConfig_Nested() {
    context.build().resource("/conf/content/site1/settings/org.apache.sling.caconfig.example.NestedConfig").resource("jcr:content", "stringParam", "configValue3").siblingsMode().resource("subConfig", "stringParam", "configValue4", "intParam", 444, "boolParam", true).hierarchyMode().resource("subListConfig").siblingsMode().resource("1", "stringParam", "configValue2.1").resource("2", "stringParam", "configValue2.2").resource("3", "stringParam", "configValue2.3");
    NestedConfig cfg = underTest.get(site1Page1).as(NestedConfig.class);
    assertEquals("configValue3", cfg.stringParam());
    SimpleConfig subConfig = cfg.subConfig();
    assertEquals("configValue4", subConfig.stringParam());
    assertEquals(444, subConfig.intParam());
    assertEquals(true, subConfig.boolParam());
    ListConfig[] listConfig = cfg.subListConfig();
    assertEquals(3, listConfig.length);
    assertEquals("configValue2.1", listConfig[0].stringParam());
    assertEquals("configValue2.2", listConfig[1].stringParam());
    assertEquals("configValue2.3", listConfig[2].stringParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) NestedConfig(org.apache.sling.caconfig.example.NestedConfig) ListConfig(org.apache.sling.caconfig.example.ListConfig) Test(org.junit.Test)

Example 19 with SimpleConfig

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

the class ConfigurationResolverCustomPersistenceTest method testConfig_Nested.

@Test
public void testConfig_Nested() {
    context.build().resource("/conf/content/site1/settings/org.apache.sling.caconfig.example.NestedConfig").resource("jcr:content", "stringParam", "configValue3").siblingsMode().resource("subConfig/jcr:content", "stringParam", "configValue4", "intParam", 444, "boolParam", true).hierarchyMode().resource("subListConfig").siblingsMode().resource("1/jcr:content", "stringParam", "configValue2.1").resource("2/jcr:content", "stringParam", "configValue2.2").resource("3/jcr:content", "stringParam", "configValue2.3");
    NestedConfig cfg = underTest.get(site1Page1).as(NestedConfig.class);
    assertEquals("configValue3", cfg.stringParam());
    SimpleConfig subConfig = cfg.subConfig();
    assertEquals("configValue4", subConfig.stringParam());
    assertEquals(444, subConfig.intParam());
    assertEquals(true, subConfig.boolParam());
    ListConfig[] listConfig = cfg.subListConfig();
    assertEquals(3, listConfig.length);
    assertEquals("configValue2.1", listConfig[0].stringParam());
    assertEquals("configValue2.2", listConfig[1].stringParam());
    assertEquals("configValue2.3", listConfig[2].stringParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) NestedConfig(org.apache.sling.caconfig.example.NestedConfig) ListConfig(org.apache.sling.caconfig.example.ListConfig) Test(org.junit.Test)

Example 20 with SimpleConfig

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

the class ConfigurationResolverAnnotationClassTest method testConfig_SimpleWithName.

@Test
public void testConfig_SimpleWithName() {
    context.build().resource("/conf/content/site1/sling:configs/sampleName", "stringParam", "configValue1.1", "intParam", 1111, "boolParam", true);
    SimpleConfig cfg = underTest.get(site1Page1).name("sampleName").as(SimpleConfig.class);
    assertEquals("configValue1.1", cfg.stringParam());
    assertEquals(1111, cfg.intParam());
    assertEquals(true, cfg.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) Test(org.junit.Test)

Aggregations

SimpleConfig (org.apache.sling.caconfig.example.SimpleConfig)20 Test (org.junit.Test)20 NestedConfig (org.apache.sling.caconfig.example.NestedConfig)6 ListConfig (org.apache.sling.caconfig.example.ListConfig)4 Resource (org.apache.sling.api.resource.Resource)1 ConfigurationBuilder (org.apache.sling.caconfig.ConfigurationBuilder)1 WithoutAnnotationConfig (org.apache.sling.caconfig.example.WithoutAnnotationConfig)1