001    package org.apache.maven.lifecycle.internal;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
005     * agreements. See the NOTICE file distributed with this work for additional information regarding
006     * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance with the License. You may obtain a
008     * copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software distributed under the License
013     * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
014     * or implied. See the License for the specific language governing permissions and limitations under
015     * the License.
016     */
017    
018    import org.apache.maven.execution.MavenSession;
019    import org.apache.maven.execution.ProjectDependencyGraph;
020    import org.apache.maven.lifecycle.LifecycleNotFoundException;
021    import org.apache.maven.lifecycle.LifecyclePhaseNotFoundException;
022    import org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub;
023    import org.apache.maven.plugin.InvalidPluginDescriptorException;
024    import org.apache.maven.plugin.MojoNotFoundException;
025    import org.apache.maven.plugin.PluginDescriptorParsingException;
026    import org.apache.maven.plugin.PluginNotFoundException;
027    import org.apache.maven.plugin.PluginResolutionException;
028    import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
029    import org.apache.maven.plugin.version.PluginVersionResolutionException;
030    import org.apache.maven.project.MavenProject;
031    
032    import java.util.List;
033    
034    import static org.apache.maven.lifecycle.internal.stub.ProjectDependencyGraphStub.*;
035    
036    /**
037     * @author Kristian Rosenvold
038     */
039    public class ConcurrencyDependencyGraphTest
040        extends junit.framework.TestCase
041    {
042        public void testConcurrencyGraphPrimaryVersion()
043            throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
044            NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
045            LifecyclePhaseNotFoundException, LifecycleNotFoundException
046        {
047            ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
048            final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
049    
050            ConcurrencyDependencyGraph graph =
051                new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
052    
053            final List<MavenProject> projectBuilds = graph.getRootSchedulableBuilds();
054            assertEquals( 1, projectBuilds.size() );
055            assertEquals( A, projectBuilds.get( 0 ) );
056    
057            final List<MavenProject> subsequent = graph.markAsFinished( A );
058            assertEquals( 2, subsequent.size() );
059            assertEquals( ProjectDependencyGraphStub.B, subsequent.get( 0 ) );
060            assertEquals( C, subsequent.get( 1 ) );
061    
062            final List<MavenProject> bDescendants = graph.markAsFinished( B );
063            assertEquals( 1, bDescendants.size() );
064            assertEquals( Y, bDescendants.get( 0 ) );
065    
066            final List<MavenProject> cDescendants = graph.markAsFinished( C );
067            assertEquals( 2, cDescendants.size() );
068            assertEquals( X, cDescendants.get( 0 ) );
069            assertEquals( Z, cDescendants.get( 1 ) );
070        }
071    
072        public void testConcurrencyGraphDifferentCompletionOrder()
073            throws InvalidPluginDescriptorException, PluginVersionResolutionException, PluginDescriptorParsingException,
074            NoPluginFoundForPrefixException, MojoNotFoundException, PluginNotFoundException, PluginResolutionException,
075            LifecyclePhaseNotFoundException, LifecycleNotFoundException
076        {
077            ProjectDependencyGraph dependencyGraph = new ProjectDependencyGraphStub();
078            final MavenSession session = ProjectDependencyGraphStub.getMavenSession();
079            ConcurrencyDependencyGraph graph =
080                new ConcurrencyDependencyGraph( getProjectBuildList( session ), dependencyGraph );
081    
082            graph.markAsFinished( A );
083            final List<MavenProject> cDescendants = graph.markAsFinished( C );
084            assertEquals( 1, cDescendants.size() );
085            assertEquals( Z, cDescendants.get( 0 ) );
086    
087            final List<MavenProject> bDescendants = graph.markAsFinished( B );
088            assertEquals( 2, bDescendants.size() );
089            assertEquals( X, bDescendants.get( 0 ) );
090            assertEquals( Y, bDescendants.get( 1 ) );
091        }
092    
093    }