Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from glenritchie/master
JENKINS-27722 - fix for previous merge that could stop plugin working on some jobs
- Loading branch information
Showing
5 changed files
with
194 additions
and
20 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
35 changes: 35 additions & 0 deletions
35
src/main/java/hudson/plugins/release/ReleaseWrapperHelper.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,35 @@ | ||
/* | ||
* | ||
*/ | ||
package hudson.plugins.release; | ||
|
||
import hudson.Functions; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Descriptor; | ||
import hudson.tasks.Builder; | ||
import hudson.tasks.Publisher; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Helper class | ||
*/ | ||
public class ReleaseWrapperHelper | ||
{ | ||
/** Retrieve a list of all build steps including publishers and builders | ||
* | ||
* @param project The project | ||
* @return A list of descriptor's for both publishers and builders | ||
*/ | ||
static public List<Descriptor> getBuildSteps(AbstractProject<?,?> project) | ||
{ | ||
List<Descriptor<Publisher>> publishers = Functions.getPublisherDescriptors(project); | ||
List<Descriptor<Builder>> builders = Functions.getBuilderDescriptors(project); | ||
|
||
List<Descriptor> descriptors = new LinkedList<Descriptor>(); | ||
descriptors.addAll(publishers); | ||
descriptors.addAll(builders); | ||
|
||
return descriptors; | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/test/java/hudson/plugins/release/TestReleasePlugin.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,36 @@ | ||
package hudson.plugins.release; | ||
|
||
import hudson.PluginWrapper; | ||
import hudson.model.Descriptor; | ||
|
||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Test the general integration of the plugin with Jenkins/Hudson and ensure the plugin is registered properly and is active | ||
*/ | ||
public class TestReleasePlugin | ||
{ | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
@Test | ||
public void testPluginActive() throws Exception | ||
{ | ||
// Check if the plugin is loaded and active | ||
PluginWrapper plugin = j.getPluginManager().getPlugin("release"); | ||
assertTrue("Plugin not active", plugin.isActive()); | ||
} | ||
|
||
@Test | ||
public void testDescriptorRegistered() throws Exception | ||
{ | ||
Descriptor<?> descriptor = Descriptor.find(ReleaseWrapper.DescriptorImpl.class.getName()); | ||
assertNotNull("Must have ReleaseWrapper descriptor", descriptor); | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
src/test/java/hudson/plugins/release/TestReleasePluginJob.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,110 @@ | ||
package hudson.plugins.release; | ||
|
||
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput; | ||
import com.gargoylesoftware.htmlunit.html.HtmlForm; | ||
import com.gargoylesoftware.htmlunit.html.HtmlPage; | ||
|
||
import org.jvnet.hudson.test.JenkinsRule; | ||
|
||
import hudson.model.*; | ||
import hudson.plugins.release.ReleaseWrapper; | ||
import hudson.plugins.release.ReleaseWrapper.ReleaseAction; | ||
import hudson.tasks.BuildWrapper; | ||
import hudson.util.DescribableList; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.Rule; | ||
|
||
/** | ||
* Test the general integration of the plugin with Jenkins/Hudson and ensure it gets added properly and correctly add it's links/buttons etc to the | ||
* required pages. | ||
*/ | ||
public class TestReleasePluginJob | ||
{ | ||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
FreeStyleProject job; | ||
|
||
@Before | ||
public void createJob() throws Exception | ||
{ | ||
job = j.createFreeStyleProject("test"); | ||
} | ||
|
||
@After | ||
public void deleteJob() throws Exception | ||
{ | ||
job.delete(); | ||
} | ||
|
||
@Test | ||
public void testPermission() throws Exception | ||
{ | ||
// Check if the user has permission to release | ||
assertTrue("No permission", ReleaseWrapper.hasReleasePermission(job)); | ||
} | ||
|
||
@Test | ||
public void testInBuilders() throws Exception | ||
{ | ||
// Check the job has the ReleaseWrapper listed in it's builders, AND that it it listed in the project actions | ||
enableReleaseBuilder(); | ||
DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappersList = job.getBuildWrappersList(); | ||
Descriptor<BuildWrapper> descriptor = Descriptor.find(ReleaseWrapper.DescriptorImpl.class.getName()); | ||
BuildWrapper buildWrapper = buildWrappersList.get(descriptor); | ||
assertNotNull(buildWrapper); | ||
Collection<? extends Action> actions = buildWrapper.getProjectActions(job); | ||
assertNotNull("Actions can't be null", actions); | ||
assertThat("Must have actions", actions.size(), not(0)); | ||
} | ||
|
||
@Test | ||
public void testInActions() throws Exception | ||
{ | ||
// Check that the job has an action listed when release is enabled | ||
enableReleaseBuilder(); | ||
assertNotNull("Must have action", job.getAction(ReleaseAction.class)); | ||
} | ||
|
||
@Test | ||
public void testEnableReleaseUsingWebPage() throws Exception | ||
{ | ||
enableReleaseBuilder(); | ||
|
||
/** Check if the Release links exist */ | ||
HtmlPage page = j.createWebClient().goTo("job/test/"); | ||
// Internationalisation not needed because the URL doesn't change between languages | ||
// see getUrlName() in ReleaseAction | ||
List<Object> nodes = page.selectNodes("//a[contains(@href, '/test/release')]"); | ||
assertThat("Require 2 href links", nodes.size(), is(2)); | ||
} | ||
|
||
/** Enable the release builder by adding it to the job */ | ||
private void enableReleaseBuilder() throws Exception | ||
{ | ||
/** Enable the release plugin for the job */ | ||
HtmlForm configForm = j.createWebClient().getPage(job, "configure").getFormByName("config"); | ||
assertThat(configForm, notNullValue()); | ||
|
||
// not sure if internationalisation required for this? | ||
HtmlCheckBoxInput releaseCheckButton = configForm.getInputByName("hudson-plugins-release-ReleaseWrapper"); | ||
assertThat("No Release Check Button found", releaseCheckButton, notNullValue()); | ||
releaseCheckButton.setChecked(true); | ||
j.submit(configForm); | ||
} | ||
|
||
} |