1 package org.apache.maven.plugins.dependency;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.Artifact;
23 import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
24 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
25 import org.apache.maven.plugin.testing.SilentLog;
26 import org.apache.maven.project.MavenProject;
27
28 import java.io.File;
29 import java.util.Set;
30
31 public class TestCollectMojo
32 extends AbstractDependencyMojoTestCase
33 {
34
35 protected void setUp()
36 throws Exception
37 {
38
39 super.setUp( "markers", false );
40 }
41
42
43
44
45
46
47 public void testCollectTestEnvironment()
48 throws Exception
49 {
50 File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
51 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
52
53 assertNotNull( mojo );
54 assertNotNull( mojo.getProject() );
55 MavenProject project = mojo.getProject();
56
57 mojo.setSilent( true );
58 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
59 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
60 artifacts.addAll( directArtifacts );
61
62 project.setArtifacts( artifacts );
63 project.setDependencyArtifacts( directArtifacts );
64
65 mojo.execute();
66 DependencyStatusSets results = mojo.getResults();
67 assertNotNull( results );
68 assertEquals( artifacts.size(), results.getResolvedDependencies().size() );
69 }
70
71
72
73
74
75
76 public void testCollectTestEnvironment_excludeTransitive()
77 throws Exception
78 {
79 File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
80 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
81
82 assertNotNull( mojo );
83 assertNotNull( mojo.getProject() );
84 MavenProject project = mojo.getProject();
85
86 mojo.setSilent( true );
87 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
88 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
89 artifacts.addAll( directArtifacts );
90
91 project.setArtifacts( artifacts );
92 project.setDependencyArtifacts( directArtifacts );
93
94 setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE );
95
96 mojo.execute();
97 DependencyStatusSets results = mojo.getResults();
98 assertNotNull( results );
99 assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() );
100 }
101
102 public void testSilent()
103 throws Exception
104 {
105 File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
106 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
107 mojo.setSilent( false );
108
109 assertFalse( mojo.getLog() instanceof SilentLog );
110 }
111 }