|
1 |
| package org.jconfig; |
|
2 |
| |
|
3 |
| import junit.framework.TestCase; |
|
4 |
| |
|
5 |
| import org.jconfig.handler.ConfigurationHandler; |
|
6 |
| import org.jconfig.handler.PropertiesFileHandler; |
|
7 |
| |
|
8 |
| import java.util.HashMap; |
|
9 |
| import java.util.Map; |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| public class ConfigurationManagerTest extends TestCase { |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
10
| public ConfigurationManagerTest(String arg0) {
|
|
23 |
10
| super(arg0);
|
|
24 |
| } |
|
25 |
| |
|
26 |
0
| public static void main(String[] args) {
|
|
27 |
0
| junit.textui.TestRunner.run(ConfigurationManagerTest.class);
|
|
28 |
| } |
|
29 |
| |
|
30 |
1
| public void testGetInstance() {
|
|
31 |
1
| ConfigurationManager cm = ConfigurationManager.getInstance();
|
|
32 |
1
| assertNotNull(cm);
|
|
33 |
| } |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
1
| public void testGetConfiguration() {
|
|
39 |
1
| Configuration config = ConfigurationManager.getConfiguration();
|
|
40 |
1
| assertNotNull(config);
|
|
41 |
| } |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
1
| public void testGetConfigurationString() {
|
|
47 |
1
| Configuration configXyz = ConfigurationManager.getConfiguration("xyz");
|
|
48 |
1
| Configuration configAbc = ConfigurationManager.getConfiguration("abc");
|
|
49 |
1
| assertNotNull(configXyz);
|
|
50 |
1
| assertNotNull(configAbc);
|
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
1
| public void testSaveConfigurationHandlerConfiguration() {
|
|
61 |
| } |
|
62 |
| |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
1
| public void testReload() {
|
|
67 |
1
| Configuration config = ConfigurationManager.getConfiguration("default");
|
|
68 |
| } |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
1
| public void testSaveString() {
|
|
77 |
| } |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
1
| public void testAddPropertyListener() throws Exception {
|
|
83 |
1
| ConfigurationHandler ish = new PropertiesFileHandler("jconfig.properties");
|
|
84 |
| |
|
85 |
1
| ConfigurationManager.getInstance().load(ish,"default");
|
|
86 |
1
| ConfigurationManager manager = ConfigurationManager.getInstance();
|
|
87 |
| } |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
0
| public void _testFileChanged() {
|
|
94 |
0
| Configuration config = ConfigurationManager.getConfiguration();
|
|
95 |
0
| WaitingHelper helper = new WaitingHelper();
|
|
96 |
0
| helper.run();
|
|
97 |
0
| config.getProperty("SOMETHING", "SOMETHING");
|
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| } |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
1
| public void testInputStreamHandler() throws Exception {
|
|
109 |
1
| ConfigurationHandler ish = new PropertiesFileHandler("jconfig.properties");
|
|
110 |
| |
|
111 |
1
| Configuration config = ConfigurationManager.getConfiguration("default");
|
|
112 |
1
| ConfigurationManager.getInstance().load(ish,"default");
|
|
113 |
1
| assertEquals("8080",config.getProperty("http.proxyPort"));
|
|
114 |
1
| assertEquals("192.168.3.1",config.getProperty("http.proxyHost"));
|
|
115 |
| } |
|
116 |
| |
|
117 |
1
| public void testGetConfigurationWithName() {
|
|
118 |
1
| Configuration configXyz = ConfigurationManager.getConfiguration("test");
|
|
119 |
1
| assertNotNull(configXyz);
|
|
120 |
1
| assertTrue(!configXyz.isNew());
|
|
121 |
1
| String special = configXyz.getProperty("special");
|
|
122 |
1
| assertEquals("one",special);
|
|
123 |
| } |
|
124 |
| |
|
125 |
1
| public void testGetConfigurationNames() {
|
|
126 |
1
| String[] names = ConfigurationManager.getInstance().getConfigurationNames();
|
|
127 |
1
| Map map = new HashMap();
|
|
128 |
1
| for (int i = 0; i < names.length; i++) {
|
|
129 |
3
| map.put(names[i], names[i]);
|
|
130 |
| } |
|
131 |
1
| assertNotNull(names);
|
|
132 |
1
| assertNotNull(map.get("default"));
|
|
133 |
1
| assertNotNull(map.get("test"));
|
|
134 |
| } |
|
135 |
| } |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
| class WaitingHelper implements Runnable { |
|
144 |
| private boolean state = true; |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
0
| public void run() {
|
|
149 |
0
| int i = 0;
|
|
150 |
0
| while(i<999999999) {
|
|
151 |
0
| i++;
|
|
152 |
| } |
|
153 |
| } |
|
154 |
| |
|
155 |
| } |