KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ldap > server > prefs > ServerSystemPreferencesTest


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
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 JavaDoc;
23 import java.util.prefs.Preferences JavaDoc;
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 JavaDoc
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 JavaDoc
51     {
52         Preferences JavaDoc prefs = new ServerSystemPreferences();
53
54         Preferences JavaDoc 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 JavaDoc
68     {
69         Preferences JavaDoc prefs = new ServerSystemPreferences();
70
71         Preferences JavaDoc 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 JavaDoc
111     {
112         Preferences JavaDoc prefs = new ServerSystemPreferences();
113
114         Preferences JavaDoc 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 }
161
Popular Tags