001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
003 * agreements. See the NOTICE file distributed with this work for additional information regarding
004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
005 * "License"); you may not use this file except in compliance with the License. You may obtain a
006 * copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software distributed under the License
011 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
012 * or implied. See the License for the specific language governing permissions and limitations under
013 * the License.
014 */
015
016package org.apache.maven.lifecycle;
017
018import junit.framework.TestCase;
019import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
020import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
021import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
022import org.apache.maven.model.Plugin;
023
024import java.util.Iterator;
025import java.util.List;
026import java.util.Set;
027
028/**
029 * @author Kristian Rosenvold
030 */
031public class MavenExecutionPlanTest
032    extends TestCase
033{
034    public void testFindFirstWithMatchingSchedule()
035        throws Exception
036    {
037        final List<Scheduling> cycles = DefaultLifecyclesStub.getSchedulingList();
038        final Schedule schedule = cycles.get( 0 ).getSchedules().get( 0 );
039        assertNotNull( schedule );
040
041    }
042
043    public void testForceAllComplete()
044        throws Exception
045    {
046        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
047        plan.forceAllComplete();
048        final Iterator<ExecutionPlanItem> planItemIterator = plan.iterator();
049        assertTrue( planItemIterator.next().isDone() );
050        assertTrue( planItemIterator.next().isDone() );
051    }
052
053    public void testFindLastInPhase()
054        throws Exception
055    {
056        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
057
058        ExecutionPlanItem expected = plan.findLastInPhase( "package" );
059        ExecutionPlanItem beerPhase = plan.findLastInPhase( "BEER" );  // Beer comes straight after package in stub
060        assertEquals( expected, beerPhase );
061        assertNotNull( expected );
062    }
063
064    public void testThreadSafeMojos()
065        throws Exception
066    {
067        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
068        final Set<Plugin> unSafePlugins = plan.getNonThreadSafePlugins();
069        // There is only a single threadsafe plugin here...
070        assertEquals( plan.size() - 1, unSafePlugins.size() );
071
072    }
073
074
075    public void testFindLastWhenFirst()
076        throws Exception
077    {
078        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
079
080        ExecutionPlanItem beerPhase = plan.findLastInPhase(
081            LifecycleExecutionPlanCalculatorStub.VALIDATE.getPhase() );  // Beer comes straight after package in stub
082        assertNull( beerPhase );
083    }
084
085    public void testFindLastInPhaseMisc()
086        throws Exception
087    {
088        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
089
090        assertNull( plan.findLastInPhase( "pacXkage" ) );
091        // Beer comes straight after package in stub, much like real life.
092        assertNotNull( plan.findLastInPhase( LifecycleExecutionPlanCalculatorStub.INITIALIZE.getPhase() ) );
093    }
094}