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;
019
020import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
021import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
022import org.apache.maven.model.Plugin;
023
024import java.util.Set;
025
026/**
027 * @author Kristian Rosenvold
028 */
029public class MavenExecutionPlanTest
030    extends TestCase
031{
032
033    public void testFindLastInPhase()
034        throws Exception
035    {
036        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
037
038        ExecutionPlanItem expected = plan.findLastInPhase( "package" );
039        ExecutionPlanItem beerPhase = plan.findLastInPhase( "BEER" );  // Beer comes straight after package in stub
040        assertEquals( expected, beerPhase );
041        assertNotNull( expected );
042    }
043
044    public void testThreadSafeMojos()
045        throws Exception
046    {
047        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
048        final Set<Plugin> unSafePlugins = plan.getNonThreadSafePlugins();
049        // There is only a single threadsafe plugin here...
050        assertEquals( plan.size() - 1, unSafePlugins.size() );
051
052    }
053
054
055    public void testFindLastWhenFirst()
056        throws Exception
057    {
058        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
059
060        ExecutionPlanItem beerPhase = plan.findLastInPhase(
061            LifecycleExecutionPlanCalculatorStub.VALIDATE.getPhase() );  // Beer comes straight after package in stub
062        assertNull( beerPhase );
063    }
064
065    public void testFindLastInPhaseMisc()
066        throws Exception
067    {
068        MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
069
070        assertNull( plan.findLastInPhase( "pacXkage" ) );
071        // Beer comes straight after package in stub, much like real life.
072        assertNotNull( plan.findLastInPhase( LifecycleExecutionPlanCalculatorStub.INITIALIZE.getPhase() ) );
073    }
074}