1 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 35 public class XMLConfigurationFactoryTest extends TestCase { 36 37 public XMLConfigurationFactoryTest(String testName) { 38 super(testName); 39 } 40 41 protected void setUp() throws Exception { 42 } 43 44 protected void tearDown() throws Exception { 45 } 46 47 public static Test suite() { 48 TestSuite suite = new TestSuite(XMLConfigurationFactoryTest.class); 49 50 return suite; 51 } 52 53 56 public void testConfig() throws Exception { 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 Configuration config = instance.getConfig(java.lang.String .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 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 |