1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.se.config; |
17 |
|
|
18 |
|
import java.io.File; |
19 |
|
import java.util.Map; |
20 |
|
|
21 |
|
import org.qedeq.base.io.IoUtility; |
22 |
|
import org.qedeq.base.test.QedeqTestCase; |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
@author |
28 |
|
|
|
|
| 92.5% |
Uncovered Elements: 6 (80) |
Complexity: 13 |
Complexity Density: 0.19 |
|
29 |
|
public class ConfigAccessTest extends QedeqTestCase { |
30 |
|
|
31 |
|
private ConfigAccess con1; |
32 |
|
private ConfigAccess con2; |
33 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
34 |
0
|
public ConfigAccessTest(){... |
35 |
0
|
super(); |
36 |
|
} |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
38 |
4
|
public ConfigAccessTest(final String name){... |
39 |
4
|
super(name); |
40 |
|
} |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
42 |
4
|
public void setUp() throws Exception {... |
43 |
4
|
super.setUp(); |
44 |
4
|
this.con1 = new ConfigAccess(getFile("ConfigAccess/con1.properties"), "con1 test"); |
45 |
4
|
this.con2 = new ConfigAccess(getFile("ConfigAccess/con2.properties"), "con2 test"); |
46 |
|
} |
47 |
|
|
|
|
| 96.2% |
Uncovered Elements: 1 (26) |
Complexity: 4 |
Complexity Density: 0.18 |
1
PASS
|
|
48 |
1
|
public void testStore() throws Exception {... |
49 |
1
|
final File dir = new File(getOutdir(), "testConfigAccess"); |
50 |
1
|
IoUtility.deleteDir(dir, true); |
51 |
1
|
final File file = new File(dir, "con3.properties"); |
52 |
1
|
final ConfigAccess con3 = new ConfigAccess(file, "never"); |
53 |
1
|
con3.setString("testValue", "we all live in a yellow submarine"); |
54 |
1
|
con3.store(); |
55 |
1
|
assertEquals("we all live in a yellow submarine", con3.getString("testValue")); |
56 |
1
|
final StringBuffer buffer = new StringBuffer(); |
57 |
1
|
IoUtility.loadFile(file, buffer, "ISO-8859-1"); |
58 |
1
|
assertTrue(buffer.indexOf("never") > 0); |
59 |
1
|
final ConfigAccess con4 = new ConfigAccess(file, "never"); |
60 |
1
|
assertEquals("we all live in a yellow submarine", con4.getString("testValue")); |
61 |
1
|
try { |
62 |
1
|
final String sep = System.getProperty("file.separator"); |
63 |
1
|
String forbiddenName = ""; |
64 |
10001
|
for (int i = 0; i < 10000; i++) { |
65 |
10000
|
forbiddenName += sep; |
66 |
|
} |
67 |
10001
|
for (int i = 0; i < 10000; i++) { |
68 |
10000
|
forbiddenName += "|"; |
69 |
|
} |
70 |
1
|
final File file2 = new File(forbiddenName); |
71 |
1
|
new ConfigAccess(file2, "never"); |
72 |
0
|
fail("Exception expected"); |
73 |
|
} catch (Exception e) { |
74 |
|
|
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
|
|
|
|
| 90% |
Uncovered Elements: 3 (30) |
Complexity: 4 |
Complexity Density: 0.13 |
1
PASS
|
|
79 |
1
|
public void testGetter() throws Exception {... |
80 |
1
|
assertEquals(4711, con1.getInteger("testInteger")); |
81 |
1
|
assertEquals(4711, con1.getInteger("testInteger", 4713)); |
82 |
1
|
assertEquals(4713, con1.getInteger("testIntegerNonExisting", 4713)); |
83 |
1
|
try { |
84 |
1
|
con1.getInteger("testIntegerNonExisting2"); |
85 |
0
|
fail("Exceptin expected"); |
86 |
|
} catch (Exception e) { |
87 |
|
|
88 |
|
} |
89 |
1
|
assertEquals("more light", con1.getString("testString")); |
90 |
1
|
assertEquals("", con1.getString("testEmpty")); |
91 |
1
|
try { |
92 |
1
|
con1.getInteger("testString"); |
93 |
0
|
fail("Exceptin expected"); |
94 |
|
} catch (Exception e) { |
95 |
|
|
96 |
|
} |
97 |
1
|
try { |
98 |
1
|
con1.getInteger("testString", 4713); |
99 |
0
|
fail("Exceptin expected"); |
100 |
|
} catch (Exception e) { |
101 |
|
|
102 |
|
} |
103 |
1
|
assertEquals("t1", con2.getString("test.t1")); |
104 |
1
|
assertEquals("t2", con2.getString("test.t2")); |
105 |
1
|
assertEquals("t2", con2.getString("test.t2", "default")); |
106 |
1
|
assertEquals("default", con2.getString("dontexist", "default")); |
107 |
1
|
final Map test = con2.getProperties("test."); |
108 |
1
|
assertEquals(2, test.size()); |
109 |
1
|
assertNull(test.get("test.t1")); |
110 |
1
|
assertNull(test.get("test.t2")); |
111 |
1
|
assertEquals("t1", test.get("t1")); |
112 |
1
|
assertEquals("t2", test.get("t2")); |
113 |
1
|
assertEquals(0, con2.getProperties("notexisting").size()); |
114 |
1
|
final String[] values = con2.getStringProperties("test."); |
115 |
1
|
assertEquals(2, values.length); |
116 |
1
|
assertEquals("t1", values[0]); |
117 |
1
|
assertEquals("t2", values[1]); |
118 |
1
|
assertEquals(0, con2.getStringProperties("notexisting").length); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
121 |
1
|
public void testRemoveProperty() throws Exception {... |
122 |
1
|
assertEquals(4711, con1.getInteger("testInteger", 4713)); |
123 |
1
|
con1.removeProperty("testInteger"); |
124 |
1
|
assertEquals(4713, con1.getInteger("testInteger", 4713)); |
125 |
|
} |
126 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
127 |
1
|
public void testRemoveProperties() {... |
128 |
1
|
assertEquals("t1", con2.getString("test.t1")); |
129 |
1
|
assertEquals("t2", con2.getString("test.t2")); |
130 |
1
|
assertEquals("t2", con2.getString("test.t2", "default")); |
131 |
1
|
assertEquals("default", con2.getString("dontexist", "default")); |
132 |
1
|
Map test = con2.getProperties("test."); |
133 |
1
|
assertEquals(2, test.size()); |
134 |
1
|
con2.removeProperties("test."); |
135 |
1
|
test = con2.getProperties("test."); |
136 |
1
|
assertEquals(0, test.size()); |
137 |
|
} |
138 |
|
} |