1 package org.apache.maven.plugin.invoker;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
37 public class InvokerMojoTest
38 extends AbstractMojoTestCase
39 {
40
41
42
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 }