View Javadoc
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  
20  import org.apache.maven.lifecycle.internal.ExecutionPlanItem;
21  import org.apache.maven.lifecycle.internal.stub.DefaultLifecyclesStub;
22  import org.apache.maven.lifecycle.internal.stub.LifecycleExecutionPlanCalculatorStub;
23  import org.apache.maven.model.Plugin;
24  
25  import java.util.Iterator;
26  import java.util.List;
27  import java.util.Set;
28  
29  /**
30   * @author Kristian Rosenvold
31   */
32  public class MavenExecutionPlanTest
33      extends TestCase
34  {
35  
36      public void testFindLastInPhase()
37          throws Exception
38      {
39          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
40  
41          ExecutionPlanItem expected = plan.findLastInPhase( "package" );
42          ExecutionPlanItem beerPhase = plan.findLastInPhase( "BEER" );  // Beer comes straight after package in stub
43          assertEquals( expected, beerPhase );
44          assertNotNull( expected );
45      }
46  
47      public void testThreadSafeMojos()
48          throws Exception
49      {
50          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
51          final Set<Plugin> unSafePlugins = plan.getNonThreadSafePlugins();
52          // There is only a single threadsafe plugin here...
53          assertEquals( plan.size() - 1, unSafePlugins.size() );
54  
55      }
56  
57  
58      public void testFindLastWhenFirst()
59          throws Exception
60      {
61          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
62  
63          ExecutionPlanItem beerPhase = plan.findLastInPhase(
64              LifecycleExecutionPlanCalculatorStub.VALIDATE.getPhase() );  // Beer comes straight after package in stub
65          assertNull( beerPhase );
66      }
67  
68      public void testFindLastInPhaseMisc()
69          throws Exception
70      {
71          MavenExecutionPlan plan = LifecycleExecutionPlanCalculatorStub.getProjectAExceutionPlan();
72  
73          assertNull( plan.findLastInPhase( "pacXkage" ) );
74          // Beer comes straight after package in stub, much like real life.
75          assertNotNull( plan.findLastInPhase( LifecycleExecutionPlanCalculatorStub.INITIALIZE.getPhase() ) );
76      }
77  }