1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3    * agreements. See the NOTICE file distributed with this work for additional information regarding
4    * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * copy of the License at
7    *
8    * http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package org.apache.maven.lifecycle;
17  
18  import junit.framework.TestCase;
19  import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
20  import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
21  import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
22  import org.apache.maven.model.Plugin;
23  
24  import java.util.Iterator;
25  import java.util.List;
26  import java.util.Set;
27  
28  /**
29   * @author Kristian Rosenvold
30   */
31  public class MavenExecutionPlanTest
32      extends TestCase
33  {
34      public void testFindFirstWithMatchingSchedule()
35          throws Exception
36      {
37          final List<Scheduling> cycles = DefaultLifecyclesStub.getSchedulingList();
38          final Schedule schedule = cycles.get( 0 ).getSchedules().get( 0 );
39          assertNotNull( schedule );
40  
41      }
42  
43      public void testForceAllComplete()
44          throws Exception
45      {
46          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
47          plan.forceAllComplete();
48          final Iterator<ExecutionPlanItem> planItemIterator = plan.iterator();
49          assertTrue( planItemIterator.next().isDone() );
50          assertTrue( planItemIterator.next().isDone() );
51      }
52  
53      public void testFindLastInPhase()
54          throws Exception
55      {
56          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
57  
58          ExecutionPlanItem expected = plan.findLastInPhase( "package" );
59          ExecutionPlanItem beerPhase = plan.findLastInPhase( "BEER" );  // Beer comes straight after package in stub
60          assertEquals( expected, beerPhase );
61          assertNotNull( expected );
62      }
63  
64      public void testThreadSafeMojos()
65          throws Exception
66      {
67          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
68          final Set<Plugin> unSafePlugins = plan.getNonThreadSafePlugins();
69          // There is only a single threadsafe plugin here...
70          assertEquals( plan.size() - 1, unSafePlugins.size() );
71  
72      }
73  
74  
75      public void testFindLastWhenFirst()
76          throws Exception
77      {
78          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
79  
80          ExecutionPlanItem beerPhase = plan.findLastInPhase(
81              LifecycleExecutionPlanCalculatorStub.VALIDATE.getPhase() );  // Beer comes straight after package in stub
82          assertNull( beerPhase );
83      }
84  
85      public void testFindLastInPhaseMisc()
86          throws Exception
87      {
88          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
89  
90          assertNull( plan.findLastInPhase( "pacXkage" ) );
91          // Beer comes straight after package in stub, much like real life.
92          assertNotNull( plan.findLastInPhase( LifecycleExecutionPlanCalculatorStub.INITIALIZE.getPhase() ) );
93      }
94  }