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));
}
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"));
}
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"));
}
Aggregations