1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.apache.maven.lifecycle.internal;
16
17 import org.apache.maven.execution.MavenSession;
18 import org.apache.maven.execution.ProjectDependencyGraph;
19 import org.apache.maven.lifecycle.LifecycleNotFoundException;
20 import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
21 import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
22 import org.apache.maven.plugin.InvalidPluginDescriptorException;
23 import org.apache.maven.plugin.MojoNotFoundException;
24 import org.apache.maven.plugin.PluginDescriptorParsingException;
25 import org.apache.maven.plugin.PluginNotFoundException;
26 import org.apache.maven.plugin.PluginResolutionException;
27 import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
28 import org.apache.maven.plugin.version.PluginVersionResolutionException;
29 import org.apache.maven.project.MavenProject;
30
31 import java.util.List;
32
33 import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*;
34
35
36
37
38 public class ConcurrencyDependencyGraphTest
39 extends junit.framework.TestCase
40 {
41 public void testConcurrencyGraphPrimaryVersion()
42 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
43 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
44 LifecyclePhaseNotFoundException, LifecycleNotFoundException
45 {
46 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
47 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
48
49 ConcurrencyDependencyGraph graph =
50 new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
51
52 final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds();
53 assertEquals( 1, projectBuilds.size() );
54 assertEquals( A, projectBuilds.get( 0 ) );
55
56 final List<MavenProject> subsequent = graph.markAsFinished( A );
57 assertEquals( 2, subsequent.size() );
58 assertEquals( ProjectDependencyGraphStub.B, subsequent.get( 0 ) );
59 assertEquals( C, subsequent.get( 1 ) );
60
61 final List<MavenProject> bDescendants = graph.markAsFinished( B );
62 assertEquals( 1, bDescendants.size() );
63 assertEquals( Y, bDescendants.get( 0 ) );
64
65 final List<MavenProject> cDescendants = graph.markAsFinished( C );
66 assertEquals( 2, cDescendants.size() );
67 assertEquals( X, cDescendants.get( 0 ) );
68 assertEquals( Z, cDescendants.get( 1 ) );
69 }
70
71 public void testConcurrencyGraphDifferentCompletionOrder()
72 throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
73 NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
74 LifecyclePhaseNotFoundException, LifecycleNotFoundException
75 {
76 ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
77 final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
78 ConcurrencyDependencyGraph graph =
79 new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
80
81 graph.markAsFinished( A );
82 final List<MavenProject> cDescendants = graph.markAsFinished( C );
83 assertEquals( 1, cDescendants.size() );
84 assertEquals( Z, cDescendants.get( 0 ) );
85
86 final List<MavenProject> bDescendants = graph.markAsFinished( B );
87 assertEquals( 2, bDescendants.size() );
88 assertEquals( X, bDescendants.get( 0 ) );
89 assertEquals( Y, bDescendants.get( 1 ) );
90 }
91
92 }