|
1 |
| package org.jconfig; |
|
2 |
| |
|
3 |
| import junit.framework.TestCase; |
|
4 |
| import java.io.File; |
|
5 |
| import org.jconfig.handler.*; |
|
6 |
| import org.jconfig.parser.DefaultConfigParser; |
|
7 |
| import org.jconfig.parser.NestedConfigParser; |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| public class LoadSaveTest extends TestCase { |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
2
| public LoadSaveTest(String arg0) {
|
|
21 |
2
| super(arg0);
|
|
22 |
| } |
|
23 |
| |
|
24 |
0
| public static void main(String[] args) {
|
|
25 |
0
| junit.textui.TestRunner.run(LoadSaveTest.class);
|
|
26 |
| } |
|
27 |
| |
|
28 |
2
| public void setUp() throws Exception {
|
|
29 |
2
| System.setProperty("jconfig.parser", DefaultConfigParser.class.getName());
|
|
30 |
| } |
|
31 |
| |
|
32 |
1
| public void testGetInstance() {
|
|
33 |
1
| ConfigurationManager cm = ConfigurationManager.getInstance();
|
|
34 |
1
| Configuration config = ConfigurationManager.getConfiguration("test_ls");
|
|
35 |
1
| assertNotNull(config);
|
|
36 |
1
| String var = config.getVariable("user.name");
|
|
37 |
1
| assertEquals("developer",var);
|
|
38 |
1
| try {
|
|
39 |
1
| cm.save("test_ls");
|
|
40 |
| } |
|
41 |
| catch (Exception e) { |
|
42 |
0
| fail("unexpected exception");
|
|
43 |
| } |
|
44 |
1
| cm.removeConfiguration("test_ls");
|
|
45 |
1
| config = ConfigurationManager.getConfiguration("test_ls");
|
|
46 |
1
| assertNotNull(config);
|
|
47 |
1
| var = config.getVariable("user.name");
|
|
48 |
1
| assertEquals("developer",var);
|
|
49 |
| } |
|
50 |
| |
|
51 |
1
| public void testLoadAndSaveConfigEscape() {
|
|
52 |
1
| System.setProperty("jconfig.parser", NestedConfigParser.class.getName());
|
|
53 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
54 |
1
| try {
|
|
55 |
1
| cfg.setProperty("path1","<testme\">","addon");
|
|
56 |
1
| String fileName = System.getProperty("java.io.tmpdir")+File.separator+"test_config.xml";
|
|
57 |
1
| XMLFileHandler handler = new XMLFileHandler(fileName);
|
|
58 |
1
| handler.store(cfg);
|
|
59 |
1
| Configuration new_cfg = handler.load("just_a_test");
|
|
60 |
1
| assertEquals("<testme\">",new_cfg.getProperty("path1",null,"addon"));
|
|
61 |
| } |
|
62 |
| catch (Exception e) { |
|
63 |
0
| e.printStackTrace();
|
|
64 |
0
| fail("unexpected exception");
|
|
65 |
| } |
|
66 |
| } |
|
67 |
| } |