001 package org.apache.maven.model.inheritance;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.io.File;
023 import java.io.FileInputStream;
024 import java.io.IOException;
025 import java.io.InputStreamReader;
026 import java.io.Reader;
027
028 import org.apache.maven.model.Model;
029 import org.apache.maven.model.building.SimpleProblemCollector;
030 import org.apache.maven.model.io.ModelParseException;
031 import org.apache.maven.model.io.ModelReader;
032 import org.apache.maven.model.io.ModelWriter;
033 import org.codehaus.plexus.PlexusTestCase;
034 import org.codehaus.plexus.util.IOUtil;
035 import org.custommonkey.xmlunit.XMLAssert;
036 import org.custommonkey.xmlunit.XMLUnit;
037
038 /**
039 * @author Hervé Boutemy
040 */
041 public class DefaultInheritanceAssemblerTest
042 extends PlexusTestCase
043 {
044 private ModelReader reader;
045
046 private ModelWriter writer;
047
048 private InheritanceAssembler assembler;
049
050 @Override
051 protected void setUp()
052 throws Exception
053 {
054 super.setUp();
055
056 reader = lookup( ModelReader.class );
057 writer = lookup( ModelWriter.class );
058 assembler = lookup( InheritanceAssembler.class );
059 }
060
061 private File getPom( String name )
062 {
063 return getTestFile( "src/test/resources/poms/inheritance/" + name + ".xml" );
064 }
065
066 private Model getModel( String name )
067 throws ModelParseException, IOException
068 {
069 return reader.read( getPom( name ), null );
070 }
071
072 public void testPluginConfiguration()
073 throws Exception
074 {
075 Model parent = getModel( "plugin-configuration-parent" );
076
077 Model child = getModel( "plugin-configuration-child" );
078
079 SimpleProblemCollector problems = new SimpleProblemCollector();
080
081 assembler.assembleModelInheritance( child, parent, null, problems );
082
083 File actual = getTestFile( "target/test-classes/poms/inheritance/plugin-configuration-actual.xml" );
084
085 writer.write( actual, null, child );
086
087 // check with getPom( "plugin-configuration-effective" )
088 Reader control = null;
089 Reader test = null;
090 try
091 {
092 File expected = getPom( "plugin-configuration-expected" );
093 control = new InputStreamReader( new FileInputStream( expected ), "UTF-8" );
094
095 test = new InputStreamReader( new FileInputStream( actual ), "UTF-8" );
096
097 XMLUnit.setIgnoreComments( true );
098 XMLUnit.setIgnoreWhitespace( true );
099 XMLAssert.assertXMLEqual( control, test );
100 }
101 catch ( IOException ioe )
102 {
103 IOUtil.close( control );
104 IOUtil.close( test );
105 }
106 }
107
108 }