KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > excalibur > configuration > test > ConfigurationUtilTestCase


1 /*
2
3  ============================================================================
4                    The Apache Software License, Version 1.1
5  ============================================================================
6
7  Copyright (C) 1999-2003 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.excalibur.configuration.test;
52
53 import junit.framework.TestCase;
54
55 import org.apache.avalon.framework.configuration.DefaultConfiguration;
56 import org.apache.excalibur.configuration.ConfigurationUtil;
57
58 /**
59  * Test the ConfigurationUtil class
60  *
61  * @author <a HREF="mailto:proyal@apache.org">Peter Royal</a>
62  */

63 public final class ConfigurationUtilTestCase extends TestCase
64 {
65     private DefaultConfiguration m_configuration;
66
67     public ConfigurationUtilTestCase()
68     {
69         this( "ConfigurationUtil Test Case" );
70     }
71
72     public ConfigurationUtilTestCase( 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     /** this method is gone? public void testBranch()
88         throws Exception
89     {
90         m_configuration.setAttribute( "test", "test" );
91         m_configuration.setValue( "test" );
92         m_configuration.addChild( new DefaultConfiguration( "test", "test" ) );
93
94         final Configuration c =
95                 ConfigurationUtil.branch( m_configuration, "branched" );
96
97         assertEquals( "branched", c.getName() );
98         assertEquals( "test", c.getAttribute( "test" ) );
99         assertEquals( "test", c.getValue() );
100         assertTrue( c.getChild( "test", false ) != null );
101     }*/

102
103     public void testIdentityEquals()
104     {
105         assertTrue( ConfigurationUtil.equals( m_configuration, m_configuration ) );
106     }
107
108     public void testAttributeEquals()
109     {
110         DefaultConfiguration c1 = new DefaultConfiguration("a", "here");
111         DefaultConfiguration c2 = new DefaultConfiguration("a", "there");
112
113         c1.setAttribute("test", "test");
114         c2.setAttribute("test", "test");
115
116         assertTrue( ConfigurationUtil.equals( c1, c2 ) );
117     }
118
119     public void testValueEquals()
120     {
121         DefaultConfiguration c1 = new DefaultConfiguration("a", "here");
122         DefaultConfiguration c2 = new DefaultConfiguration("a", "there");
123
124         c1.setValue("test");
125         c2.setValue("test");
126
127         assertTrue( ConfigurationUtil.equals( c1, c2 ) );
128     }
129
130     public void testChildrenEquals()
131     {
132         DefaultConfiguration c1 = new DefaultConfiguration("a", "here");
133         DefaultConfiguration k1 = new DefaultConfiguration("b", "wow");
134         DefaultConfiguration c2 = new DefaultConfiguration("a", "there");
135         DefaultConfiguration k2 = new DefaultConfiguration("c", "wow");
136         DefaultConfiguration k3 = new DefaultConfiguration("c", "wow");
137
138         k3.setValue( "bigger stronger faster" );
139
140         k1.setAttribute("test", "test");
141         k2.setAttribute("test", "test");
142
143         c1.addChild( k1 );
144         c2.addChild( k2 );
145
146         assertTrue( !ConfigurationUtil.equals( c1, c2 ) );
147
148         c1.addChild( k2 );
149         c2.addChild( k1 );
150
151         assertTrue( ConfigurationUtil.equals( c1, c2 ) );
152
153         c1.addChild( k2 );
154         c1.addChild( k1 );
155         c2.addChild( k1 );
156         c2.addChild( k2 );
157         c1.addChild( k3 );
158         c2.addChild( k3 );
159
160         assertTrue( ConfigurationUtil.equals( c1, c2 ) );
161     }
162 }
163
164
165
166
167
168
Popular Tags