KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > configuration > xml > XMLConfigurationFactoryTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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 GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * XMLConfigurationFactoryTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.configuration.xml;
25
26 import junit.framework.*;
27 import com.rift.coad.lib.configuration.ConfigurationFactory;
28 import com.rift.coad.lib.configuration.ConfigurationException;
29 import com.rift.coad.lib.configuration.Configuration;
30
31 /**
32  *
33  * @author mincemeat
34  */

35 public class XMLConfigurationFactoryTest extends TestCase {
36     
37     public XMLConfigurationFactoryTest(String JavaDoc testName) {
38         super(testName);
39     }
40
41     protected void setUp() throws Exception JavaDoc {
42     }
43
44     protected void tearDown() throws Exception JavaDoc {
45     }
46
47     public static Test suite() {
48         TestSuite suite = new TestSuite(XMLConfigurationFactoryTest.class);
49         
50         return suite;
51     }
52
53     /**
54      * Test of class com.rift.coad.lib.configuration.xml.XMLConfigurationFactory.
55      */

56     public void testConfig() throws Exception JavaDoc {
57         System.out.println("getConfig");
58         
59         ConfigurationFactory instance = ConfigurationFactory.getInstance();
60         
61         if (instance == null) {
62             fail("Failed to load configuration.");
63         }
64         
65         // retrieve a general section
66
Configuration config = instance.getConfig(java.lang.String JavaDoc.class);
67         if (config.getString("gen1").equals("value 1") == false) {
68             fail("Should have found [value 1] got [" + config.getString("gen1") + "]");
69         } else if (config.getString("gen2").equals("value 2") == false) {
70             fail("Should have found [value 2] got [" + config.getString("gen1") + "]");
71         } else if (config.getLong("gen3") != 3) {
72             fail("Should have found [3] got [" + config.getLong("gen3") + "]");
73         }
74         
75         // the local class data
76
config = instance.getConfig(XMLConfigurationFactoryTest.class);
77         if (config.getString("gen1").equals("value 1") == false) {
78             fail("Should have found [value 1] got [" + config.getString("gen1") + "]");
79         } else if (config.getString("gen2").equals("value 2") == false) {
80             fail("Should have found [value 2] got [" + config.getString("gen1") + "]");
81         } else if (config.getLong("gen3") != 3) {
82             fail("Should have found [3] got [" + config.getLong("gen3") + "]");
83         } else if (config.getString("key1").equals("value 4") == false) {
84             fail("Should have found [value 4].");
85         } else if (config.getString("key2").equals("value 5") == false) {
86             fail("Should have found [value 5].");
87         } else if (config.getLong("key3") != 6) {
88             fail("Should have found [6] got [" + config.getLong("key3") + "]");
89         } else if (config.isBoolean("key4") != true) {
90             fail("Check for is boolean on a boolean value failed.");
91         } else if (config.getBoolean("key4") != true) {
92             fail("Should have found [true] got [" + config.getBoolean("key4") +
93                     "]");
94         } else if (config.getBoolean("key5") != false) {
95             fail("Should have found [false] got [" +
96                     config.getBoolean("key4") + "]");
97         }
98         
99     }
100     
101 }
102
Popular Tags