1 51 package org.apache.avalon.framework.configuration.test; 52 53 import junit.framework.TestCase; 54 55 import org.apache.avalon.framework.configuration.Configuration; 56 import org.apache.avalon.framework.configuration.DefaultConfiguration; 57 58 63 public final class DefaultConfigurationTestCase extends TestCase 64 { 65 private DefaultConfiguration m_configuration; 66 67 public DefaultConfigurationTestCase() 68 { 69 this("DefaultConfiguration Test Case"); 70 } 71 72 public DefaultConfigurationTestCase( String name ) 73 { 74 super( name ); 75 } 76 77 public void setUp() 78 { 79 m_configuration = new DefaultConfiguration( "a", "b" ); 80 } 81 82 public void tearDowm() 83 { 84 m_configuration = null; 85 } 86 87 public void testGetValue() 88 throws Exception 89 { 90 final String orgValue = "Original String"; 91 m_configuration.setValue( orgValue ); 92 assertEquals( orgValue, m_configuration.getValue() ); 93 } 94 95 public void testGetValueAsInteger() 96 throws Exception 97 { 98 final int orgValue = 55; 99 final String strValue = Integer.toHexString( orgValue ); 100 m_configuration.setValue( "0x" + strValue ); 101 assertEquals( orgValue, m_configuration.getValueAsInteger() ); 102 } 103 104 public void testGetValueAsBoolen() 105 throws Exception 106 { 107 final boolean b = true; 108 m_configuration.setValue("TrUe"); 109 assertEquals( b, m_configuration.getValueAsBoolean() ); 110 } 111 112 public void testGetAttribute() 113 throws Exception 114 { 115 final String key = "key"; 116 final String value = "original value"; 117 final String defaultStr = "default"; 118 m_configuration.setAttribute( key, value ); 119 assertEquals( value, m_configuration.getAttribute( key, defaultStr ) ); 120 assertEquals(defaultStr , m_configuration.getAttribute( "newKey", defaultStr ) ); 121 } 122 123 public void testMakeReadOnly() 124 { 125 final String key = "key"; 126 final String value = "original value"; 127 String exception = "exception not thrown"; 128 final String exceptionStr ="Configuration is read only"; 129 m_configuration.makeReadOnly(); 130 131 try 132 { 133 m_configuration.setAttribute( key, value ); 134 } 135 catch( final IllegalStateException ise ) 136 { 137 exception = exceptionStr; 138 } 139 140 assertEquals( exception, exceptionStr ); 141 } 142 143 public void testAddRemoveChild() 144 { 145 final String childName = "child"; 146 final Configuration child = new DefaultConfiguration( childName, "child location" ); 147 148 m_configuration.addChild( child ); 149 assertEquals( child, m_configuration.getChild( childName ) ); 150 151 m_configuration.removeChild( child ); 152 assertEquals( null, m_configuration.getChild( childName, false ) ); 153 } 154 } 155 156 157 158 159 160 | Popular Tags |