1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.directory.server.core.prefs;
21
22
23 import org.apache.directory.server.core.DirectoryService;
24 import org.apache.directory.server.core.integ.CiRunner;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.assertNotNull;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30
31 import java.util.prefs.BackingStoreException;
32 import java.util.prefs.Preferences;
33
34
35
36
37
38
39
40
41 @RunWith ( CiRunner.class )
42 public class PreferencesIT
43 {
44 public static DirectoryService service;
45
46
47 @Test
48 public void testSystemRoot()
49 {
50 ServerPreferencesFactory factory = new ServerPreferencesFactory( service );
51 Preferences prefs = factory.systemRoot();
52
53 assertNotNull( prefs );
54 assertEquals( "sysPrefRoot", prefs.get( "prefNodeName", "default value" ) );
55 }
56
57
58
59
60
61
62
63 @Test
64 public void testRoot() throws Exception
65 {
66 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
67 assertEquals( "sysPrefRoot", prefs.get( "prefNodeName", "not the value" ) );
68 }
69
70
71
72
73
74
75
76 @Test
77 public void testCreate() throws BackingStoreException
78 {
79 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
80 Preferences testNode = prefs.node( "testNode" );
81
82 testNode.put( "cn", "testNodeValue" );
83 testNode.sync();
84 }
85
86
87
88
89
90
91
92 @Test
93 public void testCreateAndSetBoolean() throws BackingStoreException
94 {
95 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
96 Preferences testNode = prefs.node( "testNode" );
97 testNode.putBoolean( "cn", false );
98 testNode.sync();
99 testNode = prefs.node( "testNode" );
100 assertEquals( false, testNode.getBoolean( "cn", false ) );
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 @Test
128 public void testCreateAndSetDouble() throws BackingStoreException
129 {
130 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
131 Preferences testNode = prefs.node( "testNode" );
132 testNode.putDouble( "cn", 3.14 );
133 testNode.sync();
134 testNode = prefs.node( "testNode" );
135 assertTrue( 3.14 == testNode.getDouble( "cn", 9.20 ) );
136 }
137
138
139
140
141
142
143
144 @Test
145 public void testCreateAndSetFloat() throws BackingStoreException
146 {
147 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
148 Preferences testNode = prefs.node( "testNode" );
149 testNode.putFloat( "cn", ( float ) 9.20 );
150 testNode.sync();
151 testNode = prefs.node( "testNode" );
152 assertTrue( ( float ) 9.20 == testNode.getFloat( "cn", ( float ) 9.20 ) );
153 }
154
155
156
157
158
159
160
161 @Test
162 public void testCreateAndSetInt() throws BackingStoreException
163 {
164 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
165 Preferences testNode = prefs.node( "testNode" );
166 testNode.putInt( "cn", 345 );
167 testNode.sync();
168 testNode = prefs.node( "testNode" );
169 assertTrue( 345 == testNode.getInt( "cn", 345 ) );
170 }
171
172
173
174
175
176
177
178 @Test
179 public void testCreateAndSetLong() throws BackingStoreException
180 {
181 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
182 Preferences testNode = prefs.node( "testNode" );
183 testNode.putLong( "cn", 75449559185447L );
184 testNode.sync();
185 testNode = prefs.node( "testNode" );
186 assertTrue( 75449559185447L == testNode.getLong( "cn", 75449559185447L ) );
187 }
188
189
190
191
192
193
194
195 @Test
196 public void testCreateAndRemove() throws BackingStoreException
197 {
198 ServerSystemPreferences prefs = new ServerSystemPreferences( service );
199 Preferences testNode = prefs.node( "testNode" );
200
201 testNode.put( "cn", "testNodeValue" );
202 testNode.putInt( "roomNumber", 345 );
203 testNode.sync();
204
205 testNode = prefs.node( "testNode" );
206 assertEquals( 345, testNode.getInt( "roomNumber", 87 ) );
207 testNode.remove( "cn" );
208 testNode.remove( "roomNumber" );
209 testNode.sync();
210
211 assertEquals( "no value", testNode.get( "cn", "no value" ) );
212 assertEquals( "no value", testNode.get( "roomNumber", "no value" ) );
213 }
214 }