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