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