Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
195   373   38   6.5
12   302   0.19   30
30     1.27  
1    
 
  QedeqConfigTest       Line # 33 195 38 89.9% 0.89873415
 
  (21)
 
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.List;
20    import java.util.Vector;
21   
22    import org.qedeq.base.io.IoUtility;
23    import org.qedeq.base.io.Parameters;
24    import org.qedeq.base.test.QedeqTestCase;
25    import org.qedeq.base.utility.EqualsUtility;
26    import org.qedeq.kernel.se.common.Service;
27   
28    /**
29    * Test class.
30    *
31    * @author Michael Meyling
32    */
 
33    public class QedeqConfigTest extends QedeqTestCase {
34   
35    private QedeqConfig con1;
36    private QedeqConfig con2;
37    private File file1;
38    private File file2;
39    private File basis1;
40    private File basis2;
41    private Service service1;
42    private Service service2;
43   
 
44  0 toggle public QedeqConfigTest(){
45  0 super();
46    }
47   
 
48  21 toggle public QedeqConfigTest(final String name){
49  21 super(name);
50    }
51   
 
52  21 toggle public void setUp() throws Exception {
53  21 super.setUp();
54  21 this.service1 = new Service() {
 
55  8 toggle public String getServiceId() {
56  8 return "org.qedeq.kernel.bo.service.logic.SimpleProofFinderPlugin";
57    }
58   
 
59  0 toggle public String getServiceAction() {
60  0 return "action";
61    }
62   
 
63  0 toggle public String getServiceDescription() {
64  0 return "description";
65    }};
66   
67  21 this.service2 = new Service() {
 
68  6 toggle public String getServiceId() {
69  6 return Service.class.toString();
70    }
71   
 
72  0 toggle public String getServiceAction() {
73  0 return "action";
74    }
75   
 
76  0 toggle public String getServiceDescription() {
77  0 return "description";
78    }};
79   
80  21 file1 = getFile("QedeqConfig/qedeq1.properties");
81  21 basis1 = file1.getParentFile();
82  21 this.con1 = new QedeqConfig(file1, "QedeqConfig test 1", basis1);
83  21 file2 = getFile("QedeqConfig/qedeq2.properties");
84  21 basis2 = file2.getParentFile();
85  21 this.con2 = new QedeqConfig(file2, "QedeqConfig test 2", basis2);
86    }
87   
 
88  1 toggle public void testGetBasisDirectory() throws Exception {
89  1 assertEquals(basis1.getCanonicalFile(), con1.getBasisDirectory());
90  1 assertEquals(basis2.getCanonicalFile(), con2.getBasisDirectory());
91    }
92   
 
93  1 toggle public void testGetSetBufferDirectory() throws Exception {
94  1 assertEquals(new File(basis1, "buffer").getCanonicalFile(),
95    con1.getBufferDirectory().getCanonicalFile());
96  1 con1.setBufferDirectory(new File(con1.getBasisDirectory(), "newLocation"));
97  1 assertEquals(new File(basis1, "newLocation").getCanonicalFile(),
98    con1.getBufferDirectory().getCanonicalFile());
99  1 assertEquals(new File(basis2, "buffer").getCanonicalFile(),
100    con2.getBufferDirectory().getCanonicalFile());
101  1 con2.setBufferDirectory(new File(con2.getBasisDirectory(), "newLocation"));
102  1 assertEquals(new File(basis2, "newLocation").getCanonicalFile(),
103    con2.getBufferDirectory().getCanonicalFile());
104    }
105   
 
106  1 toggle public void testGetSetGenerationDirectory() throws Exception {
107  1 assertEquals(new File(basis1, "generated").getCanonicalFile(),
108    con1.getGenerationDirectory().getCanonicalFile());
109  1 con1.setGenerationDirectory(new File(con1.getBasisDirectory(), "newGeneration"));
110  1 assertEquals(new File(basis1, "newGeneration").getCanonicalFile(),
111    con1.getGenerationDirectory().getCanonicalFile());
112  1 assertEquals(new File(basis2, "generated").getCanonicalFile(),
113    con2.getGenerationDirectory().getCanonicalFile());
114  1 con2.setGenerationDirectory(new File(con2.getBasisDirectory(), "newGeneration"));
115  1 assertEquals(new File(basis2, "newGeneration").getCanonicalFile(),
116    con2.getGenerationDirectory().getCanonicalFile());
117    }
118   
 
119  1 toggle public void testGetLocalModulesDirectory() throws Exception {
120  1 assertEquals(new File(basis1, "local").getCanonicalFile(),
121    con1.getLocalModulesDirectory().getCanonicalFile());
122  1 con1.setLocalModulesDirectory(new File(con1.getBasisDirectory(), "newLocal"));
123  1 assertEquals(new File(basis1, "newLocal").getCanonicalFile(),
124    con1.getLocalModulesDirectory().getCanonicalFile());
125  1 assertEquals(new File(basis2, "local").getCanonicalFile(),
126    con2.getLocalModulesDirectory().getCanonicalFile());
127  1 con2.setLocalModulesDirectory(new File(con2.getBasisDirectory(), "newLocal"));
128  1 assertEquals(new File(basis2, "newLocal").getCanonicalFile(),
129    con2.getLocalModulesDirectory().getCanonicalFile());
130    }
131   
 
132  1 toggle public void testGetSetConnectTimeout() throws Exception {
133  1 assertEquals(2002, con1.getConnectionTimeout());
134  1 con1.setConnectionTimeout(1007);
135  1 assertEquals(1007, con1.getConnectionTimeout());
136  1 assertEquals(2000, con2.getConnectionTimeout());
137  1 con2.setConnectionTimeout(1007);
138  1 assertEquals(1007, con2.getConnectionTimeout());
139    }
140   
 
141  1 toggle public void testGetSetReadConnectTimeout() throws Exception {
142  1 assertEquals(1001, con1.getReadTimeout());
143  1 con1.setReadTimeout(2801);
144  1 assertEquals(2801, con1.getReadTimeout());
145  1 assertEquals(1000, con2.getReadTimeout());
146  1 con2.setReadTimeout(1009);
147  1 assertEquals(1009, con2.getReadTimeout());
148    }
149   
 
150  1 toggle public void testGetSetHttpProxyHost() throws Exception {
151  1 final String key = "http.proxyHost";
152  1 final String originalValue = System.getProperty(key);
153  1 if (originalValue != null) {
154  0 System.getProperties().remove(key);
155    }
156   
157  1 assertEquals("proxy", con1.getHttpProxyHost());
158  1 con1.setHttpProxyHost("newProxy");
159  1 assertEquals("newProxy", con1.getHttpProxyHost());
160  1 assertNull(con2.getHttpProxyHost());
161   
162  1 System.setProperty(key, "systemProxy");
163  1 assertEquals("systemProxy", con2.getHttpProxyHost());
164  1 con2.setHttpProxyHost("newProxys");
165  1 assertEquals("newProxys", con2.getHttpProxyHost());
166   
167  1 assertEquals("newProxys", con2.getHttpProxyHost());
168  1 con2.setHttpProxyHost("newProxys2");
169  1 assertEquals("newProxys2", con2.getHttpProxyHost());
170   
171  1 if (originalValue != null) {
172  0 System.setProperty(key, originalValue);
173    } else {
174  1 System.getProperties().remove(key);
175    }
176    }
177   
 
178  1 toggle public void testGetSetHttpProxyPort() throws Exception {
179  1 final String key = "http.proxyPort";
180  1 final String originalValue = System.getProperty(key);
181  1 if (originalValue != null) {
182  0 System.getProperties().remove(key);
183    }
184   
185  1 assertEquals("", con1.getHttpProxyPort());
186  1 con1.setHttpProxyPort("888");
187  1 assertEquals("888", con1.getHttpProxyPort());
188   
189  1 assertNull(con2.getHttpProxyPort());
190  1 System.setProperty(key, "systemPort");
191  1 assertEquals("systemPort", con2.getHttpProxyPort());
192   
193  1 con2.setHttpProxyPort("889");
194  1 assertEquals("889", con2.getHttpProxyPort());
195   
196  1 if (originalValue != null) {
197  0 System.setProperty(key, originalValue);
198    } else {
199  1 System.getProperties().remove(key);
200    }
201   
202    }
203   
 
204  1 toggle public void testGetSetHttpNonProxyHosts() throws Exception {
205  1 final String key = "http.nonProxyHosts";
206  1 final String originalValue = System.getProperty(key);
207  1 if (originalValue != null) {
208  0 System.getProperties().remove(key);
209    }
210   
211  1 assertEquals("none", con1.getHttpNonProxyHosts());
212  1 con1.setHttpNonProxyHosts("all");
213  1 assertEquals("all", con1.getHttpNonProxyHosts());
214   
215  1 assertNull(con2.getHttpNonProxyHosts());
216  1 System.setProperty(key, "systemNon");
217  1 assertEquals("systemNon", con2.getHttpNonProxyHosts());
218   
219  1 con2.setHttpNonProxyHosts("neverland");
220  1 assertEquals("neverland", con2.getHttpNonProxyHosts());
221   
222  1 if (originalValue != null) {
223  0 System.setProperty(key, originalValue);
224    } else {
225  1 System.getProperties().remove(key);
226    }
227   
228    }
229   
 
230  1 toggle public void testGetLogFile() throws Exception {
231  1 assertEquals(new File(basis1.getCanonicalFile(), "search/for/me/log.txt"),
232    con1.getLogFile());
233  1 assertEquals(new File(basis2.getCanonicalFile(), "log/log.txt"),
234    con2.getLogFile());
235    }
236   
 
237  1 toggle public void testGetSaveModuleHistory() throws Exception {
238  1 final String[] history = con1.getModuleHistory();
239  1 assertEquals(12, history.length);
240  1 assertEquals("http://wwww.qedeq.org/0_04_05/doc/sample/qedeq_sample3.xml", history[10]);
241  1 List history0 = new Vector();
242  1 history0.add("We dont need no thought control");
243  1 con1.saveModuleHistory(history0);
244  1 final String[] history02 = con1.getModuleHistory();
245  1 assertEquals(1, history02.length);
246  1 assertEquals("We dont need no thought control", history02[0]);
247  1 final String[] history2 = con2.getModuleHistory();
248  1 assertEquals(0, history2.length);
249    }
250   
 
251  1 toggle public void testGetSetPreviouslyLoadedModules() throws Exception {
252  1 final String[] loaded = con1.getPreviouslyLoadedModules();
253  1 assertEquals(21, loaded.length);
254  1 assertEquals("http://www.qedeq.org/0_04_05/sample/qedeq_error_sample_15.xml", loaded[9]);
255  1 final String[] newLoaded = new String[] {"one", "two", "three"};
256  1 con1.setPreviouslyLoadedModules(newLoaded);
257  1 assertTrue(EqualsUtility.equals(newLoaded, con1.getPreviouslyLoadedModules()));
258  1 final String[] loaded2 = con2.getPreviouslyLoadedModules();
259  1 assertEquals(0, loaded2.length);
260    }
261   
 
262  1 toggle public void testGetSetKeyValueString() throws Exception {
263  1 assertEquals("true", con1.getKeyValue("automaticLogScroll"));
264  1 assertEquals("true", con1.getKeyValue("automaticLogScroll", "false"));
265  1 con1.setKeyValue("automaticLogScroll", "false");
266  1 assertEquals("false", con1.getKeyValue("automaticLogScroll"));
267    }
268   
 
269  1 toggle public void testGetKeyValueStringBoolean() throws Exception {
270  1 assertEquals(true, con1.getKeyValue("automaticLogScroll", false));
271  1 con1.setKeyValue("automaticLogScroll", false);
272  1 assertEquals(false, con1.getKeyValue("automaticLogScroll", true));
273  1 assertEquals("false", con1.getKeyValue("automaticLogScroll"));
274  1 con1.setKeyValue("automaticLogScroll", true);
275  1 assertEquals(true, con1.getKeyValue("automaticLogScroll", false));
276  1 assertEquals(false, con2.getKeyValue("automaticLogScroll2nowhere", false));
277  1 assertEquals(true, con2.getKeyValue("automaticLogScroll3nowhere", true));
278    }
279   
 
280  1 toggle public void testGetKeyValueStringString() throws Exception {
281  1 assertEquals("true", con1.getKeyValue("automaticLogScroll", "false"));
282    }
283   
 
284  1 toggle public void testGetKeyValueStringInt() throws Exception {
285  1 try {
286  1 assertEquals(15, con1.getKeyValue("automaticLogScroll", 15));
287  0 fail("Exception expected");
288    } catch (Exception e) {
289    // ok
290    }
291  1 assertEquals("2002", con1.getKeyValue("connectionTimeout"));
292  1 assertEquals(2002, con1.getKeyValue("connectionTimeout", 1003));
293  1 assertEquals(1003, con1.getKeyValue("connectionTimeoutFee", 1003));
294    }
295   
 
296  1 toggle public void testGetSetServiceValues() {
297  1 Parameters paras = con1.getServiceEntries(service1);
298  1 assertEquals(20, paras.keySet().size());
299  1 assertEquals(6, paras.getInt("conjunctionOrder"));
300  1 assertTrue(paras.getBoolean("boolean"));
301  1 paras = con1.getServiceEntries(service2);
302  1 assertEquals(0, paras.keySet().size());
303  1 paras = con2.getServiceEntries(service2);
304  1 assertEquals(0, paras.keySet().size());
305  1 paras = new Parameters();
306  1 paras.setDefault("mine", "value");
307  1 paras.setDefault("apollo", "11");
308  1 paras.setDefault("cheese", "true");
309  1 con2.setServiceKeyValues(service1, paras);
310  1 assertEquals("value", con2.getServiceKeyValue(service1, "mine", ""));
311  1 assertEquals(11, con2.getServiceKeyValue(service1, "apollo", 13));
312  1 assertEquals(true, con2.getServiceKeyValue(service1, "cheese", false));
313  1 Parameters paras2 = con2.getServiceEntries(service1);
314  1 assertEquals(3, paras2.keySet().size());
315  1 assertEquals("value", paras2.getString("mine"));
316  1 assertEquals("11", paras2.getString("apollo"));
317  1 assertEquals("true", paras2.getString("cheese"));
318  1 con1.setServiceKeyValue(service2, "mine", "value");
319  1 con1.setServiceKeyValue(service2, "apollo", 11);
320  1 con1.setServiceKeyValue(service2, "cheese", true);
321  1 Parameters paras3 = con1.getServiceEntries(service2);
322  1 assertEquals(3, paras3.keySet().size());
323  1 assertEquals("value", paras3.getString("mine"));
324  1 assertEquals("11", paras3.getString("apollo"));
325  1 assertEquals("true", paras3.getString("cheese"));
326    }
327   
 
328  1 toggle public void testCreateAbsolutePath() throws Exception {
329  1 new File(System.getProperty("file.separator"), "top").getCanonicalFile().equals(
330    con1.createAbsolutePath(System.getProperty("file.separator") + "top"));
331    }
332   
 
333  1 toggle public void testIsSetIsTraceOn() {
334  1 assertTrue(con1.isTraceOn());
335  1 con1.setTraceOn(false);
336  1 assertFalse(con1.isTraceOn());
337  1 assertFalse(con2.isTraceOn());
338  1 con2.setTraceOn(true);
339  1 assertTrue(con2.isTraceOn());
340    }
341   
 
342  1 toggle public void testIsSetAutoReloadLastSessionChecked() {
343  1 assertTrue(con1.isAutoReloadLastSessionChecked());
344  1 con1.setAutoReloadLastSessionChecked(false);
345  1 assertFalse(con1.isAutoReloadLastSessionChecked());
346  1 assertTrue(con2.isAutoReloadLastSessionChecked());
347  1 con2.setAutoReloadLastSessionChecked(true);
348  1 assertTrue(con2.isAutoReloadLastSessionChecked());
349    }
350   
 
351  1 toggle public void testStore() throws Exception {
352  1 final File file3 = new File(getOutdir(), "testQedeqConfig/qedeq3.properties");
353  1 final File basis3 = file3.getParentFile();
354  1 IoUtility.deleteDir(basis3, true);
355  1 QedeqConfig con3 = new QedeqConfig(file3, "QedeqConfig test 3", basis3);
356  1 assertFalse(12345 == con3.getConnectionTimeout());
357  1 con3.setConnectionTimeout(12345);
358  1 con3.store();
359  1 QedeqConfig con4 = new QedeqConfig(file3, "ho", basis3);
360  1 assertEquals(12345, con4.getConnectionTimeout());
361  1 final File file5 = new File(getOutdir(), "testQedeqConfig/qedeq5.properties/dir");
362  1 IoUtility.createNecessaryDirectories(file5);
363  1 final File file6 = new File(getOutdir(), "testQedeqConfig/qedeq5.properties");
364  1 QedeqConfig con5 = new QedeqConfig(file6, "ho", file6.getParentFile());
365  1 try {
366  1 con5.store();
367  0 fail("Exception expected, file name is already a directory!");
368    } catch (Exception e) {
369    // ok
370    }
371    }
372   
373    }