KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > framework > configuration > test > DefaultConfigurationTestCase


1 /*
2
3  ============================================================================
4                    The Apache Software License, Version 1.1
5  ============================================================================
6  
7  Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
8  
9  Redistribution and use in source and binary forms, with or without modifica-
10  tion, are permitted provided that the following conditions are met:
11  
12  1. Redistributions of source code must retain the above copyright notice,
13     this list of conditions and the following disclaimer.
14  
15  2. Redistributions in binary form must reproduce the above copyright notice,
16     this list of conditions and the following disclaimer in the documentation
17     and/or other materials provided with the distribution.
18  
19  3. The end-user documentation included with the redistribution, if any, must
20     include the following acknowledgment: "This product includes software
21     developed by the Apache Software Foundation (http://www.apache.org/)."
22     Alternately, this acknowledgment may appear in the software itself, if
23     and wherever such third-party acknowledgments normally appear.
24  
25  4. The names "Jakarta", "Apache Avalon", "Avalon Excalibur", "Avalon
26     Framework" and "Apache Software Foundation" must not be used to endorse
27     or promote products derived from this software without prior written
28     permission. For written permission, please contact apache@apache.org.
29  
30  5. Products derived from this software may not be called "Apache", nor may
31     "Apache" appear in their name, without prior written permission of the
32     Apache Software Foundation.
33  
34  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  
45  This software consists of voluntary contributions made by many individuals
46  on behalf of the Apache Software Foundation and was originally created by
47  Stefano Mazzocchi <stefano@apache.org>. For more information on the Apache
48  Software Foundation, please see <http://www.apache.org/>.
49  
50 */

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 /**
59  * Test the basic public methods of DefaultConfiguration.
60  *
61  * @author <a HREF="mailto:rantene@hotmail.com">Ran Tene</a>
62  */

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 JavaDoc 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 JavaDoc
89     {
90         final String JavaDoc orgValue = "Original String";
91         m_configuration.setValue( orgValue );
92         assertEquals( orgValue, m_configuration.getValue() );
93     }
94
95     public void testGetValueAsInteger()
96         throws Exception JavaDoc
97     {
98         final int orgValue = 55;
99         final String JavaDoc 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 JavaDoc
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 JavaDoc
114     {
115         final String JavaDoc key = "key";
116         final String JavaDoc value = "original value";
117         final String JavaDoc 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 JavaDoc key = "key";
126         final String JavaDoc value = "original value";
127         String JavaDoc exception = "exception not thrown";
128         final String JavaDoc exceptionStr ="Configuration is read only";
129         m_configuration.makeReadOnly();
130
131         try
132         {
133             m_configuration.setAttribute( key, value );
134         }
135         catch( final IllegalStateException JavaDoc ise )
136         {
137             exception = exceptionStr;
138         }
139
140         assertEquals( exception, exceptionStr );
141     }
142
143     public void testAddRemoveChild()
144     {
145         final String JavaDoc 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