Search in sources :

Example 1 with AllTypesConfig

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

the class ConfigurationProxyTest method testNonExistingConfig_AllTypes.

@Test
public void testNonExistingConfig_AllTypes() {
    AllTypesConfig cfg = get(null, AllTypesConfig.class);
    assertNull(cfg.stringParam());
    assertEquals(STRING_DEFAULT, cfg.stringParamWithDefault());
    assertEquals(0, cfg.intParam());
    assertEquals(INT_DEFAULT, cfg.intParamWithDefault());
    assertEquals(0L, cfg.longParam());
    assertEquals(LONG_DEFAULT, cfg.longParamWithDefault());
    assertEquals(0d, cfg.doubleParam(), 0.001d);
    assertEquals(DOUBLE_DEFAULT, cfg.doubleParamWithDefault(), 0.001d);
    assertEquals(false, cfg.boolParam());
    assertEquals(BOOL_DEFAULT, cfg.boolParamWithDefault());
    assertArrayEquals(new String[0], cfg.stringArrayParam());
    assertArrayEquals(new String[] { STRING_DEFAULT, STRING_DEFAULT_2 }, cfg.stringArrayParamWithDefault());
    assertArrayEquals(new int[0], cfg.intArrayParam());
    assertArrayEquals(new int[] { INT_DEFAULT, INT_DEFAULT_2 }, cfg.intArrayParamWithDefault());
    assertArrayEquals(new long[0], cfg.longArrayParam());
    assertArrayEquals(new long[] { LONG_DEFAULT, LONG_DEFAULT_2 }, cfg.longArrayParamWithDefault());
    assertArrayEquals(new double[0], cfg.doubleArrayParam(), 0.001d);
    assertArrayEquals(new double[] { DOUBLE_DEFAULT, DOUBLE_DEFAULT_2 }, cfg.doubleArrayParamWithDefault(), 0.001d);
    assertArrayEquals(new boolean[0], cfg.boolArrayParam());
    assertArrayEquals(new boolean[] { BOOL_DEFAULT, BOOL_DEFAULT_2 }, cfg.boolArrayParamWithDefault());
}
Also used : AllTypesConfig(org.apache.sling.caconfig.example.AllTypesConfig) Test(org.junit.Test)

Example 2 with AllTypesConfig

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

the class ConfigurationProxyTest method testConfig_AllTypes.

@Test
public void testConfig_AllTypes() {
    Resource resource = context.build().resource("/test", "stringParam", "configValue2", "intParam", 222, "longParam", 3456L, "doubleParam", 0.123d, "boolParam", true, "stringArrayParam", new String[] { STRING_DEFAULT_2, STRING_DEFAULT }, "intArrayParam", new int[] { INT_DEFAULT_2 }, "longArrayParam", new long[] { LONG_DEFAULT_2, LONG_DEFAULT }, "doubleArrayParam", new double[] { DOUBLE_DEFAULT_2 }, "boolArrayParam", new boolean[] { BOOL_DEFAULT_2, BOOL_DEFAULT }).getCurrentParent();
    AllTypesConfig cfg = get(resource, AllTypesConfig.class);
    assertEquals("configValue2", cfg.stringParam());
    assertEquals(STRING_DEFAULT, cfg.stringParamWithDefault());
    assertEquals(222, cfg.intParam());
    assertEquals(INT_DEFAULT, cfg.intParamWithDefault());
    assertEquals(3456L, cfg.longParam());
    assertEquals(LONG_DEFAULT, cfg.longParamWithDefault());
    assertEquals(0.123d, cfg.doubleParam(), 0.001d);
    assertEquals(DOUBLE_DEFAULT, cfg.doubleParamWithDefault(), 0.001d);
    assertEquals(true, cfg.boolParam());
    assertEquals(BOOL_DEFAULT, cfg.boolParamWithDefault());
    assertArrayEquals(new String[] { STRING_DEFAULT_2, STRING_DEFAULT }, cfg.stringArrayParam());
    assertArrayEquals(new String[] { STRING_DEFAULT, STRING_DEFAULT_2 }, cfg.stringArrayParamWithDefault());
    assertArrayEquals(new int[] { INT_DEFAULT_2 }, cfg.intArrayParam());
    assertArrayEquals(new int[] { INT_DEFAULT, INT_DEFAULT_2 }, cfg.intArrayParamWithDefault());
    assertArrayEquals(new long[] { LONG_DEFAULT_2, LONG_DEFAULT }, cfg.longArrayParam());
    assertArrayEquals(new long[] { LONG_DEFAULT, LONG_DEFAULT_2 }, cfg.longArrayParamWithDefault());
    assertArrayEquals(new double[] { DOUBLE_DEFAULT_2 }, cfg.doubleArrayParam(), 0.001d);
    assertArrayEquals(new double[] { DOUBLE_DEFAULT, DOUBLE_DEFAULT_2 }, cfg.doubleArrayParamWithDefault(), 0.001d);
    assertArrayEquals(new boolean[] { BOOL_DEFAULT_2, BOOL_DEFAULT }, cfg.boolArrayParam());
    assertArrayEquals(new boolean[] { BOOL_DEFAULT, BOOL_DEFAULT_2 }, cfg.boolArrayParamWithDefault());
}
Also used : Resource(org.apache.sling.api.resource.Resource) AllTypesConfig(org.apache.sling.caconfig.example.AllTypesConfig) Test(org.junit.Test)

Aggregations

AllTypesConfig (org.apache.sling.caconfig.example.AllTypesConfig)2 Test (org.junit.Test)2 Resource (org.apache.sling.api.resource.Resource)1