View Javadoc
1   package org.apache.maven.plugins.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.Collections;
24  import java.util.List;
25  
26  import org.apache.maven.plugin.testing.AbstractMojoTestCase;
27  import org.apache.maven.plugins.invoker.model.BuildJob;
28  
29  /**
30   * @author Olivier Lamy
31   * @since 18 nov. 07
32   */
33  public class InvokerMojoTest
34      extends AbstractMojoTestCase
35  {
36  
37      public void testSingleInvokerTest()
38          throws Exception
39      {
40          InvokerMojo invokerMojo = new InvokerMojo();
41          String dirPath = getBasedir() + "/src/test/resources/unit";
42          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
43          assertEquals( 1, goals.size() );
44          setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) );
45          setVariableValueToObject( invokerMojo, "invokerTest", "*dummy*" );
46          BuildJob[] poms = invokerMojo.getBuildJobs();
47          assertEquals( 1, poms.length );
48      }
49  
50      public void testMultiInvokerTest()
51          throws Exception
52      {
53          InvokerMojo invokerMojo = new InvokerMojo();
54          String dirPath = getBasedir() + "/src/test/resources/unit";
55          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
56          assertEquals( 1, goals.size() );
57          setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) );
58          setVariableValueToObject( invokerMojo, "invokerTest", "*dummy*,*terpolatio*" );
59          BuildJob[] poms = invokerMojo.getBuildJobs();
60          assertEquals( 2, poms.length );
61      }
62  
63      public void testFullPatternInvokerTest()
64          throws Exception
65      {
66          InvokerMojo invokerMojo = new InvokerMojo();
67          String dirPath = getBasedir() + "/src/test/resources/unit";
68          List<String> goals = invokerMojo.getGoals( new File( dirPath ) );
69          assertEquals( 1, goals.size() );
70          setVariableValueToObject( invokerMojo, "projectsDirectory", new File( dirPath ) );
71          setVariableValueToObject( invokerMojo, "invokerTest", "*" );
72          BuildJob[] poms = invokerMojo.getBuildJobs();
73          assertEquals( 4, poms.length );
74      }
75  
76      public void testAlreadyCloned()
77          throws Exception
78      {
79          assertFalse( AbstractInvokerMojo.alreadyCloned( "dir", Collections.<String>emptyList() ) );
80          assertTrue( AbstractInvokerMojo.alreadyCloned( "dir", Collections.singletonList( "dir" ) ) );
81          assertTrue( AbstractInvokerMojo.alreadyCloned( "dir" + File.separator + "sub",
82                                                         Collections.singletonList( "dir" ) ) );
83          assertFalse( AbstractInvokerMojo.alreadyCloned( "dirs", Collections.singletonList( "dir" ) ) );
84      }
85  
86  }