|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| package org.jconfig.parser; |
|
8 |
| |
|
9 |
| import java.io.File; |
|
10 |
| |
|
11 |
| import junit.framework.TestCase; |
|
12 |
| |
|
13 |
| import org.jconfig.Configuration; |
|
14 |
| import org.jconfig.ConfigurationManager; |
|
15 |
| import org.jconfig.handler.XMLFileHandler; |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| public class CDataConfigParserTest extends TestCase { |
|
26 |
| |
|
27 |
1
| public CDataConfigParserTest(String arg0) {
|
|
28 |
1
| super(arg0);
|
|
29 |
| } |
|
30 |
| |
|
31 |
0
| public static void main(String[] args) {
|
|
32 |
0
| junit.textui.TestRunner.run(CDataConfigParserTest.class);
|
|
33 |
| } |
|
34 |
| |
|
35 |
1
| public void testParseCDataConfig() {
|
|
36 |
1
| System.setProperty("jconfig.parser","org.jconfig.parser.CDataConfigParser");
|
|
37 |
1
| Configuration config = ConfigurationManager.getConfiguration("advanced");
|
|
38 |
1
| String world = config.getProperty("hello");
|
|
39 |
1
| assertEquals("world",world);
|
|
40 |
1
| String escape = config.getProperty("escapetest");
|
|
41 |
1
| assertEquals(escape,"this\nis\nme");
|
|
42 |
1
| String special = config.getProperty("special",null,"inner");
|
|
43 |
1
| assertEquals("one",special);
|
|
44 |
1
| System.setProperty("jconfig.parser","org.jconfig.parser.DefaultConfigParser");
|
|
45 |
| } |
|
46 |
| |
|
47 |
0
| public void _testParseSaveLoadNestedConfig() {
|
|
48 |
0
| System.setProperty("jconfig.parser","org.jconfig.parser.CDataConfigParser");
|
|
49 |
0
| try {
|
|
50 |
0
| XMLFileHandler fileHandler = new XMLFileHandler();
|
|
51 |
0
| String filename = System.getProperty("java.io.tmpdir")+"cdata_test_config.xml";
|
|
52 |
0
| File file = new File(filename);
|
|
53 |
0
| fileHandler.setFile(file);
|
|
54 |
0
| Configuration config = ConfigurationManager.getConfiguration("advanced");
|
|
55 |
0
| fileHandler.store(config);
|
|
56 |
0
| config = fileHandler.load(file, "MyTest");
|
|
57 |
0
| String special = config.getProperty("special",null,"inner");
|
|
58 |
0
| assertEquals("one",special);
|
|
59 |
| } |
|
60 |
| catch (Exception e) { |
|
61 |
0
| e.printStackTrace();
|
|
62 |
0
| fail("unexpected exception");
|
|
63 |
| } |
|
64 |
| } |
|
65 |
| |
|
66 |
| } |