提交 900341f4 编写于 作者: C Christoph Kutzinski

Add regression test for SurefireArchiver test mojo detection [JENKINS-8334]

上级 310e22db
......@@ -253,7 +253,7 @@ public class SurefireArchiver extends TestFailureDetector {
}
}
private boolean isTestMojo(MojoInfo mojo) {
boolean isTestMojo(MojoInfo mojo) {
if ((!mojo.is("com.sun.maven", "maven-junit-plugin", "test"))
&& (!mojo.is("org.sonatype.flexmojos", "flexmojos-maven-plugin", "test-run"))
&& (!mojo.is("org.eclipse.tycho", "tycho-surefire-plugin", "test"))
......
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;
}
}
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));
}
}
......@@ -13,6 +13,7 @@ import hudson.maven.MavenBuildProxy;
import hudson.maven.MavenProjectActionBuilder;
import hudson.maven.MavenReporter;
import hudson.maven.MojoInfo;
import hudson.maven.MojoInfoBuilder;
import hudson.model.BuildListener;
import hudson.model.Cause;
import hudson.model.Result;
......@@ -28,9 +29,6 @@ import java.util.Calendar;
import java.util.List;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.tools.ant.types.FileSet;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.junit.Assert;
......@@ -69,17 +67,8 @@ public class SurefireArchiverUnitTest {
}
private MojoInfo createMojoInfo() throws ComponentConfigurationException {
PluginDescriptor pluginDescriptor = new PluginDescriptor();
pluginDescriptor.setGroupId("org.apache.maven.plugins");
pluginDescriptor.setArtifactId("maven-surefire-plugin");
pluginDescriptor.setVersion("2.9");
MojoDescriptor mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setPluginDescriptor(pluginDescriptor);
mojoDescriptor.setGoal("test");
MojoExecution mojoExecution = new MojoExecution(mojoDescriptor);
MojoInfo info = new MojoInfo(mojoExecution, null, null, null);
MojoInfo info = MojoInfoBuilder.mojoBuilder("org.apache.maven.plugins", "maven-surefire-plugin", "test")
.version("2.9").build();
MojoInfo spy = spy(info);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册