< prev index next >

test/jdk/java/util/prefs/CheckUserPrefsStorage.java

Print this page


   1 /*
   2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 








  24 import java.util.prefs.Preferences;
  25 
  26 /**
  27  *
  28  * @author khazra
  29  * First class called by CheckUserPrefsStorage.sh to create and
  30  * store a user preference
  31  */

















  32 
  33 public class CheckUserPrefFirst {



  34 
  35     public static void main(String[] args) throws Exception {
  36         Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class);
  37         prefs.put("Check", "Success");



  38         prefs.flush();
  39     }
  40 }
  41 

   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 7198073 7197662
  27  * @summary Tests that user preferences are stored in the permanent storage
  28  * @library /test/lib
  29  * @run main/othervm -Djava.util.prefs.userRoot=. CheckUserPrefsStorage
  30  */
  31 
  32 import java.util.prefs.Preferences;
  33 
  34 import jdk.test.lib.process.ProcessTools;
  35 
  36 public class CheckUserPrefsStorage {
  37 
  38     private static final Class PREF_NODE = CheckUserPrefsStorage.class;
  39     private static final String KEY = "Check";
  40     private static final String VALUE = "Success";
  41     private static final Preferences prefs = Preferences.userNodeForPackage(PREF_NODE);
  42 
  43     public static void main(String[] args) throws Throwable {
  44         if (args.length == 0) {
  45             createPref(KEY, VALUE);
  46             ProcessTools.executeTestJvm("-Djava.util.prefs.userRoot=.",
  47                                         PREF_NODE.getName(),
  48                                         KEY,
  49                                         VALUE)
  50                         .outputTo(System.out)
  51                         .errorTo(System.out)
  52                         .shouldHaveExitValue(0);
  53         } else {
  54             checkPref(args[0], args[1]);
  55         }
  56     }
  57 
  58     public static void createPref(String key, String value) throws Exception {
  59         prefs.put(key, value);
  60         prefs.flush();
  61     }
  62 
  63     public static void checkPref(String key, String value) throws Exception {
  64         String result = prefs.get(key, null);
  65         if ((result == null) || !(result.equals(value))) {
  66             throw new RuntimeException("User pref not stored!");
  67         }
  68         prefs.remove(key);
  69         prefs.flush();
  70     }

  71 
  72 }
< prev index next >