View Javadoc
1   package org.codehaus.plexus.util.xml;
2   
3   /*
4    * Copyright The Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.io.StringReader;
20  
21  import junit.framework.TestCase;
22  
23  public class Xpp3DomUtilsTest
24      extends TestCase
25  {
26  
27      public void testCombineId()
28          throws Exception
29      {
30          String lhs = "<props>" + "<property combine.id='LHS-ONLY'><name>LHS-ONLY</name><value>LHS</value></property>"
31              + "<property combine.id='TOOVERWRITE'><name>TOOVERWRITE</name><value>LHS</value></property>" + "</props>";
32  
33          String rhs = "<props>" + "<property combine.id='RHS-ONLY'><name>RHS-ONLY</name><value>RHS</value></property>"
34              + "<property combine.id='TOOVERWRITE'><name>TOOVERWRITE</name><value>RHS</value></property>" + "</props>";
35  
36          Xpp3Dom leftDom = Xpp3DomBuilder.build( new StringReader( lhs ) );
37          Xpp3Dom rightDom = Xpp3DomBuilder.build( new StringReader( rhs ) );
38  
39          Xpp3Dom mergeResult = Xpp3DomUtils.mergeXpp3Dom( leftDom, rightDom, true );
40          assertEquals( 3, mergeResult.getChildren( "property" ).length );
41  
42          assertEquals( "LHS-ONLY", mergeResult.getChildren( "property" )[0].getChild( "name" ).getValue() );
43          assertEquals( "LHS", mergeResult.getChildren( "property" )[0].getChild( "value" ).getValue() );
44          assertEquals( "TOOVERWRITE", mergeResult.getChildren( "property" )[1].getChild( "name" ).getValue() );
45          assertEquals( "LHS", mergeResult.getChildren( "property" )[1].getChild( "value" ).getValue() );
46          assertEquals( "RHS-ONLY", mergeResult.getChildren( "property" )[2].getChild( "name" ).getValue() );
47          assertEquals( "RHS", mergeResult.getChildren( "property" )[2].getChild( "value" ).getValue() );
48      }
49  }