View Javadoc
1   package org.apache.maven.plugins.shade.resource;
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 junit.framework.TestCase;
23  
24  import org.apache.maven.plugins.shade.relocation.Relocator;
25  import org.codehaus.plexus.util.IOUtil;
26  import org.custommonkey.xmlunit.Diff;
27  import org.custommonkey.xmlunit.XMLAssert;
28  import org.custommonkey.xmlunit.XMLUnit;
29  
30  import java.io.InputStream;
31  import java.util.Collections;
32  
33  /**
34   * Test for {@link ComponentsXmlResourceTransformer}.
35   *
36   * @author Brett Porter
37   *
38   */
39  public class ComponentsXmlResourceTransformerTest
40      extends TestCase
41  {
42      private ComponentsXmlResourceTransformer transformer;
43  
44      public void setUp()
45      {
46          this.transformer = new ComponentsXmlResourceTransformer();
47      }
48  
49      public void testConfigurationMerging()
50          throws Exception
51      {
52  
53          XMLUnit.setNormalizeWhitespace( true );
54  
55          InputStream resourceAsStream = getClass().getResourceAsStream( "/components-1.xml" );
56          transformer.processResource( "components-1.xml", resourceAsStream,
57                                       Collections.<Relocator> emptyList() );
58          resourceAsStream.close();
59          InputStream resourceAsStream1 = getClass().getResourceAsStream( "/components-2.xml" );
60          transformer.processResource( "components-1.xml", resourceAsStream1,
61                                       Collections.<Relocator> emptyList() );
62          resourceAsStream1.close();
63          final InputStream resourceAsStream2 = getClass().getResourceAsStream( "/components-expected.xml" );
64          Diff diff = XMLUnit.compareXML(
65              IOUtil.toString( resourceAsStream2, "UTF-8" ),
66              IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ) );
67          //assertEquals( IOUtil.toString( getClass().getResourceAsStream( "/components-expected.xml" ), "UTF-8" ),
68          //              IOUtil.toString( transformer.getTransformedResource(), "UTF-8" ).replaceAll("\r\n", "\n") );
69          resourceAsStream2.close();
70          XMLAssert.assertXMLIdentical( diff, true );
71      }
72  }