001: /*
002: * CoadunationLib: The coaduntion implementation library.
003: * Copyright (C) 2006 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * XMLConfigurationFactoryTest.java
020: *
021: * JUnit based test
022: */
023:
024: package com.rift.coad.lib.configuration.xml;
025:
026: import junit.framework.*;
027: import com.rift.coad.lib.configuration.ConfigurationFactory;
028: import com.rift.coad.lib.configuration.ConfigurationException;
029: import com.rift.coad.lib.configuration.Configuration;
030:
031: /**
032: *
033: * @author mincemeat
034: */
035: public class XMLConfigurationFactoryTest extends TestCase {
036:
037: public XMLConfigurationFactoryTest(String testName) {
038: super (testName);
039: }
040:
041: protected void setUp() throws Exception {
042: }
043:
044: protected void tearDown() throws Exception {
045: }
046:
047: public static Test suite() {
048: TestSuite suite = new TestSuite(
049: XMLConfigurationFactoryTest.class);
050:
051: return suite;
052: }
053:
054: /**
055: * Test of class com.rift.coad.lib.configuration.xml.XMLConfigurationFactory.
056: */
057: public void testConfig() throws Exception {
058: System.out.println("getConfig");
059:
060: ConfigurationFactory instance = ConfigurationFactory
061: .getInstance();
062:
063: if (instance == null) {
064: fail("Failed to load configuration.");
065: }
066:
067: // retrieve a general section
068: Configuration config = instance
069: .getConfig(java.lang.String.class);
070: if (config.getString("gen1").equals("value 1") == false) {
071: fail("Should have found [value 1] got ["
072: + config.getString("gen1") + "]");
073: } else if (config.getString("gen2").equals("value 2") == false) {
074: fail("Should have found [value 2] got ["
075: + config.getString("gen1") + "]");
076: } else if (config.getLong("gen3") != 3) {
077: fail("Should have found [3] got [" + config.getLong("gen3")
078: + "]");
079: }
080:
081: // the local class data
082: config = instance.getConfig(XMLConfigurationFactoryTest.class);
083: if (config.getString("gen1").equals("value 1") == false) {
084: fail("Should have found [value 1] got ["
085: + config.getString("gen1") + "]");
086: } else if (config.getString("gen2").equals("value 2") == false) {
087: fail("Should have found [value 2] got ["
088: + config.getString("gen1") + "]");
089: } else if (config.getLong("gen3") != 3) {
090: fail("Should have found [3] got [" + config.getLong("gen3")
091: + "]");
092: } else if (config.getString("key1").equals("value 4") == false) {
093: fail("Should have found [value 4].");
094: } else if (config.getString("key2").equals("value 5") == false) {
095: fail("Should have found [value 5].");
096: } else if (config.getLong("key3") != 6) {
097: fail("Should have found [6] got [" + config.getLong("key3")
098: + "]");
099: } else if (config.isBoolean("key4") != true) {
100: fail("Check for is boolean on a boolean value failed.");
101: } else if (config.getBoolean("key4") != true) {
102: fail("Should have found [true] got ["
103: + config.getBoolean("key4") + "]");
104: } else if (config.getBoolean("key5") != false) {
105: fail("Should have found [false] got ["
106: + config.getBoolean("key4") + "]");
107: }
108:
109: }
110:
111: }
|