Skip to content

Commit

Permalink
Add regression test for SurefireArchiver test mojo detection [JENKINS…
Browse files Browse the repository at this point in the history
…-8334]

Originally-Committed-As: 900341f4912e3d055c30cc12ea5ed05310bf97df
  • Loading branch information
kutzi committed Jan 4, 2013
1 parent 3950ecc commit 61f6325
Show file tree
Hide file tree
Showing 4 changed files with 252 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hudson/maven/reporters/SurefireArchiver.java
Expand Up @@ -253,7 +253,7 @@ public Collection<? extends Action> getProjectActions(MavenModule module) {
}
}

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"))
Expand Down
85 changes: 85 additions & 0 deletions src/test/java/hudson/maven/MojoInfoBuilder.java
@@ -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;
}


}
@@ -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));
}
}
17 changes: 3 additions & 14 deletions src/test/java/hudson/maven/reporters/SurefireArchiverUnitTest.java
Expand Up @@ -13,6 +13,7 @@
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;
Expand All @@ -28,9 +29,6 @@
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;
Expand Down Expand Up @@ -69,17 +67,8 @@ public void before() throws ComponentConfigurationException, URISyntaxException
}

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);

Expand Down

0 comments on commit 61f6325

Please sign in to comment.