|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| package org.jconfig; |
|
7 |
| |
|
8 |
| import java.io.File; |
|
9 |
| import org.jconfig.handler.XMLFileHandler; |
|
10 |
| import junit.framework.TestCase; |
|
11 |
| import java.util.Properties; |
|
12 |
| import org.jconfig.parser.NestedConfigParser; |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| public class InheritanceTest extends TestCase { |
|
20 |
| |
|
21 |
10
| public InheritanceTest(String name) {
|
|
22 |
10
| super(name);
|
|
23 |
| } |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
0
| public static void main(String[] args) {
|
|
30 |
0
| junit.textui.TestRunner.run(InheritanceTest.class);
|
|
31 |
| } |
|
32 |
| |
|
33 |
10
| protected void setUp() {
|
|
34 |
10
| System.setProperty("jconfig.parser", NestedConfigParser.class.getName());
|
|
35 |
10
| ConfigurationManager.getInstance().removeConfiguration("inheritance");
|
|
36 |
10
| ConfigurationManager.getInstance().removeConfiguration("base");
|
|
37 |
| } |
|
38 |
| |
|
39 |
10
| protected void tearDown() {
|
|
40 |
| } |
|
41 |
| |
|
42 |
1
| public void testGetAllCategoryNames() {
|
|
43 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
44 |
1
| String[] names = cfg.getCategoryNames();
|
|
45 |
1
| assertEquals(10,names.length);
|
|
46 |
| } |
|
47 |
| |
|
48 |
1
| public void testGetNumberOfCategories() {
|
|
49 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
50 |
1
| int cnt = cfg.getNumberOfCategories();
|
|
51 |
1
| assertEquals(10,cnt);
|
|
52 |
| } |
|
53 |
| |
|
54 |
1
| public void testGetProperties() {
|
|
55 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
56 |
1
| Properties props = cfg.getProperties();
|
|
57 |
1
| assertEquals(6,props.size());
|
|
58 |
| } |
|
59 |
| |
|
60 |
1
| public void testGetIntProperty() {
|
|
61 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
62 |
1
| int port = cfg.getIntProperty("port",-1,"testme");
|
|
63 |
1
| assertEquals(8080,port);
|
|
64 |
| } |
|
65 |
| |
|
66 |
1
| public void testGetIntProperty2() {
|
|
67 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
68 |
1
| int number = cfg.getIntProperty("number",-1);
|
|
69 |
1
| assertEquals(100,number);
|
|
70 |
| } |
|
71 |
| |
|
72 |
1
| public void testGetLongProperty() {
|
|
73 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
74 |
1
| long number = cfg.getLongProperty("longValue",-1,"simpleTypes");
|
|
75 |
1
| assertEquals(326781,number);
|
|
76 |
| } |
|
77 |
| |
|
78 |
1
| public void testGetBooleanProperty() {
|
|
79 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
80 |
1
| boolean ret = cfg.getBooleanProperty("booleanValue",false,"simpleTypes");
|
|
81 |
1
| assertTrue(ret);
|
|
82 |
| } |
|
83 |
| |
|
84 |
1
| public void testGetCharProperty() {
|
|
85 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
86 |
1
| char n = cfg.getCharProperty("charValue",'N',"simpleTypes");
|
|
87 |
1
| assertEquals(n,'C');
|
|
88 |
| } |
|
89 |
| |
|
90 |
1
| public void testGetDoubleProperty() {
|
|
91 |
1
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
92 |
1
| double d = cfg.getDoubleProperty("doubleValue",-1.0,"simpleTypes");
|
|
93 |
1
| assertTrue((d==12.3));
|
|
94 |
| } |
|
95 |
| |
|
96 |
1
| public void testGetArray() {
|
|
97 |
1
| Configuration config = ConfigurationManager.getConfiguration("inheritance");
|
|
98 |
1
| String[] ar = config.getArray("array");
|
|
99 |
1
| assertNotNull(ar);
|
|
100 |
1
| assertEquals("is",ar[0]);
|
|
101 |
1
| assertEquals("out",ar[3]);
|
|
102 |
1
| ar = config.getArray("arr",new String[]{"hello","world"});
|
|
103 |
1
| assertNotNull(ar);
|
|
104 |
1
| assertEquals("world",ar[1]);
|
|
105 |
1
| ar = config.getArray("complexArray",new String[]{"hello","world"},"MyApp");
|
|
106 |
1
| assertNotNull(ar);
|
|
107 |
1
| assertEquals("hello",ar[0]);
|
|
108 |
1
| assertEquals("world",ar[1]);
|
|
109 |
| } |
|
110 |
| |
|
111 |
0
| public void _testSaveConfig() {
|
|
112 |
0
| Configuration cfg = ConfigurationManager.getConfiguration("inheritance");
|
|
113 |
0
| try {
|
|
114 |
0
| String fileName = System.getProperty("java.io.tmpdir")+File.separator+"test_config.xml";
|
|
115 |
0
| XMLFileHandler handler = new XMLFileHandler(fileName);
|
|
116 |
0
| handler.store(cfg);
|
|
117 |
| } |
|
118 |
| catch (Exception e) { |
|
119 |
0
| e.printStackTrace();
|
|
120 |
0
| fail("unexpected exception");
|
|
121 |
| } |
|
122 |
| } |
|
123 |
| |
|
124 |
| } |