Search in sources :

Example 1 with DataFileBackingStoreImpl

use of org.apache.felix.prefs.impl.DataFileBackingStoreImpl in project felix by apache.

the class PreferencesImplTest method testAddRemoveAdd.

@Test
public void testAddRemoveAdd() throws Exception {
    final BackingStore store = new DataFileBackingStoreImpl(null, Files.createTempDirectory("prefs").toFile());
    final PreferencesImpl prefs = new PreferencesImpl(new PreferencesDescription(5L, null), new BackingStoreManager() {

        public BackingStore getStore() throws BackingStoreException {
            return store;
        }
    });
    Preferences firstA = prefs.node("A");
    firstA.node("1");
    firstA.node("2");
    assertEquals(1, prefs.childrenNames().length);
    assertEquals(2, firstA.childrenNames().length);
    firstA.removeNode();
    prefs.flush();
    assertEquals(0, prefs.childrenNames().length);
    firstA = prefs.node("A");
    assertEquals(1, prefs.childrenNames().length);
    assertEquals(0, firstA.childrenNames().length);
    firstA.node("1");
    firstA.node("2");
    assertEquals(2, firstA.childrenNames().length);
}
Also used : BackingStoreException(org.osgi.service.prefs.BackingStoreException) Preferences(org.osgi.service.prefs.Preferences) DataFileBackingStoreImpl(org.apache.felix.prefs.impl.DataFileBackingStoreImpl) Test(org.junit.Test)

Aggregations

DataFileBackingStoreImpl (org.apache.felix.prefs.impl.DataFileBackingStoreImpl)1 Test (org.junit.Test)1 BackingStoreException (org.osgi.service.prefs.BackingStoreException)1 Preferences (org.osgi.service.prefs.Preferences)1