Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
69   138   13   9.86
4   102   0.19   7
7     1.86  
1    
 
  ConfigAccessTest       Line # 29 69 13 92.5% 0.925
 
  (4)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
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    * Test class.
26    *
27    * @author Michael Meyling
28    */
 
29    public class ConfigAccessTest extends QedeqTestCase {
30   
31    private ConfigAccess con1;
32    private ConfigAccess con2;
33   
 
34  0 toggle public ConfigAccessTest(){
35  0 super();
36    }
37   
 
38  4 toggle public ConfigAccessTest(final String name){
39  4 super(name);
40    }
41   
 
42  4 toggle 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   
 
48  1 toggle 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    // ok
75    }
76    }
77   
78   
 
79  1 toggle 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    // ok
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    // ok
96    }
97  1 try {
98  1 con1.getInteger("testString", 4713);
99  0 fail("Exceptin expected");
100    } catch (Exception e) {
101    // ok
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   
 
121  1 toggle 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   
 
127  1 toggle 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    }