View Javadoc
1   package org.apache.maven.model.inheritance;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.io.FileInputStream;
24  import java.io.IOException;
25  import java.io.InputStreamReader;
26  import java.io.Reader;
27  
28  import org.apache.maven.model.Model;
29  import org.apache.maven.model.building.SimpleProblemCollector;
30  import org.apache.maven.model.io.ModelParseException;
31  import org.apache.maven.model.io.ModelReader;
32  import org.apache.maven.model.io.ModelWriter;
33  import org.codehaus.plexus.PlexusTestCase;
34  import org.codehaus.plexus.util.IOUtil;
35  import org.custommonkey.xmlunit.XMLAssert;
36  import org.custommonkey.xmlunit.XMLUnit;
37  
38  /**
39   * @author Hervé Boutemy
40   */
41  public class DefaultInheritanceAssemblerTest
42      extends PlexusTestCase
43  {
44      private ModelReader reader;
45  
46      private ModelWriter writer;
47  
48      private InheritanceAssembler assembler;
49  
50      @Override
51      protected void setUp()
52          throws Exception
53      {
54          super.setUp();
55  
56          reader = lookup( ModelReader.class );
57          writer = lookup( ModelWriter.class );
58          assembler = lookup( InheritanceAssembler.class );
59      }
60  
61      private File getPom( String name )
62      {
63          return getTestFile( "src/test/resources/poms/inheritance/" + name + ".xml" );
64      }
65  
66      private Model getModel( String name )
67          throws ModelParseException, IOException
68      {
69          return reader.read( getPom( name ), null );
70      }
71  
72      public void testPluginConfiguration()
73          throws Exception
74      {
75          Model parent = getModel( "plugin-configuration-parent" );
76  
77          Model child = getModel( "plugin-configuration-child" );
78  
79          SimpleProblemCollector problems = new SimpleProblemCollector();
80  
81          assembler.assembleModelInheritance( child, parent, null, problems );
82  
83          File actual = getTestFile( "target/test-classes/poms/inheritance/plugin-configuration-actual.xml" );
84  
85          writer.write( actual, null, child );
86  
87          // check with getPom( "plugin-configuration-effective" )
88          Reader control = null;
89          Reader test = null;
90          try
91          {
92              File expected = getPom( "plugin-configuration-expected" );
93              control = new InputStreamReader( new FileInputStream( expected ), "UTF-8" );
94  
95              test = new InputStreamReader( new FileInputStream( actual ), "UTF-8" );
96  
97              XMLUnit.setIgnoreComments( true );
98              XMLUnit.setIgnoreWhitespace( true );
99              XMLAssert.assertXMLEqual( control, test );
100         }
101         catch ( IOException ioe )
102         {
103             IOUtil.close( control );
104             IOUtil.close( test );
105         }
106     }
107 
108 }