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.resolvers;
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.AbstractDependencyMojoTestCase;
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 TestResolveMojo extends AbstractDependencyMojoTestCase {
33
34 protected void setUp() throws Exception {
35
36 super.setUp("markers", false);
37
38 MavenProject project = new DependencyProjectStub();
39 getContainer().addComponent(project, MavenProject.class.getName());
40
41 MavenSession session = newMavenSession(project);
42 getContainer().addComponent(session, MavenSession.class.getName());
43 }
44
45
46
47
48
49
50 public void testresolveTestEnvironment() throws Exception {
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() throws Exception {
80 File testPom = new File(getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml");
81 ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo("resolve", testPom);
82 mojo.setSilent(false);
83
84 assertFalse(mojo.getLog() instanceof SilentLog);
85 }
86 }