-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-106] Fixes for settings migration to 2.0
- Unit tests for configuration migration - Fix for premature exit of migration because a job without the old settings is encountered - Fix for jobs that have Slack job properties because they were edited after the was plugin installed, but do not send notifications - Fix to remove the Slack job properties from the configuration, even if there is no notifier
- Loading branch information
Showing
22 changed files
with
646 additions
and
22 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
180 changes: 180 additions & 0 deletions
180
src/test/java/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest.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,180 @@ | ||
package jenkins.plugins.slack.config; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import hudson.matrix.MatrixProject; | ||
import hudson.model.FreeStyleProject; | ||
import jenkins.model.Jenkins; | ||
import jenkins.plugins.slack.CommitInfoChoice; | ||
import jenkins.plugins.slack.SlackNotifier; | ||
import jenkins.plugins.slack.SlackNotifier.SlackJobProperty; | ||
|
||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.jvnet.hudson.test.JenkinsRule; | ||
import org.jvnet.hudson.test.recipes.LocalData; | ||
|
||
@SuppressWarnings("deprecation") | ||
public class BackwordsCompatible_1_8_SlackNotifierTest { | ||
|
||
@Rule | ||
public JenkinsRule j = new JenkinsRule(); | ||
|
||
public Jenkins jenkins; | ||
|
||
@Before | ||
public void setup() { | ||
jenkins = j.getInstance(); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void testBasicMigration() { | ||
FreeStyleProject project = (FreeStyleProject) jenkins.getItem("Test_Slack_Plugin"); | ||
SlackNotifier notifier = project.getPublishersList().get(SlackNotifier.class); | ||
|
||
assertEquals("jenkins-slack-plugin", notifier.getTeamDomain()); | ||
assertEquals("auth-token-for-test", notifier.getAuthToken()); | ||
assertEquals("http://localhost:8080/", notifier.getBuildServerUrl()); | ||
assertEquals("#slack-plugin-testing", notifier.getRoom()); | ||
|
||
assertFalse(notifier.getStartNotification()); | ||
assertTrue(notifier.getNotifySuccess()); | ||
assertFalse(notifier.getNotifyAborted()); | ||
assertFalse(notifier.getNotifyNotBuilt()); | ||
assertFalse(notifier.getNotifyUnstable()); | ||
assertTrue(notifier.getNotifyFailure()); | ||
assertFalse(notifier.getNotifyBackToNormal()); | ||
assertFalse(notifier.getNotifyRepeatedFailure()); | ||
assertFalse(notifier.includeTestSummary()); | ||
assertEquals(CommitInfoChoice.NONE, notifier.getCommitInfoChoice()); | ||
assertFalse(notifier.includeCustomMessage()); | ||
assertEquals("", notifier.getCustomMessage()); | ||
|
||
assertNull(project.getProperty(SlackJobProperty.class)); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void testGlobalSettingsOverriden() { | ||
FreeStyleProject project = (FreeStyleProject) jenkins.getItem("Test_Slack_Plugin"); | ||
SlackNotifier notifier = project.getPublishersList().get(SlackNotifier.class); | ||
|
||
assertEquals("jenkins-slack-plugin", notifier.getTeamDomain()); | ||
assertEquals("auth-token-for-test", notifier.getAuthToken()); | ||
assertEquals("http://localhost:8080/", notifier.getBuildServerUrl()); | ||
assertEquals("#slack-plugin-testing", notifier.getRoom()); | ||
|
||
assertFalse(notifier.getStartNotification()); | ||
assertTrue(notifier.getNotifySuccess()); | ||
assertFalse(notifier.getNotifyAborted()); | ||
assertFalse(notifier.getNotifyNotBuilt()); | ||
assertFalse(notifier.getNotifyUnstable()); | ||
assertTrue(notifier.getNotifyFailure()); | ||
assertFalse(notifier.getNotifyBackToNormal()); | ||
assertFalse(notifier.getNotifyRepeatedFailure()); | ||
assertFalse(notifier.includeTestSummary()); | ||
assertEquals(CommitInfoChoice.NONE, notifier.getCommitInfoChoice()); | ||
assertFalse(notifier.includeCustomMessage()); | ||
assertEquals("", notifier.getCustomMessage()); | ||
|
||
assertNull(project.getProperty(SlackJobProperty.class)); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void testGlobalSettingsNotOverridden() throws IOException { | ||
FreeStyleProject project = (FreeStyleProject) jenkins.getItem("Test_Slack_Plugin"); | ||
SlackNotifier notifier = project.getPublishersList().get(SlackNotifier.class); | ||
|
||
assertEquals("", notifier.getTeamDomain()); | ||
assertEquals("", notifier.getAuthToken()); | ||
assertEquals(j.getURL().toString(), notifier.getBuildServerUrl()); | ||
assertEquals("", notifier.getRoom()); | ||
|
||
assertFalse(notifier.getStartNotification()); | ||
assertTrue(notifier.getNotifySuccess()); | ||
assertFalse(notifier.getNotifyAborted()); | ||
assertFalse(notifier.getNotifyNotBuilt()); | ||
assertFalse(notifier.getNotifyUnstable()); | ||
assertTrue(notifier.getNotifyFailure()); | ||
assertFalse(notifier.getNotifyBackToNormal()); | ||
assertFalse(notifier.getNotifyRepeatedFailure()); | ||
assertFalse(notifier.includeTestSummary()); | ||
assertEquals(CommitInfoChoice.NONE, notifier.getCommitInfoChoice()); | ||
assertFalse(notifier.includeCustomMessage()); | ||
assertEquals("", notifier.getCustomMessage()); | ||
|
||
assertNull(project.getProperty(SlackJobProperty.class)); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void testMigrationFromNoPlugin() { | ||
FreeStyleProject project1 = (FreeStyleProject) jenkins.getItem("Test_01"); | ||
assertNull(project1.getPublishersList().get(SlackNotifier.class)); | ||
assertNull(project1.getProperty(SlackJobProperty.class)); | ||
|
||
FreeStyleProject project2 = (FreeStyleProject) jenkins.getItem("Test_02"); | ||
assertNull(project2.getPublishersList().get(SlackNotifier.class)); | ||
assertNull(project2.getProperty(SlackJobProperty.class)); | ||
|
||
MatrixProject project3 = (MatrixProject) jenkins.getItem("Test_03"); | ||
assertNull(project3.getPublishersList().get(SlackNotifier.class)); | ||
assertNull(project3.getProperty(SlackJobProperty.class)); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void testMigrationOfSomeJobs() throws IOException { | ||
// Project without Slack notifications | ||
FreeStyleProject project1 = (FreeStyleProject) jenkins.getItem("Test_01"); | ||
assertNull(project1.getPublishersList().get(SlackNotifier.class)); | ||
assertNull(project1.getProperty(SlackJobProperty.class)); | ||
|
||
// Another project without Slack notifications | ||
MatrixProject project3 = (MatrixProject) jenkins.getItem("Test_03"); | ||
assertNull(project3.getPublishersList().get(SlackNotifier.class)); | ||
assertNull(project3.getProperty(SlackJobProperty.class)); | ||
|
||
// Project with Slack notifications | ||
FreeStyleProject project2 = (FreeStyleProject) jenkins.getItem("Test_02"); | ||
SlackNotifier notifier = project2.getPublishersList().get(SlackNotifier.class); | ||
assertNotNull(notifier); | ||
|
||
assertEquals("", notifier.getTeamDomain()); | ||
assertEquals("", notifier.getAuthToken()); | ||
assertEquals(j.getURL().toString(), notifier.getBuildServerUrl()); | ||
assertEquals("", notifier.getRoom()); | ||
|
||
assertTrue(notifier.getStartNotification()); | ||
assertTrue(notifier.getNotifySuccess()); | ||
assertTrue(notifier.getNotifyAborted()); | ||
assertTrue(notifier.getNotifyNotBuilt()); | ||
assertTrue(notifier.getNotifyUnstable()); | ||
assertTrue(notifier.getNotifyFailure()); | ||
assertTrue(notifier.getNotifyBackToNormal()); | ||
assertTrue(notifier.getNotifyRepeatedFailure()); | ||
assertTrue(notifier.includeTestSummary()); | ||
assertEquals(CommitInfoChoice.AUTHORS_AND_TITLES, notifier.getCommitInfoChoice()); | ||
assertTrue(notifier.includeCustomMessage()); | ||
assertEquals("Custom message for 1.8 plugin.", notifier.getCustomMessage()); | ||
|
||
assertNull(project2.getProperty(SlackJobProperty.class)); | ||
} | ||
|
||
@Test | ||
@LocalData | ||
public void testMigrationWithNoNotifier() { | ||
FreeStyleProject project = (FreeStyleProject) jenkins.getItem("Test_01"); | ||
assertNull(project.getPublishersList().get(SlackNotifier.class)); | ||
assertNull(project.getProperty(SlackJobProperty.class)); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...gins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/config.xml
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 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
</hudson> |
46 changes: 46 additions & 0 deletions
46
...ordsCompatible_1_8_SlackNotifierTest/testBasicMigration/jobs/Test_Slack_Plugin/config.xml
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,46 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<project> | ||
<actions/> | ||
<description></description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties> | ||
<jenkins.plugins.slack.SlackNotifier_-SlackJobProperty plugin="slack@1.8.1-SNAPSHOT"> | ||
<teamDomain></teamDomain> | ||
<token></token> | ||
<room></room> | ||
<startNotification>false</startNotification> | ||
<notifySuccess>true</notifySuccess> | ||
<notifyAborted>false</notifyAborted> | ||
<notifyNotBuilt>false</notifyNotBuilt> | ||
<notifyUnstable>false</notifyUnstable> | ||
<notifyFailure>true</notifyFailure> | ||
<notifyBackToNormal>false</notifyBackToNormal> | ||
<notifyRepeatedFailure>false</notifyRepeatedFailure> | ||
<includeTestSummary>false</includeTestSummary> | ||
<showCommitList>false</showCommitList> | ||
<includeCustomMessage>false</includeCustomMessage> | ||
<customMessage></customMessage> | ||
</jenkins.plugins.slack.SlackNotifier_-SlackJobProperty> | ||
</properties> | ||
<scm class="hudson.scm.NullSCM"/> | ||
<canRoam>true</canRoam> | ||
<disabled>false</disabled> | ||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> | ||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> | ||
<triggers/> | ||
<concurrentBuild>false</concurrentBuild> | ||
<builders> | ||
<hudson.tasks.Shell> | ||
<command>echo "Hello World"</command> | ||
</hudson.tasks.Shell> | ||
</builders> | ||
<publishers> | ||
<jenkins.plugins.slack.SlackNotifier plugin="slack@1.8.1-SNAPSHOT"> | ||
<teamDomain>jenkins-slack-plugin</teamDomain> | ||
<authToken>auth-token-for-test</authToken> | ||
<buildServerUrl>http://localhost:8080/</buildServerUrl> | ||
<room>#slack-plugin-testing</room> | ||
</jenkins.plugins.slack.SlackNotifier> | ||
</publishers> | ||
<buildWrappers/> | ||
</project> |
3 changes: 3 additions & 0 deletions
3
...nfig/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/config.xml
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 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
</hudson> |
7 changes: 7 additions & 0 deletions
7
...SlackNotifierTest/testGlobalSettingsNotOverridden/jenkins.plugins.slack.SlackNotifier.xml
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,7 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<jenkins.plugins.slack.SlackNotifier_-DescriptorImpl plugin="slack@1.8.1-SNAPSHOT"> | ||
<teamDomain>jenkins-slack-plugin-global</teamDomain> | ||
<token>auth-token-for-test-global</token> | ||
<room>#slack-plugin-testing-global</room> | ||
<buildServerUrl>http://localhost:8080/global/</buildServerUrl> | ||
</jenkins.plugins.slack.SlackNotifier_-DescriptorImpl> |
46 changes: 46 additions & 0 deletions
46
...e_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jobs/Test_Slack_Plugin/config.xml
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,46 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<project> | ||
<actions/> | ||
<description></description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties> | ||
<jenkins.plugins.slack.SlackNotifier_-SlackJobProperty plugin="slack@1.8.1-SNAPSHOT"> | ||
<teamDomain></teamDomain> | ||
<token></token> | ||
<room></room> | ||
<startNotification>false</startNotification> | ||
<notifySuccess>true</notifySuccess> | ||
<notifyAborted>false</notifyAborted> | ||
<notifyNotBuilt>false</notifyNotBuilt> | ||
<notifyUnstable>false</notifyUnstable> | ||
<notifyFailure>true</notifyFailure> | ||
<notifyBackToNormal>false</notifyBackToNormal> | ||
<notifyRepeatedFailure>false</notifyRepeatedFailure> | ||
<includeTestSummary>false</includeTestSummary> | ||
<showCommitList>false</showCommitList> | ||
<includeCustomMessage>false</includeCustomMessage> | ||
<customMessage></customMessage> | ||
</jenkins.plugins.slack.SlackNotifier_-SlackJobProperty> | ||
</properties> | ||
<scm class="hudson.scm.NullSCM"/> | ||
<canRoam>true</canRoam> | ||
<disabled>false</disabled> | ||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> | ||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> | ||
<triggers/> | ||
<concurrentBuild>false</concurrentBuild> | ||
<builders> | ||
<hudson.tasks.Shell> | ||
<command>echo "Hello World"</command> | ||
</hudson.tasks.Shell> | ||
</builders> | ||
<publishers> | ||
<jenkins.plugins.slack.SlackNotifier plugin="slack@1.8.1-SNAPSHOT"> | ||
<teamDomain></teamDomain> | ||
<authToken></authToken> | ||
<buildServerUrl></buildServerUrl> | ||
<room></room> | ||
</jenkins.plugins.slack.SlackNotifier> | ||
</publishers> | ||
<buildWrappers/> | ||
</project> |
3 changes: 3 additions & 0 deletions
3
...k/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/config.xml
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 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<hudson> | ||
</hudson> |
7 changes: 7 additions & 0 deletions
7
...1_8_SlackNotifierTest/testGlobalSettingsOverriden/jenkins.plugins.slack.SlackNotifier.xml
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,7 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<jenkins.plugins.slack.SlackNotifier_-DescriptorImpl plugin="slack@1.8.1-SNAPSHOT"> | ||
<teamDomain>jenkins-slack-plugin-global</teamDomain> | ||
<token>auth-token-for-test-global</token> | ||
<room>#slack-plugin-testing-global</room> | ||
<buildServerUrl>http://localhost:8080/global/</buildServerUrl> | ||
</jenkins.plugins.slack.SlackNotifier_-DescriptorImpl> |
Oops, something went wrong.