|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
30 | 30 | * @run main/othervm -Djava.util.prefs.userRoot=. ExportNode
|
31 | 31 | * @author Konstantin Kladko
|
32 | 32 | */
|
33 |
| -import java.util.prefs.*; |
34 |
| -import java.io.*; |
| 33 | + |
| 34 | +import java.io.ByteArrayOutputStream; |
| 35 | +import java.io.IOException; |
| 36 | +import java.util.prefs.BackingStoreException; |
| 37 | +import java.util.prefs.Preferences; |
35 | 38 |
|
36 | 39 | public class ExportNode {
|
| 40 | + private static final String NODE_NAME_1 = "ExportNodeTestName1"; |
| 41 | + private static final String NODE_NAME_2 = "ExportNodeTestName2"; |
| 42 | + |
37 | 43 | public static void main(String[] args) throws
|
38 |
| - BackingStoreException, IOException { |
39 |
| - Preferences N1 = Preferences.userRoot().node("ExportNodeTest1"); |
40 |
| - N1.put("ExportNodeTestName1","ExportNodeTestValue1"); |
41 |
| - Preferences N2 = N1.node("ExportNodeTest2"); |
42 |
| - N2.put("ExportNodeTestName2","ExportNodeTestValue2"); |
43 |
| - ByteArrayOutputStream exportStream = new ByteArrayOutputStream(); |
44 |
| - N2.exportNode(exportStream); |
45 |
| - |
46 |
| - // Removal of preference node should always succeed on Solaris/Linux |
47 |
| - // by successfully acquiring the appropriate file lock (4947349) |
48 |
| - N1.removeNode(); |
49 |
| - |
50 |
| - if (((exportStream.toString()).lastIndexOf("ExportNodeTestName2")== -1) || |
51 |
| - ((exportStream.toString()).lastIndexOf("ExportNodeTestName1")!= -1)) { |
52 |
| - } |
| 44 | + BackingStoreException, IOException { |
| 45 | + Preferences N1 = Preferences.userRoot().node("ExportNodeTest1"); |
| 46 | + N1.put(NODE_NAME_1,"ExportNodeTestValue1"); |
| 47 | + Preferences N2 = N1.node("ExportNodeTest2"); |
| 48 | + N2.put(NODE_NAME_2,"ExportNodeTestValue2"); |
| 49 | + ByteArrayOutputStream exportStream = new ByteArrayOutputStream(); |
| 50 | + N2.exportNode(exportStream); |
| 51 | + |
| 52 | + // Removal of preference node should always succeed on Solaris/Linux |
| 53 | + // by successfully acquiring the appropriate file lock (4947349) |
| 54 | + N1.removeNode(); |
| 55 | + |
| 56 | + String streamAsString = exportStream.toString("UTF-8"); |
| 57 | + |
| 58 | + StringBuilder sb = null; |
| 59 | + if (streamAsString.lastIndexOf(NODE_NAME_2) == -1) { |
| 60 | + if (sb == null) |
| 61 | + sb = new StringBuilder(); |
| 62 | + sb.append(NODE_NAME_2 + " should have been found"); |
| 63 | + } |
| 64 | + if (streamAsString.lastIndexOf(NODE_NAME_1) != -1) { |
| 65 | + if (sb == null) |
| 66 | + sb = new StringBuilder(); |
| 67 | + else |
| 68 | + sb.append("; "); |
| 69 | + sb.append(NODE_NAME_1 + " should *not* have been found"); |
| 70 | + } |
| 71 | + |
| 72 | + if (sb != null) |
| 73 | + throw new RuntimeException(sb.toString()); |
53 | 74 | }
|
54 | 75 | }
|
0 commit comments