1   package org.apache.maven.plugin.dependency;
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 java.io.File;
23  import java.util.Set;
24  
25  import org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo;
26  import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
27  import org.apache.maven.plugin.testing.SilentLog;
28  import org.apache.maven.project.MavenProject;
29  
30  public class TestResolveMojo
31      extends AbstractDependencyMojoTestCase
32  {
33  
34      protected void setUp()
35          throws Exception
36      {
37          // required for mojo lookups to work
38          super.setUp( "markers", false );
39      }
40  
41      /**
42       * tests the proper discovery and configuration of the mojo
43       * 
44       * @throws Exception
45       */
46      public void testresolveTestEnvironment()
47          throws Exception
48      {
49          File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" );
50          ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom );
51  
52          assertNotNull( mojo );
53          assertNotNull( mojo.getProject() );
54          MavenProject project = mojo.getProject();
55  
56          mojo.silent = true;
57          Set artifacts = this.stubFactory.getScopedArtifacts();
58          Set directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
59          artifacts.addAll( directArtifacts );
60  
61          project.setArtifacts( artifacts );
62          project.setDependencyArtifacts( directArtifacts );
63  
64          mojo.execute();
65          DependencyStatusSets results = mojo.getResults();
66          assertNotNull( results );
67          assertEquals( artifacts.size(), results.getResolvedDependencies().size() );
68  
69          setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE );
70  
71          mojo.execute();
72          results = mojo.getResults();
73          assertNotNull( results );
74          assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() );
75      }
76  
77      public void testSilent()
78          throws Exception
79      {
80          File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" );
81          ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom );
82          mojo.silent = false;
83  
84          assertFalse( mojo.getLog() instanceof SilentLog );
85      } // TODO: Test skipping artifacts.
86  }