1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency;
20
21 import java.io.File;
22 import java.util.Set;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.execution.MavenSession;
26 import org.apache.maven.plugin.testing.SilentLog;
27 import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
28 import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
29 import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
30 import org.apache.maven.project.MavenProject;
31
32 public class TestCollectMojo extends AbstractDependencyMojoTestCase {
33
34 protected void setUp() throws Exception {
35
36 super.setUp("markers", false);
37 MavenProject project = new DependencyProjectStub();
38 getContainer().addComponent(project, MavenProject.class.getName());
39
40 MavenSession session = newMavenSession(project);
41 getContainer().addComponent(session, MavenSession.class.getName());
42 }
43
44
45
46
47
48
49 public void testCollectTestEnvironment() throws Exception {
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() throws Exception {
77 File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
78 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
79
80 assertNotNull(mojo);
81 assertNotNull(mojo.getProject());
82 MavenProject project = mojo.getProject();
83
84 mojo.setSilent(true);
85 Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
86 Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
87 artifacts.addAll(directArtifacts);
88
89 project.setArtifacts(artifacts);
90 project.setDependencyArtifacts(directArtifacts);
91
92 setVariableValueToObject(mojo, "excludeTransitive", Boolean.TRUE);
93
94 mojo.execute();
95 DependencyStatusSets results = mojo.getResults();
96 assertNotNull(results);
97 assertEquals(directArtifacts.size(), results.getResolvedDependencies().size());
98 }
99
100 public void testSilent() throws Exception {
101 File testPom = new File(getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml");
102 CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo("collect", testPom);
103 mojo.setSilent(false);
104
105 assertFalse(mojo.getLog() instanceof SilentLog);
106 }
107 }