Search in sources :

Example 6 with ConfigurationPersistenceStrategy2

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

the class DefaultConfigurationPersistenceStrategyTest method testGetResource.

@Test
public void testGetResource() {
    ConfigurationPersistenceStrategy2 underTest = context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy());
    Resource resource = context.create().resource("/conf/test");
    assertSame(resource, underTest.getResource(resource));
    assertSame(resource, underTest.getCollectionParentResource(resource));
    assertSame(resource, underTest.getCollectionItemResource(resource));
}
Also used : ConfigurationPersistenceStrategy2(org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2) Resource(org.apache.sling.api.resource.Resource) Test(org.junit.Test)

Example 7 with ConfigurationPersistenceStrategy2

use of org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2 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)

Example 8 with ConfigurationPersistenceStrategy2

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

the class DefaultConfigurationPersistenceStrategyTest method testPersistConfiguration.

@Test
public void testPersistConfiguration() throws Exception {
    ConfigurationPersistenceStrategy2 underTest = context.registerInjectActivateService(new DefaultConfigurationPersistenceStrategy());
    // store config data
    assertTrue(underTest.persistConfiguration(context.resourceResolver(), "/conf/test", new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop1", "value1", "prop2", 5))));
    context.resourceResolver().commit();
    ValueMap props = context.resourceResolver().getResource("/conf/test").getValueMap();
    assertEquals("value1", props.get("prop1", String.class));
    assertEquals((Integer) 5, props.get("prop2", Integer.class));
    // remove config data
    assertTrue(underTest.persistConfiguration(context.resourceResolver(), "/conf/test", new ConfigurationPersistData(ImmutableMap.<String, Object>of())));
    context.resourceResolver().commit();
    props = context.resourceResolver().getResource("/conf/test").getValueMap();
    assertNull(props.get("prop1", String.class));
    assertNull(props.get("prop2", Integer.class));
    underTest.deleteConfiguration(context.resourceResolver(), "/conf/test");
    assertNull(context.resourceResolver().getResource("/conf/test"));
}
Also used : ConfigurationPersistenceStrategy2(org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2) ConfigurationPersistData(org.apache.sling.caconfig.spi.ConfigurationPersistData) ValueMap(org.apache.sling.api.resource.ValueMap) Test(org.junit.Test)

Aggregations

ConfigurationPersistenceStrategy2 (org.apache.sling.caconfig.spi.ConfigurationPersistenceStrategy2)8 Test (org.junit.Test)7 Resource (org.apache.sling.api.resource.Resource)4 ConfigurationPersistData (org.apache.sling.caconfig.spi.ConfigurationPersistData)4 ConfigurationCollectionPersistData (org.apache.sling.caconfig.spi.ConfigurationCollectionPersistData)3 ValueMap (org.apache.sling.api.resource.ValueMap)2 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)1 ConfigurationPersistenceStrategyBridge (org.apache.sling.caconfig.impl.ConfigurationPersistenceStrategyBridge)1