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