1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.ldap.server.prefs;
18
19
20 import org.apache.ldap.server.AbstractCoreTest;
21
22 import java.util.prefs.BackingStoreException;
23 import java.util.prefs.Preferences;
24
25
26 /***
27 * Tests the ServerSystemPreferences class.
28 *
29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
30 * @version $Rev$
31 */
32 public class ServerSystemPreferencesTest extends AbstractCoreTest
33 {
34 /***
35 * Tests to make sure the system preferences root has entry (test, abc123).
36 */
37 public void testRoot() throws BackingStoreException
38 {
39 ServerSystemPreferences prefs = new ServerSystemPreferences();
40
41 assertEquals( "sysPrefRoot", prefs.get( "prefNodeName", "not the value" ) );
42 }
43
44
45 /***
46 * Tests the creation and use of a new preferences node.
47 *
48 * @throws BackingStoreException if there are failures with the store
49 */
50 public void testCreate() throws BackingStoreException
51 {
52 Preferences prefs = new ServerSystemPreferences();
53
54 Preferences testNode = prefs.node( "testNode" );
55
56 testNode.put( "testNodeKey", "testNodeValue" );
57
58 testNode.sync();
59 }
60
61
62 /***
63 * Tests the creation and use of a new preferences node.
64 *
65 * @throws BackingStoreException if there are failures with the store
66 */
67 public void testCreateAndSet() throws BackingStoreException
68 {
69 Preferences prefs = new ServerSystemPreferences();
70
71 Preferences testNode = prefs.node( "testNode" );
72
73 testNode.put( "testNodeKey", "testNodeValue" );
74
75 testNode.sync();
76
77 testNode.putBoolean( "boolKey", true );
78
79 testNode.putByteArray( "arrayKey", new byte[10] );
80
81 testNode.putDouble( "doubleKey", 3.14 );
82
83 testNode.putFloat( "floatKey", ( float ) 3.14 );
84
85 testNode.putInt( "intKey", 345 );
86
87 testNode.putLong( "longKey", 75449559185447L );
88
89 testNode.sync();
90
91 testNode = prefs.node( "testNode" );
92
93 assertEquals( true, testNode.getBoolean( "boolKey", false ) );
94
95 assertTrue( 3.14 == testNode.getDouble( "doubleKey", 9.20 ) );
96
97 assertTrue( (float) 3.14 == testNode.getFloat( "floatKey", (float) 3.90 ) );
98
99 assertEquals( 345, testNode.getInt( "intKey", 87 ) );
100
101 assertEquals( 75449559185447L, testNode.getLong( "longKey", 75449547L ) );
102 }
103
104
105 /***
106 * Tests the creation and use of a new preferences node.
107 *
108 * @throws BackingStoreException if there are failures with the store
109 */
110 public void testCreateAndRemove() throws BackingStoreException
111 {
112 Preferences prefs = new ServerSystemPreferences();
113
114 Preferences testNode = prefs.node( "testNode" );
115
116 testNode.put( "testNodeKey", "testNodeValue" );
117
118 testNode.sync();
119
120 testNode.putBoolean( "boolKey", true );
121
122 testNode.putByteArray( "arrayKey", new byte[10] );
123
124 testNode.putDouble( "doubleKey", 3.14 );
125
126 testNode.putFloat( "floatKey", ( float ) 3.14 );
127
128 testNode.putInt( "intKey", 345 );
129
130 testNode.putLong( "longKey", 75449559185447L );
131
132 testNode.sync();
133
134 testNode = prefs.node( "testNode" );
135
136 assertEquals( true, testNode.getBoolean( "boolKey", false ) );
137
138 assertTrue( 3.14 == testNode.getDouble( "doubleKey", 9.20 ) );
139
140 assertTrue( (float) 3.14 == testNode.getFloat( "floatKey", (float) 3.90 ) );
141
142 assertEquals( 345, testNode.getInt( "intKey", 87 ) );
143
144 assertEquals( 75449559185447L, testNode.getLong( "longKey", 75449547L ) );
145
146 testNode.remove( "doubleKey" );
147
148 testNode.remove( "arrayKey" );
149
150 assertEquals( "no value", testNode.get( "doubleKey", "no value" ) );
151
152 assertEquals( "no value", testNode.get( "arrayKey", "no value" ) );
153
154 testNode.sync();
155
156 assertEquals( "no value", testNode.get( "doubleKey", "no value" ) );
157
158 assertEquals( "no value", testNode.get( "arrayKey", "no value" ) );
159 }
160 }