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.Collection;
26  
27  /**
28   * This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-2921">MNG-2921</a>. It naturally includes the
29   * test for the related issue <a href="https://issues.apache.org/jira/browse/MNG-2877">MNG-2877</a> whose original test was
30   * too weak to prevent this issue.
31   *
32   * @author Benjamin Bentmann
33   *
34   */
35  public class MavenITmng2921ActiveAttachedArtifactsTest
36      extends AbstractMavenIntegrationTestCase
37  {
38  
39      public MavenITmng2921ActiveAttachedArtifactsTest()
40      {
41          super( "(2.0.6,)" );
42      }
43  
44      /**
45       * Verify that attached project artifacts can be resolved from the reactor as active project artifacts for
46       * consumption on other module's class paths. Note the subtle difference of this test compared to the closely
47       * related issue MNG-2871: This test is about *attached* artifacts, i.e. dependencies that have already been
48       * packaged. MNG-2871 on the other hand is about dependencies that haven't been packaged yet but merely exist
49       * as loose class files in a module's output directory. In other words, this test is concerned with the situation
50       * during the lifecycle phase "package" while MNG-2871 is concerned with earlier phases like "test".
51       *
52       * @throws Exception in case of failure
53       */
54      public void testitMNG2921()
55          throws Exception
56      {
57          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-2921" );
58          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
59          verifier.setAutoclean( false );
60          verifier.deleteDirectory( "consumer/target" );
61          verifier.executeGoal( "validate" );
62          verifier.verifyErrorFreeLog();
63          verifier.resetStreams();
64  
65          Collection<String> compileArtifacts = verifier.loadLines( "consumer/target/compile.txt", "UTF-8" );
66          assertTrue( compileArtifacts.toString(),
67              compileArtifacts.contains( "org.apache.maven.its.mng2921:ejbs:ejb-client:client:1.0-SNAPSHOT" ) );
68          assertTrue( compileArtifacts.toString(),
69              compileArtifacts.contains( "org.apache.maven.its.mng2921:producer:ejb-client:client:1.0-SNAPSHOT" ) );
70          assertFalse( compileArtifacts.toString(),
71              compileArtifacts.contains( "org.apache.maven.its.mng2921:tests:test-jar:tests:1.0-SNAPSHOT" ) );
72          assertFalse( compileArtifacts.toString(),
73              compileArtifacts.contains( "org.apache.maven.its.mng2921:producer:test-jar:tests:1.0-SNAPSHOT" ) );
74  
75          Collection<String> testArtifacts = verifier.loadLines( "consumer/target/test.txt", "UTF-8" );
76          assertTrue( testArtifacts.toString(),
77              testArtifacts.contains( "org.apache.maven.its.mng2921:ejbs:ejb-client:client:1.0-SNAPSHOT" ) );
78          assertTrue( testArtifacts.toString(),
79              testArtifacts.contains( "org.apache.maven.its.mng2921:producer:ejb-client:client:1.0-SNAPSHOT" ) );
80          assertTrue( testArtifacts.toString(),
81              testArtifacts.contains( "org.apache.maven.its.mng2921:tests:test-jar:tests:1.0-SNAPSHOT" ) );
82          assertTrue( testArtifacts.toString(),
83              testArtifacts.contains( "org.apache.maven.its.mng2921:producer:test-jar:tests:1.0-SNAPSHOT" ) );
84  
85          Collection<String> testClassPath = verifier.loadLines( "consumer/target/test-classpath.txt", "UTF-8" );
86          assertTrue( testClassPath.toString(), testClassPath.contains( "ejbs/attached.jar" ) );
87          assertTrue( testClassPath.toString(), testClassPath.contains( "tests/attached.jar" ) );
88          assertTrue( testClassPath.toString(), testClassPath.contains( "producer/client.jar" ) );
89          assertTrue( testClassPath.toString(), testClassPath.contains( "producer/tests.jar" ) );
90      }
91  
92  }