Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression test for SurefireArchiver test mojo detection [JENKINS…
…-8334] Originally-Committed-As: 900341f4912e3d055c30cc12ea5ed05310bf97df
- Loading branch information
Showing
4 changed files
with
252 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package hudson.maven; | ||
|
||
import hudson.maven.MojoInfo; | ||
|
||
import java.io.File; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.plugin.descriptor.MojoDescriptor; | ||
import org.apache.maven.plugin.descriptor.PluginDescriptor; | ||
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; | ||
import org.codehaus.plexus.configuration.DefaultPlexusConfiguration; | ||
import org.codehaus.plexus.configuration.PlexusConfiguration; | ||
|
||
public class MojoInfoBuilder { | ||
|
||
private String groupId; | ||
private String artifactId; | ||
private String goalName; | ||
private String version = "1.0"; | ||
private Map<String, String> configValues = new HashMap<String, String>(); | ||
|
||
public static MojoInfoBuilder mojoBuilder(String groupId, String artifactId, String goalName) { | ||
return new MojoInfoBuilder(groupId, artifactId, goalName); | ||
} | ||
|
||
private MojoInfoBuilder(String groupId, String artifactId, String goalName) { | ||
this.groupId = groupId; | ||
this.artifactId = artifactId; | ||
this.goalName = goalName; | ||
} | ||
|
||
public MojoInfoBuilder copy() { | ||
MojoInfoBuilder copy = new MojoInfoBuilder(this.groupId, this.artifactId, this.goalName) | ||
.version(this.version); | ||
copy.configValues.putAll(this.configValues); | ||
return copy; | ||
} | ||
|
||
public MojoInfoBuilder version(String version) { | ||
this.version = version; | ||
return this; | ||
} | ||
|
||
public MojoInfoBuilder configValue(String key,String value) { | ||
configValues.put(key, value); | ||
return this; | ||
} | ||
|
||
public MojoInfo build() { | ||
PluginDescriptor pluginDescriptor = new PluginDescriptor(); | ||
pluginDescriptor.setGroupId(groupId); | ||
pluginDescriptor.setArtifactId(artifactId); | ||
pluginDescriptor.setVersion(version); | ||
|
||
MojoDescriptor mojoDescriptor = new MojoDescriptor(); | ||
mojoDescriptor.setPluginDescriptor(pluginDescriptor); | ||
mojoDescriptor.setGoal(goalName); | ||
|
||
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor); | ||
|
||
PlexusConfiguration configuration = new DefaultPlexusConfiguration("configuration"); | ||
for (Map.Entry<String, String> e : this.configValues.entrySet()) { | ||
configuration.addChild(e.getKey(),e.getValue()); | ||
} | ||
|
||
ExpressionEvaluator evaluator = new ExpressionEvaluator() { | ||
@Override | ||
public Object evaluate(String expression) { | ||
return expression; | ||
} | ||
|
||
@Override | ||
public File alignToBaseDirectory(File file) { | ||
return file; | ||
} | ||
}; | ||
|
||
MojoInfo info = new MojoInfo(mojoExecution, null, configuration, evaluator); | ||
return info; | ||
} | ||
|
||
|
||
} |
163 changes: 163 additions & 0 deletions
163
src/test/java/hudson/maven/reporters/SurefireArchiverDetectTestMojosTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package hudson.maven.reporters; | ||
|
||
import static hudson.maven.MojoInfoBuilder.mojoBuilder; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import hudson.maven.MojoInfo; | ||
import hudson.maven.MojoInfoBuilder; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Regression test for the detection of test mojos in {@link SurefireArchiver}. | ||
* | ||
* @author kutzi | ||
*/ | ||
public class SurefireArchiverDetectTestMojosTest { | ||
|
||
private SurefireArchiver surefireArchiver; | ||
|
||
@Before | ||
public void before() { | ||
this.surefireArchiver = new SurefireArchiver(); | ||
} | ||
|
||
@Test | ||
public void shouldDetectMavenSurefire() { | ||
MojoInfo mojo = mojoBuilder("org.apache.maven.plugins", "maven-surefire-plugin", "test").build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectMavenFailsafe() { | ||
MojoInfo mojo = mojoBuilder("org.apache.maven.plugins", "maven-failsafe-plugin", "verify").build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectMavenSurefireSkip() { | ||
MojoInfoBuilder builder = mojoBuilder("org.apache.maven.plugins", "maven-surefire-plugin", "test"); | ||
MojoInfo mojo = builder.copy() | ||
.configValue("skip", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy() | ||
.version("2.4") | ||
.configValue("skipTests", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy() | ||
.version("2.3") | ||
.configValue("skipExec", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
// That's not a valid skip property: | ||
mojo = builder.copy() | ||
.configValue("skip--Exec", "true").build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectMavenJunitPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("com.sun.maven", "maven-junit-plugin", "test"); | ||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy() | ||
.configValue("skipTests", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectFlexMojoMavenPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("org.sonatype.flexmojos", "flexmojos-maven-plugin", "test-run"); | ||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy() | ||
.configValue("skipTest", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectOsgiTestPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("org.sonatype.tycho", "maven-osgi-test-plugin", "test"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy().configValue("skipTest", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectTychoSurefirePlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("org.eclipse.tycho", "tycho-surefire-plugin", "test"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy().configValue("skipTest", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectMavenAndroidPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("com.jayway.maven.plugins.android.generation2", "maven-android-plugin", "internal-integration-test") | ||
.version("3.0.0-alpha-6"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy().configValue("skipTests", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectAndroidMavenPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("com.jayway.maven.plugins.android.generation2", "android-maven-plugin", "internal-integration-test") | ||
.version("3.0.0-alpha-6"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy().configValue("skipTests", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectGwtMavenPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("org.codehaus.mojo", "gwt-maven-plugin", "test") | ||
.version("1.2"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
// that version of the plugin is too old | ||
mojo = builder.copy().version("1.1").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectSoapUiMavenPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("eviware", "maven-soapui-plugin", "test"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy().configValue("skip", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
|
||
@Test | ||
public void shouldDetectSoapUiProMavenPlugin() { | ||
MojoInfoBuilder builder = mojoBuilder("eviware", "maven-soapui-pro-plugin", "test"); | ||
|
||
MojoInfo mojo = builder.build(); | ||
assertTrue(this.surefireArchiver.isTestMojo(mojo)); | ||
|
||
mojo = builder.copy().configValue("skip", "true").build(); | ||
assertFalse(this.surefireArchiver.isTestMojo(mojo)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters