コード例 #1
0
 public void testNode5() throws BackingStoreException {
   Preferences child = pref.node("a");
   child.put("key", "value");
   child.flush();
   assertNotNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
 }
コード例 #2
0
 public void testChildrenNames() throws Exception {
   Preferences subnode = pref.node("c1");
   subnode.put("k", "v");
   subnode.flush();
   subnode = pref.node("c2");
   subnode.put("k", "v");
   subnode.flush();
   subnode = pref.node("c3/c4");
   subnode.put("k", "v");
   subnode.flush();
   assertEquals(
       new TreeSet<String>(Arrays.asList("c1", "c2", "c3")),
       new TreeSet<String>(Arrays.asList(storage.childrenNames())));
   pref.node("c2").removeNode();
   assertEquals(
       new TreeSet<String>(Arrays.asList("c1", "c3")),
       new TreeSet<String>(Arrays.asList(storage.childrenNames())));
   pref.node("c3").removeNode();
   assertEquals(
       Collections.singleton("c1"), new TreeSet<String>(Arrays.asList(storage.childrenNames())));
   pref.node("c1").removeNode();
   assertEquals(
       Collections.emptySet(), new TreeSet<String>(Arrays.asList(storage.childrenNames())));
 }
コード例 #3
0
  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());
  }
コード例 #4
0
 public static void main(String[] args) throws Exception {
   String osName = System.getProperty("os.name");
   if (osName.startsWith("Windows")) return;
   Preferences root = Preferences.userRoot();
   Preferences node1 = root.node("node1");
   Preferences node1A = node1.node("node1A");
   Preferences node1B = node1.node("node1B");
   node1B.put("mykey", "myvalue");
   node1.flush();
   String node1BDirName = System.getProperty("user.home") + "/.java/.userPrefs" + "/node1/node1B";
   File node1BDir = new File(node1BDirName);
   node1BDir.setReadOnly();
   try {
     node1.removeNode();
   } catch (BackingStoreException ex) {
     // expected exception
   } finally {
     Runtime.getRuntime().exec("chmod 755 " + node1BDirName).waitFor();
     try {
       node1.removeNode();
     } catch (Exception e) {
     }
   }
 }