KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > loom > components > configuration > merger > ConfigurationMergerTestCase


1 /* ====================================================================
2  * Loom Software License, version 1.1
3  *
4  * Copyright (c) 2003, Loom Group. All rights reserved.
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * 3. Neither the name of the Loom Group nor the name "Loom" nor
18  * the names of its contributors may be used to endorse or promote
19  * products derived from this software without specific prior
20  * written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * ====================================================================
36  *
37  * Loom includes code from the Apache Software Foundation
38  *
39  * ====================================================================
40  * The Apache Software License, Version 1.1
41  *
42  * Copyright (c) 1997-2003 The Apache Software Foundation. All rights
43  * reserved.
44  *
45  * Redistribution and use in source and binary forms, with or without
46  * modification, are permitted provided that the following conditions
47  * are met:
48  *
49  * 1. Redistributions of source code must retain the above copyright
50  * notice, this list of conditions and the following disclaimer.
51  *
52  * 2. Redistributions in binary form must reproduce the above copyright
53  * notice, this list of conditions and the following disclaimer in
54  * the documentation and/or other materials provided with the
55  * distribution.
56  *
57  * 3. The end-user documentation included with the redistribution,
58  * if any, must include the following acknowledgment:
59  * "This product includes software developed by the
60  * Apache Software Foundation (http://www.apache.org/)."
61  * Alternately, this acknowledgment may appear in the software
62  * itself, if and wherever such third-party acknowledgments
63  * normally appear.
64  *
65  * 4. The names "Jakarta", "Avalon", and "Apache Software Foundation"
66  * must not be used to endorse or promote products derived from this
67  * software without prior written permission. For written
68  * permission, please contact apache@apache.org.
69  *
70  * 5. Products derived from this software may not be called "Apache",
71  * nor may "Apache" appear in their name, without prior written
72  * permission of the Apache Software Foundation.
73  *
74  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
75  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
76  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
77  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
78  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
79  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
80  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
81  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
82  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
83  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
84  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
85  * SUCH DAMAGE.
86  */

87 package org.codehaus.loom.components.configuration.merger;
88
89 import junit.framework.TestCase;
90 import org.codehaus.dna.impl.ConfigurationUtil;
91 import org.codehaus.dna.impl.DefaultConfiguration;
92 import org.codehaus.loom.components.configuration.merger.ConfigurationMerger;
93 import org.codehaus.loom.components.configuration.merger.ConfigurationSplitter;
94
95 /**
96  * @author Peter Royal
97  */

98 public class ConfigurationMergerTestCase
99     extends TestCase
100 {
101     public void testAttributeOnlyMerge()
102         throws Exception JavaDoc
103     {
104         final DefaultConfiguration result = new DefaultConfiguration( "a", "",
105                                                                       "" );
106         result.setAttribute( "a", "1" );
107
108         final DefaultConfiguration base = new DefaultConfiguration( "a", "",
109                                                                     "" );
110         base.setAttribute( "a", "2" );
111
112         final DefaultConfiguration layer =
113             new DefaultConfiguration( "a", "", "" );
114         layer.setAttribute( "a", "1" );
115
116         assertTrue(
117             ConfigurationUtil.equals( result,
118                                       ConfigurationMerger.merge( layer, base ) ) );
119         assertTrue( ConfigurationUtil.equals( layer,
120                                               ConfigurationSplitter.split(
121                                                   result,
122                                                   base ) ) );
123     }
124
125     public void testAddChild()
126         throws Exception JavaDoc
127     {
128         final DefaultConfiguration result =
129             new DefaultConfiguration( "a", "", "" );
130         result.addChild( new DefaultConfiguration( "kid1", "", "" ) );
131         result.addChild( new DefaultConfiguration( "kid2", "", "" ) );
132
133         final DefaultConfiguration base =
134             new DefaultConfiguration( "a", "", "" );
135         base.addChild( new DefaultConfiguration( "kid1", "", "" ) );
136
137         final DefaultConfiguration layer = new DefaultConfiguration( "a", "",
138                                                                      "" );
139         layer.addChild( new DefaultConfiguration( "kid2", "", "" ) );
140         assertTrue(
141             ConfigurationUtil.equals( result,
142                                       ConfigurationMerger.merge( layer, base ) ) );
143         assertTrue( ConfigurationUtil.equals( layer,
144                                               ConfigurationSplitter.split(
145                                                   result,
146                                                   base ) ) );
147     }
148
149     public void testOverrideChild()
150         throws Exception JavaDoc
151     {
152         final DefaultConfiguration result = new DefaultConfiguration( "a", "",
153                                                                       "" );
154         final DefaultConfiguration rkid1 = new DefaultConfiguration( "kid1",
155                                                                      "",
156                                                                      "" );
157         rkid1.setAttribute( "test", "1" );
158         result.addChild( rkid1 );
159
160         final DefaultConfiguration base = new DefaultConfiguration( "a", "",
161                                                                     "" );
162         final DefaultConfiguration bkid1 = new DefaultConfiguration( "kid1",
163                                                                      "",
164                                                                      "" );
165         bkid1.setAttribute( "test", "0" );
166         base.addChild( bkid1 );
167
168         final DefaultConfiguration layer = new DefaultConfiguration( "a", "",
169                                                                      "" );
170         final DefaultConfiguration lkid1 = new DefaultConfiguration( "kid1",
171                                                                      "",
172                                                                      "" );
173         lkid1.setAttribute( "test", "1" );
174         layer.addChild( lkid1 );
175
176         assertTrue( !ConfigurationUtil.equals( result,
177                                                ConfigurationMerger.merge(
178                                                    layer,
179                                                    base ) ) );
180
181         lkid1.setAttribute( "excalibur-configuration:merge", "true" );
182
183         assertTrue(
184             ConfigurationUtil.equals( result,
185                                       ConfigurationMerger.merge( layer, base ) ) );
186         assertTrue( ConfigurationUtil.equals( layer,
187                                               ConfigurationSplitter.split(
188                                                   result,
189                                                   base ) ) );
190     }
191 }
192
Popular Tags