Search in sources :

Example 1 with SimpleConfig

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

the class ConfigurationProxyTest method testNonExistingConfig_Nested.

@Test
public void testNonExistingConfig_Nested() {
    NestedConfig cfg = get(null, NestedConfig.class);
    assertNull(cfg.stringParam());
    SimpleConfig subConfig = cfg.subConfig();
    assertNull(subConfig.stringParam());
    assertEquals(5, subConfig.intParam());
    assertFalse(subConfig.boolParam());
    assertArrayEquals(new ListConfig[0], cfg.subListConfig());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) NestedConfig(org.apache.sling.caconfig.example.NestedConfig) Test(org.junit.Test)

Example 2 with SimpleConfig

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

the class ConfigurationProxyTest method testConfig_Nested.

@Test
public void testConfig_Nested() {
    context.build().resource("/test", "stringParam", "v1").resource("/test/subConfig", "stringParam", "v2", "intParam", 444, "boolParam", true).resource("/test/subListConfig/1", "stringParam", "v3.1").resource("/test/subListConfig/2", "stringParam", "v3.2").resource("/test/subListConfig/3", "stringParam", "v3.3").resource("/test/subConfigWithoutAnnotation", "stringParam", "v4");
    Resource resource = context.resourceResolver().getResource("/test");
    NestedConfig cfg = get(resource, NestedConfig.class);
    assertEquals("v1", cfg.stringParam());
    SimpleConfig subConfig = cfg.subConfig();
    assertEquals("v2", subConfig.stringParam());
    assertEquals(444, subConfig.intParam());
    assertEquals(true, subConfig.boolParam());
    ListConfig[] listConfig = cfg.subListConfig();
    assertEquals(3, listConfig.length);
    assertEquals("v3.1", listConfig[0].stringParam());
    assertEquals("v3.2", listConfig[1].stringParam());
    assertEquals("v3.3", listConfig[2].stringParam());
    WithoutAnnotationConfig subConfigWithoutAnnotation = cfg.subConfigWithoutAnnotation();
    assertEquals("v4", subConfigWithoutAnnotation.stringParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) WithoutAnnotationConfig(org.apache.sling.caconfig.example.WithoutAnnotationConfig) Resource(org.apache.sling.api.resource.Resource) NestedConfig(org.apache.sling.caconfig.example.NestedConfig) ListConfig(org.apache.sling.caconfig.example.ListConfig) Test(org.junit.Test)

Example 3 with SimpleConfig

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

the class ConfigurationResolverCustomPersistenceTest method testConfig_Simple.

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

Example 4 with SimpleConfig

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

the class ConfigurationResolverCustomPersistenceTest method testNonExistingConfig_Simple.

@Test
public void testNonExistingConfig_Simple() {
    SimpleConfig cfg = underTest.get(site1Page1).as(SimpleConfig.class);
    assertNull(cfg.stringParam());
    assertEquals(5, cfg.intParam());
    assertEquals(false, cfg.boolParam());
}
Also used : SimpleConfig(org.apache.sling.caconfig.example.SimpleConfig) Test(org.junit.Test)

Example 5 with SimpleConfig

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

the class ConfigurationResolverAnnotationClassTest method testConfig_Simple_PropertyInheritance.

@Test
public void testConfig_Simple_PropertyInheritance() {
    context.build().resource("/conf/global/sling:configs/org.apache.sling.caconfig.example.SimpleConfig", "stringParam", "configValue1", "intParam", 111).resource("/conf/content/site1/sling:configs/org.apache.sling.caconfig.example.SimpleConfig", "stringParam", "configValue2", "intParam", 222, "boolParam", true, PROPERTY_CONFIG_PROPERTY_INHERIT, true);
    SimpleConfig cfg = underTest.get(site1Page1).as(SimpleConfig.class);
    assertEquals("configValue2", cfg.stringParam());
    assertEquals(222, 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