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 #98 from mdenicki/feature/addingVersion
* upstream/pr/98: JENKINS-19286: Possibility to add fix version to list instead of replacing whole list or specific version
- Loading branch information
Showing
6 changed files
with
152 additions
and
5 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
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
3 changes: 3 additions & 0 deletions
3
src/main/resources/hudson/plugins/jira/JiraIssueMigrator/help-addRelease.html
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,3 @@ | ||
<div> | ||
<p>Add Jira Release instead of replace. If checked, Replace Jira Release field will be ignored.</p> | ||
</div> |
81 changes: 81 additions & 0 deletions
81
src/test/java/hudson/plugins/jira/JiraIssueMigratorTest.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,81 @@ | ||
package hudson.plugins.jira; | ||
|
||
import hudson.EnvVars; | ||
import hudson.Launcher; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.BuildListener; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class JiraIssueMigratorTest { | ||
|
||
private static final String PROJECT_KEY = "PROJECT"; | ||
private static final String RELEASE = "release"; | ||
private static final String RELEASE_TO_REPLACE = "releaseToReplace"; | ||
private static final String QUERY = "query"; | ||
AbstractBuild build; | ||
Launcher launcher; | ||
BuildListener listener; | ||
EnvVars envVars; | ||
JiraSite jiraSite; | ||
AbstractProject project; | ||
JiraIssueMigrator jiraIssueMigrator; | ||
|
||
@Before | ||
public void prepareMocks() throws IOException, InterruptedException { | ||
build = mock(AbstractBuild.class); | ||
launcher = mock(Launcher.class); | ||
listener = mock(BuildListener.class); | ||
envVars = mock(EnvVars.class); | ||
jiraSite = mock(JiraSite.class); | ||
project = mock(AbstractProject.class); | ||
|
||
when(build.getEnvironment(listener)).thenReturn(envVars); | ||
when(envVars.expand(PROJECT_KEY)).thenReturn(PROJECT_KEY); | ||
when(envVars.expand(RELEASE)).thenReturn(RELEASE); | ||
when(envVars.expand(QUERY)).thenReturn(QUERY); | ||
when(envVars.expand(RELEASE_TO_REPLACE)).thenReturn(RELEASE_TO_REPLACE); | ||
when(envVars.expand(null)).thenReturn(null); | ||
when(build.getProject()).thenReturn(project); | ||
} | ||
|
||
@Test | ||
public void testAddingVersion() throws IOException { | ||
boolean addRelease = true; | ||
jiraIssueMigrator = spy(new JiraIssueMigrator(PROJECT_KEY, RELEASE, QUERY, null, addRelease)); | ||
doReturn(jiraSite).when(jiraIssueMigrator).getJiraSiteForProject(project); | ||
boolean result = jiraIssueMigrator.perform(build, launcher, listener); | ||
verify(jiraSite, never()).migrateIssuesToFixVersion(anyString(), anyString(), anyString()); | ||
verify(jiraSite, never()).replaceFixVersion(anyString(), anyString(), anyString(), anyString()); | ||
verify(jiraSite, times(1)).addFixVersionToIssue(PROJECT_KEY, RELEASE, QUERY); | ||
assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void testMigratingToVersion() throws IOException { | ||
jiraIssueMigrator = spy(new JiraIssueMigrator(PROJECT_KEY, RELEASE, QUERY, null, false)); | ||
doReturn(jiraSite).when(jiraIssueMigrator).getJiraSiteForProject(project); | ||
boolean result = jiraIssueMigrator.perform(build, launcher, listener); | ||
verify(jiraSite, never()).addFixVersionToIssue(anyString(), anyString(), anyString()); | ||
verify(jiraSite, never()).replaceFixVersion(anyString(), anyString(), anyString(), anyString()); | ||
verify(jiraSite, times(1)).migrateIssuesToFixVersion(PROJECT_KEY, RELEASE, QUERY); | ||
assertTrue(result); | ||
} | ||
|
||
@Test | ||
public void testReplacingVersion() throws IOException { | ||
jiraIssueMigrator = spy(new JiraIssueMigrator(PROJECT_KEY, RELEASE, QUERY, RELEASE_TO_REPLACE, false)); | ||
doReturn(jiraSite).when(jiraIssueMigrator).getJiraSiteForProject(project); | ||
boolean result = jiraIssueMigrator.perform(build, launcher, listener); | ||
verify(jiraSite, never()).addFixVersionToIssue(anyString(), anyString(), anyString()); | ||
verify(jiraSite, never()).migrateIssuesToFixVersion(anyString(), anyString(), anyString()); | ||
verify(jiraSite, times(1)).replaceFixVersion(PROJECT_KEY, RELEASE_TO_REPLACE, RELEASE, QUERY); | ||
assertTrue(result); | ||
} | ||
} |