public void testNode() throws BackingStoreException {
   assertNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
   pref.flush();
   assertNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
   pref.put("key", "value");
 }
  public void testPreferencesEvents() throws Exception {
    storage.toFolder(true);
    FileUtil.getConfigRoot().addRecursiveListener(new FileListener());
    pref.addNodeChangeListener(new NodeListener());

    String newPath = "a/b/c";
    String[] paths = newPath.split("/");
    FileObject fo = null;
    FileObject fo0 = null;
    for (int i = 0; i < paths.length; i++) {
      String path = paths[i];
      fo = FileUtil.createFolder((fo == null) ? FileUtil.getConfigRoot() : fo, path);
      if (i == 0) {
        fo0 = fo;
      }
      nodeAddedEvent.await();
      assertEquals("Missing node added event", 0, nodeAddedEvent.getCount());
      nodeAddedEvent = new CountDownLatch(1);

      Preferences pref2 = pref.node(fo.getPath());
      pref2.addNodeChangeListener(new NodeListener());
    }

    FileObject fo1 = FileUtil.createData(fo, "a.properties");
    nodeAddedEvent.await();
    assertEquals("Missing node added event", 0, nodeAddedEvent.getCount());

    nodeRemovedEvent = new CountDownLatch(paths.length + 1);
    fo0.delete();
    nodeRemovedEvent.await();
    assertEquals("Missing node removed event", 0, nodeRemovedEvent.getCount());
  }
 public void testNode5() throws BackingStoreException {
   Preferences child = pref.node("a");
   child.put("key", "value");
   child.flush();
   assertNotNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
 }
  public void testRemoveParentNode() throws BackingStoreException {
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());

    Preferences subnode = pref.node("subnode");
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());
    subnode.put("key", "value");
    subnode.flush();
    assertNotNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());
    subnode.removeNode();
    pref.flush();
    assertNull(storage.toPropertiesFile());
    assertNull(storage.toFolder());
    assertFalse(storage.existsNode());
  }
  @RandomlyFails // FSException: Invalid lock (from flush)
  public void testRemoveNode() throws BackingStoreException {
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());

    pref.put("key", "value");
    pref.node("subnode").put("key", "value");
    pref.flush();
    assertNotNull(storage.toPropertiesFile());
    assertNotNull(storage.toFolder());
    pref.removeNode();
    pref.flush();
    assertNull(storage.toPropertiesFile());
    assertNull(storage.toFolder());
    assertFalse(storage.existsNode());
    pref.sync();
  }
  public void testRemove() throws BackingStoreException {
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());

    pref.put("key", "value");
    pref.flush();
    assertNotNull(storage.toPropertiesFile());
    pref.remove("key");
    assertTrue(pref.properties.isEmpty());
    pref.flush();
    assertNull(storage.toPropertiesFile());
  }
  public void testInvalidChildrenNames() throws Exception {
    NbPreferences subnode = pref;
    assertNotNull(subnode);
    PropertiesStorage ps = (PropertiesStorage) pref.fileStorage;
    FileObject fold = ps.toFolder(true);
    assertNotNull(FileUtil.createData(fold, "a/b/c/invalid1"));
    subnode.sync();
    assertEquals(0, subnode.childrenNames().length);

    assertNotNull(FileUtil.createData(fold, "a/b/c/invalid2.huh"));
    subnode.sync();
    assertEquals(0, subnode.childrenNames().length);

    assertNotNull(FileUtil.createData(fold, "a/b/c/invalid3.properties.huh"));
    subnode.sync();
    assertEquals(0, subnode.childrenNames().length);

    assertNotNull(FileUtil.createData(fold, "a/b/c/valid.properties"));
    subnode.sync();
    assertEquals(1, subnode.childrenNames().length);
    assertEquals("a", subnode.childrenNames()[0]);
  }