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