View Javadoc
1   package org.apache.maven.it;
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 org.apache.maven.it.util.ResourceExtractor;
23  
24  import java.io.File;
25  import java.util.List;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-1412">MNG-1412</a>:
29   * it tests that dependencies order in classpath matches <code>pom.xml</code>.
30   *
31   * @author <a href="mailto:hboutemy@apache.org">Hervé Boutemy</a>
32   *
33   */
34  public class MavenITmng1412DependenciesOrderTest
35      extends AbstractMavenIntegrationTestCase
36  {
37  
38      public MavenITmng1412DependenciesOrderTest()
39      {
40          super( "(2.0.8,)" ); // 2.0.9+
41      }
42  
43      public void testitMNG1412()
44          throws Exception
45      {
46          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-1412" );
47  
48          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
49          verifier.setAutoclean( false );
50          verifier.deleteDirectory( "target" );
51          verifier.deleteArtifacts( "org.apache.maven.its.mng1412" );
52          verifier.filterFile( "settings-template.xml", "settings.xml", "UTF-8", verifier.newDefaultFilterProperties() );
53          verifier.addCliOption( "--settings" );
54          verifier.addCliOption( "settings.xml" );
55          verifier.executeGoal( "validate" );
56          verifier.verifyErrorFreeLog();
57          verifier.resetStreams();
58  
59          List<String> compileArtifacts = verifier.loadLines( "target/compile-artifacts.txt", "UTF-8" );
60          assertArtifactOrder( compileArtifacts );
61  
62          List<String> compileClassPath = verifier.loadLines( "target/compile-classpath.txt", "UTF-8" );
63          assertClassPathOrder( compileClassPath.subList( 1, compileClassPath.size() ) );
64  
65          List<String> runtimeArtifacts = verifier.loadLines( "target/runtime-artifacts.txt", "UTF-8" );
66          assertArtifactOrder( runtimeArtifacts );
67  
68          List<String> runtimeClassPath = verifier.loadLines( "target/runtime-classpath.txt", "UTF-8" );
69          assertClassPathOrder( runtimeClassPath.subList( 1, runtimeClassPath.size() ) );
70  
71          List<String> testArtifacts = verifier.loadLines( "target/test-artifacts.txt", "UTF-8" );
72          assertArtifactOrder( testArtifacts );
73  
74          List<String> testClassPath = verifier.loadLines( "target/test-classpath.txt", "UTF-8" );
75          assertClassPathOrder( testClassPath.subList( 2, testClassPath.size() ) );
76      }
77  
78      private void assertArtifactOrder( List<String> artifacts )
79      {
80          assertEquals( 4, artifacts.size() );
81          assertEquals( "org.apache.maven.its.mng1412:a:jar:0.1", artifacts.get( 0 ) );
82          assertEquals( "org.apache.maven.its.mng1412:c:jar:0.1", artifacts.get( 1 ) );
83          assertEquals( "org.apache.maven.its.mng1412:b:jar:0.1", artifacts.get( 2 ) );
84          assertEquals( "org.apache.maven.its.mng1412:d:jar:0.1", artifacts.get( 3 ) );
85      }
86  
87      private void assertClassPathOrder( List<String> classpath )
88      {
89          assertEquals( 4, classpath.size() );
90          assertEquals( "a-0.1.jar", classpath.get( 0 ) );
91          assertEquals( "c-0.1.jar", classpath.get( 1 ) );
92          assertEquals( "b-0.1.jar", classpath.get( 2 ) );
93          assertEquals( "d-0.1.jar", classpath.get( 3 ) );
94      }
95  
96  }