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.*;
26  
27  /**
28   * Test case for <a href="https://issues.apache.org/jira/browse/MNG-6173">MNG-6173</a>.
29   */
30  public class MavenITmng6173GetProjectsAndDependencyGraphTest
31          extends AbstractMavenIntegrationTestCase
32  {
33  
34      public MavenITmng6173GetProjectsAndDependencyGraphTest()
35      {
36          super( "[3.0-alpha-3,)" );
37      }
38  
39      /**
40       * Verifies that {@code MavenSession#getProjects()} returns the projects being built and that
41       * {@code MavenSession#getDependencyGraph()} returns the dependency graph.
42       *
43       * @throws Exception in case of failure
44       */
45      public void testitShouldReturnProjectsAndProjectDependencyGraph()
46              throws Exception
47      {
48  
49          File testDir = ResourceExtractor.simpleExtractResources( getClass(),
50                  "/mng-6173-get-projects-and-dependency-graph" );
51  
52          Verifier verifier = newVerifier( testDir.getAbsolutePath() );
53          verifier.setAutoclean( false );
54          verifier.deleteDirectory( "target" );
55          verifier.deleteDirectory( "module-1/target" );
56          verifier.deleteDirectory( "module-2/target" );
57          verifier.addCliOption( "-pl" );
58          verifier.addCliOption( "module-1" );
59          verifier.executeGoal( "validate" );
60          verifier.verifyErrorFreeLog();
61          verifier.resetStreams();
62  
63          Properties properties = verifier.loadProperties( "module-1/target/session.properties" );
64          assertEquals( "1", properties.getProperty( "session.projects.size" ) );
65          assertEquals( "module-1", properties.getProperty( "session.projects.0.artifactId" ) );
66          assertEquals( "1", properties.getProperty("session.projectDependencyGraph.sortedProjects.size" ) );
67          assertEquals( "module-1", properties.getProperty(
68                  "session.projectDependencyGraph.sortedProjects.0.artifactId" ) );
69      }
70  
71  }