Search in sources :

Example 6 with ConfigurationCollectionPersistData

use of org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData in project sling by apache.

the class ConfigurationPersistenceStrategyMultiplexerImplTest method testWithDefaultStrategy.

@Test
public void testWithDefaultStrategy() {
    context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy());
    assertSame(resource1, underTest.getResource(resource1));
    assertEquals(resource1.getPath(), underTest.getResourcePath(resource1.getPath()));
    assertTrue(underTest.persistConfiguration(context.resourceResolver(), "/conf/test1", new ConfigurationPersistData(resource1.getValueMap())));
    assertTrue(underTest.persistConfigurationCollection(context.resourceResolver(), "/conf/testCol", new ConfigurationCollectionPersistData(ImmutableList.of(new ConfigurationPersistData(resource1.getValueMap()).collectionItemName(resource1.getName()), new ConfigurationPersistData(resource2.getValueMap()).collectionItemName(resource2.getName())))));
    assertTrue(underTest.deleteConfiguration(context.resourceResolver(), "/conf/test1"));
}
Also used : ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) ConfigurationCollectionPersistData(org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData) DefaultConfigurationPersistenceStrategy(org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy) Test(org.junit.Test)

Example 7 with ConfigurationCollectionPersistData

use of org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData in project sling by apache.

the class ConfigurationPersistenceStrategyMultiplexerImplTest method testWithNoStrategies.

@Test
public void testWithNoStrategies() {
    assertNull(underTest.getResource(resource1));
    assertNull(underTest.getResourcePath(resource1.getPath()));
    assertFalse(underTest.persistConfiguration(context.resourceResolver(), "/conf/test1", new ConfigurationPersistData(resource1.getValueMap())));
    assertFalse(underTest.persistConfigurationCollection(context.resourceResolver(), "/conf/testCol", new ConfigurationCollectionPersistData(ImmutableList.of(new ConfigurationPersistData(resource1.getValueMap()).collectionItemName(resource1.getName()), new ConfigurationPersistData(resource2.getValueMap()).collectionItemName(resource2.getName())))));
    assertFalse(underTest.deleteConfiguration(context.resourceResolver(), "/conf/test1"));
}
Also used : ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) ConfigurationCollectionPersistData(org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData) Test(org.junit.Test)

Example 8 with ConfigurationCollectionPersistData

use of org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData in project sling by apache.

the class ConfigurationManagerImplTest method testPersistConfigurationCollection.

@Test
public void testPersistConfigurationCollection() throws Exception {
    underTest.persistConfigurationCollection(contextResourceNoConfig, CONFIG_COL_NAME, new ConfigurationCollectionPersistData(ImmutableList.of(new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop1", "value1")).collectionItemName("0"), new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop2", 5)).collectionItemName("1"))));
    context.resourceResolver().commit();
    String configPath0 = getConfigCollectionItemPersistPath(getConfigCollectionParentPersistPath("/conf/testNoConfig/sling:configs/" + CONFIG_COL_NAME) + "/0");
    ValueMap props0 = context.resourceResolver().getResource(configPath0).getValueMap();
    assertEquals("value1", props0.get("prop1"));
    String configPath1 = getConfigCollectionItemPersistPath(getConfigCollectionParentPersistPath("/conf/testNoConfig/sling:configs/" + CONFIG_COL_NAME) + "/1");
    ValueMap props1 = context.resourceResolver().getResource(configPath1).getValueMap();
    assertEquals((Integer) 5, props1.get("prop2"));
}
Also used : ConfigurationCollectionPersistData(org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData) ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) ValueMap(org.apache.sling.api.resource.ValueMap) Test(org.junit.Test)

Example 9 with ConfigurationCollectionPersistData

use of org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData in project sling by apache.

the class DefaultConfigurationPersistenceStrategyTest method testDisabled.

@Test
public void testDisabled() {
    ConfigurationPersistenceStrategy2 underTest = context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy(), "enabled", false);
    Resource resource = context.create().resource("/conf/test");
    assertNull(underTest.getResource(resource));
    assertNull(underTest.getResourcePath(resource.getPath()));
    assertFalse(underTest.persistConfiguration(context.resourceResolver(), "/conf/test", new ConfigurationPersistData(ImmutableMap.<String, Object>of())));
    assertFalse(underTest.persistConfigurationCollection(context.resourceResolver(), "/conf/test", new ConfigurationCollectionPersistData(ImmutableList.<ConfigurationPersistData>of())));
    assertFalse(underTest.deleteConfiguration(context.resourceResolver(), "/conf/test"));
}
Also used : ConfigurationPersistenceStrategy2(org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2) ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) ConfigurationCollectionPersistData(org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Aggregations

ConfigurationCollectionPersistData (org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData)9 ConfigurationPersistData (org.apache.sling.caconfig.spi.ConfigurationPersistData)9 Test (org.junit.Test)8 Resource (org.apache.sling.api.resource.Resource)4 ConfigurationPersistenceStrategy2 (org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2)3 ArrayList (java.util.ArrayList)2 ValueMap (org.apache.sling.api.resource.ValueMap)2 HashMap (java.util.HashMap)1 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 DefaultConfigurationPersistenceStrategy (org.apache.sling.caconfig.impl.def.DefaultConfigurationPersistenceStrategy)1 SimpleConfig (org.apache.sling.caconfig.it.example.SimpleConfig)1 ConfigurationData (org.apache.sling.caconfig.management.ConfigurationData)1 ConfigurationManager (org.apache.sling.caconfig.management.ConfigurationManager)1