View Javadoc
1   package org.apache.maven.plugin.invoker;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.io.File;
23  import java.util.Arrays;
24  import java.util.Collections;
25  import java.util.List;
26  
27  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
28  import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
29  import org.apache.maven.plugin.invoker.model.BuildJob;
30  import org.apache.maven.settings.Settings;
31  
32  /**
33   * @author Olivier Lamy
34   * @since 18 nov. 07
35   * @version $Id: InvokerMojoTest.java 1606207 2014-06-27 20:27:03Z khmarbaise $
36   */
37  public class InvokerMojoTest
38      extends AbstractMojoTestCase
39  {
40  
41      /**
42       * test reading goals from a file
43       */
44      public void testReadGoalsFromFile()
45          throws Exception
46      {
47          MavenProjectStub project = new MavenProjectStub();
48          project.setTestClasspathElements( Collections.EMPTY_LIST );
49  
50          InvokerMojo invokerMojo = new InvokerMojo();
51          setVariableValueToObject( invokerMojo, "goalsFile", "goals.txt" );
52          setVariableValueToObject( invokerMojo, "project", project );
53          setVariableValueToObject( invokerMojo, "settings", new Settings() );
54          String dirPath = getBasedir() + "/src/test/resources/unit/goals-from-file/";
55          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
56          assertEquals( 3, goals.size() );
57      }
58  
59      public void testSingleInvokerTest()
60          throws Exception
61      {
62          InvokerMojo invokerMojo = new InvokerMojo();
63          setVariableValueToObject( invokerMojo, "goalsFile", "validate-goal.txt" );
64          String dirPath = getBasedir() + "/src/test/resources/unit";
65          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
66          assertEquals( 1, goals.size() );
67          setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) );
68          setVariableValueToObject( invokerMojo, "invokerTest", "*dummy*" );
69          BuildJob[] poms = invokerMojo.getBuildJobs();
70          System.out.println( Arrays.asList( poms ) );
71          assertEquals( 1, poms.length );
72      }
73  
74      public void testMultiInvokerTest()
75          throws Exception
76      {
77          InvokerMojo invokerMojo = new InvokerMojo();
78          setVariableValueToObject( invokerMojo, "goalsFile", "validate-goal.txt" );
79          String dirPath = getBasedir() + "/src/test/resources/unit";
80          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
81          assertEquals( 1, goals.size() );
82          setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) );
83          setVariableValueToObject( invokerMojo, "invokerTest", "*dummy*,*terpolatio*" );
84          BuildJob[] poms = invokerMojo.getBuildJobs();
85          System.out.println( Arrays.asList( poms ) );
86          assertEquals( 2, poms.length );
87      }
88  
89      public void testFullPatternInvokerTest()
90          throws Exception
91      {
92          InvokerMojo invokerMojo = new InvokerMojo();
93          setVariableValueToObject( invokerMojo, "goalsFile", "validate-goal.txt" );
94          String dirPath = getBasedir() + "/src/test/resources/unit";
95          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
96          assertEquals( 1, goals.size() );
97          setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) );
98          setVariableValueToObject( invokerMojo, "invokerTest", "*" );
99          BuildJob[] poms = invokerMojo.getBuildJobs();
100         System.out.println( Arrays.asList( poms ) );
101         assertEquals( 4, poms.length );
102     }
103 
104     public void testAlreadyCloned()
105         throws Exception
106     {
107         assertFalse( AbstractInvokerMojo.alreadyCloned( "dir", Collections.<String> emptyList() ) );
108         assertTrue( AbstractInvokerMojo.alreadyCloned( "dir", Collections.singletonList( "dir" ) ) );
109         assertTrue( AbstractInvokerMojo.alreadyCloned( "dir" + File.separator + "sub",
110                                                        Collections.singletonList( "dir" ) ) );
111         assertFalse( AbstractInvokerMojo.alreadyCloned( "dirs", Collections.singletonList( "dir" ) ) );
112     }
113 
114 }