Search in sources :

Example 1 with DummyConfigurationOverrideProvider

use of org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider in project sling by apache.

the class ConfigurationResolverValueMapTest method testConfigWithOverride.

@Test
public void testConfigWithOverride() {
    context.registerService(ConfigurationOverrideProvider.class, new DummyConfigurationOverrideProvider("[/content]sampleName={\"stringParam\":\"override1\",\"intParam\":222}"));
    context.build().resource("/conf/content/site1/sling:configs/sampleName", "stringParam", "configValue1", "intParam", 111, "boolParam", true);
    ValueMap props = underTest.get(site1Page1).name("sampleName").asValueMap();
    assertEquals("override1", props.get("stringParam", String.class));
    assertEquals(222, (int) props.get("intParam", 0));
    assertEquals(false, props.get("boolParam", false));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) DummyConfigurationOverrideProvider(org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider) Test(org.junit.Test)

Example 2 with DummyConfigurationOverrideProvider

use of org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider in project sling by apache.

the class ConfigurationManagerImplTest method testGetConfigurationCollection_WithOverride.

@Test
public void testGetConfigurationCollection_WithOverride() {
    context.registerService(ConfigurationOverrideProvider.class, new DummyConfigurationOverrideProvider("[/content]" + CONFIG_COL_NAME + "/prop1=\"override1\""));
    List<ConfigurationData> configDatas = ImmutableList.copyOf(underTest.getConfigurationCollection(contextResource, CONFIG_COL_NAME).getItems());
    assertEquals(2, configDatas.size());
    ConfigurationData configData1 = configDatas.get(0);
    assertFalse(configData1.isInherited());
    assertFalse(configData1.isOverridden());
    assertEquals(ImmutableSet.of("prop1", "prop2", "prop3"), configData1.getPropertyNames());
    assertEquals("value1", configData1.getValues().get("prop1", String.class));
    assertEquals("override1", configData1.getEffectiveValues().get("prop1", String.class));
    assertEquals((Integer) 5, configData1.getEffectiveValues().get("prop3", 0));
    assertFalse(configData1.getValueInfo("prop1").isInherited());
    assertTrue(configData1.getValueInfo("prop1").isOverridden());
    assertFalse(configData1.getValueInfo("prop3").isInherited());
    assertFalse(configData1.getValueInfo("prop3").isOverridden());
    ConfigurationData configData2 = configDatas.get(1);
    assertFalse(configData2.isInherited());
    assertFalse(configData2.isOverridden());
    assertEquals(ImmutableSet.of("prop1", "prop2", "prop3", "prop4"), configData2.getPropertyNames());
    assertNull(configData2.getValues().get("prop1", String.class));
    assertEquals("override1", configData2.getEffectiveValues().get("prop1", String.class));
    assertEquals((Integer) 5, configData2.getEffectiveValues().get("prop3", 0));
    assertFalse(configData2.getValueInfo("prop1").isInherited());
    assertTrue(configData2.getValueInfo("prop1").isOverridden());
    assertFalse(configData2.getValueInfo("prop3").isInherited());
    assertFalse(configData2.getValueInfo("prop3").isOverridden());
}
Also used : ConfigurationData(org.apache.sling.caconfig.management.ConfigurationData) DummyConfigurationOverrideProvider(org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider) Test(org.junit.Test)

Example 3 with DummyConfigurationOverrideProvider

use of org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider in project sling by apache.

the class ConfigurationManagerImplTest method testGetConfiguration_WithOverride.

@Test
public void testGetConfiguration_WithOverride() {
    context.registerService(ConfigurationOverrideProvider.class, new DummyConfigurationOverrideProvider("[/content]" + CONFIG_NAME + "={\"prop1\":\"override1\"}"));
    ConfigurationData configData = underTest.getConfiguration(contextResource, CONFIG_NAME);
    assertNotNull(configData);
    assertFalse(configData.isInherited());
    assertTrue(configData.isOverridden());
    assertEquals(ImmutableSet.of("prop1", "prop2", "prop3"), configData.getPropertyNames());
    assertEquals("value1", configData.getValues().get("prop1", String.class));
    assertEquals("override1", configData.getEffectiveValues().get("prop1", String.class));
    assertEquals((Integer) 5, configData.getEffectiveValues().get("prop3", 0));
    assertFalse(configData.getValueInfo("prop1").isInherited());
    assertTrue(configData.getValueInfo("prop1").isOverridden());
    assertFalse(configData.getValueInfo("prop3").isInherited());
    assertTrue(configData.getValueInfo("prop3").isOverridden());
}
Also used : ConfigurationData(org.apache.sling.caconfig.management.ConfigurationData) DummyConfigurationOverrideProvider(org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider) Test(org.junit.Test)

Example 4 with DummyConfigurationOverrideProvider

use of org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider in project sling by apache.

the class ConfigurationResolverValueMapTest method testConfigCollectionWithOverride.

@Test
public void testConfigCollectionWithOverride() {
    context.registerService(ConfigurationOverrideProvider.class, new DummyConfigurationOverrideProvider("[/content]sampleList/stringParam=\"override1\""));
    context.build().resource("/conf/content/site1/sling:configs/sampleList").siblingsMode().resource("1", "stringParam", "configValue1.1").resource("2", "stringParam", "configValue1.2").resource("3", "stringParam", "configValue1.3");
    Collection<ValueMap> propsList = underTest.get(site1Page1).name("sampleList").asValueMapCollection();
    Iterator<ValueMap> propsIterator = propsList.iterator();
    assertEquals("override1", propsIterator.next().get("stringParam", String.class));
    assertEquals("override1", propsIterator.next().get("stringParam", String.class));
    assertEquals("override1", propsIterator.next().get("stringParam", String.class));
}
Also used : ValueMap(org.apache.sling.api.resource.ValueMap) DummyConfigurationOverrideProvider(org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider) Test(org.junit.Test)

Aggregations

DummyConfigurationOverrideProvider (org.apache.sling.caconfig.impl.override.DummyConfigurationOverrideProvider)4 Test (org.junit.Test)4 ValueMap (org.apache.sling.api.resource.ValueMap)2 ConfigurationData (org.apache.sling.caconfig.management.ConfigurationData)2