From 89c9a838078910f192f74549382d70c30ff2d849 Mon Sep 17 00:00:00 2001 From: Sergiy Kopchalyuk Date: Sat, 21 Nov 2015 00:14:28 +0100 Subject: [PATCH 1/3] migrating settings from job config.properties to publishers section testing T.B.D --- .../jenkins/plugins/slack/SlackNotifier.java | 194 +++++++++++++++++- 1 file changed, 187 insertions(+), 7 deletions(-) diff --git a/src/main/java/jenkins/plugins/slack/SlackNotifier.java b/src/main/java/jenkins/plugins/slack/SlackNotifier.java index 20dc3e66..1010aed2 100755 --- a/src/main/java/jenkins/plugins/slack/SlackNotifier.java +++ b/src/main/java/jenkins/plugins/slack/SlackNotifier.java @@ -1,23 +1,21 @@ package jenkins.plugins.slack; -import hudson.EnvVars; -import hudson.Extension; -import hudson.Launcher; -import hudson.model.AbstractBuild; -import hudson.model.AbstractProject; -import hudson.model.BuildListener; -import hudson.model.Descriptor; +import hudson.*; +import hudson.model.*; +import hudson.model.listeners.ItemListener; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.BuildStepMonitor; import hudson.tasks.Notifier; import hudson.tasks.Publisher; import hudson.util.FormValidation; +import jenkins.model.Jenkins; import jenkins.model.JenkinsLocationConfiguration; import net.sf.json.JSONObject; import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.export.Exported; import java.io.IOException; import java.util.Map; @@ -325,4 +323,186 @@ public FormValidation doTestConnection(@QueryParameter("slackTeamDomain") final } } } + + @Deprecated + public static class SlackJobProperty extends hudson.model.JobProperty> { + + private String teamDomain; + private String token; + private String room; + private boolean startNotification; + private boolean notifySuccess; + private boolean notifyAborted; + private boolean notifyNotBuilt; + private boolean notifyUnstable; + private boolean notifyFailure; + private boolean notifyBackToNormal; + private boolean notifyRepeatedFailure; + private boolean includeTestSummary; + private boolean showCommitList; + private boolean includeCustomMessage; + private String customMessage; + + @DataBoundConstructor + public SlackJobProperty(String teamDomain, + String token, + String room, + boolean startNotification, + boolean notifyAborted, + boolean notifyFailure, + boolean notifyNotBuilt, + boolean notifySuccess, + boolean notifyUnstable, + boolean notifyBackToNormal, + boolean notifyRepeatedFailure, + boolean includeTestSummary, + boolean showCommitList, + boolean includeCustomMessage, + String customMessage) { + this.teamDomain = teamDomain; + this.token = token; + this.room = room; + this.startNotification = startNotification; + this.notifyAborted = notifyAborted; + this.notifyFailure = notifyFailure; + this.notifyNotBuilt = notifyNotBuilt; + this.notifySuccess = notifySuccess; + this.notifyUnstable = notifyUnstable; + this.notifyBackToNormal = notifyBackToNormal; + this.notifyRepeatedFailure = notifyRepeatedFailure; + this.includeTestSummary = includeTestSummary; + this.showCommitList = showCommitList; + this.includeCustomMessage = includeCustomMessage; + this.customMessage = customMessage; + } + + @Exported + public String getTeamDomain() { + return teamDomain; + } + + @Exported + public String getToken() { + return token; + } + + @Exported + public String getRoom() { + return room; + } + + @Exported + public boolean getStartNotification() { + return startNotification; + } + + @Exported + public boolean getNotifySuccess() { + return notifySuccess; + } + + @Exported + public boolean getShowCommitList() { + return showCommitList; + } + + @Override + public boolean prebuild(AbstractBuild build, BuildListener listener) { + return super.prebuild(build, listener); + } + + @Exported + public boolean getNotifyAborted() { + return notifyAborted; + } + + @Exported + public boolean getNotifyFailure() { + return notifyFailure; + } + + @Exported + public boolean getNotifyNotBuilt() { + return notifyNotBuilt; + } + + @Exported + public boolean getNotifyUnstable() { + return notifyUnstable; + } + + @Exported + public boolean getNotifyBackToNormal() { + return notifyBackToNormal; + } + + @Exported + public boolean includeTestSummary() { + return includeTestSummary; + } + + @Exported + public boolean getNotifyRepeatedFailure() { + return notifyRepeatedFailure; + } + + @Exported + public boolean includeCustomMessage() { + return includeCustomMessage; + } + + @Exported + public String getCustomMessage() { + return customMessage; + } + + } + + @Extension public static final class Migrator extends ItemListener { + @SuppressWarnings("deprecation") + @Override + public void onLoaded() { + logger.info("Starting Settings Migration Process"); + for (AbstractProject p : Jenkins.getInstance().getAllItems(AbstractProject.class)) { + logger.info("processing Job: " + p.getName()); + + final SlackJobProperty slackJobProperty = p.getProperty(SlackJobProperty.class); + + if(slackJobProperty == null) { + logger.info("Configuration is already uptodate, exiting migration"); + return; + } + + SlackNotifier slackNotifier = p.getPublishersList().get(SlackNotifier.class); + + //map settings + slackNotifier.teamDomain = slackJobProperty.getTeamDomain(); + slackNotifier.authToken = slackJobProperty.getToken(); + slackNotifier.room = slackJobProperty.getRoom(); + slackNotifier.startNotification = slackJobProperty.getStartNotification(); + + slackNotifier.notifyAborted = slackJobProperty.getNotifyAborted(); + slackNotifier.notifyFailure = slackJobProperty.getNotifyFailure(); + slackNotifier.notifyNotBuilt = slackJobProperty.getNotifyNotBuilt(); + slackNotifier.notifySuccess = slackJobProperty.getNotifySuccess(); + slackNotifier.notifyUnstable = slackJobProperty.getNotifyUnstable(); + slackNotifier.notifyBackToNormal = slackJobProperty.getNotifyBackToNormal(); + slackNotifier.notifyRepeatedFailure = slackJobProperty.getNotifyRepeatedFailure(); + + slackNotifier.includeTestSummary = slackJobProperty.includeTestSummary(); + slackNotifier.commitInfoChoice = slackJobProperty.getShowCommitList() ? CommitInfoChoice.AUTHORS_AND_TITLES : CommitInfoChoice.NONE; + slackNotifier.includeCustomMessage = slackJobProperty.includeCustomMessage(); + slackNotifier.customMessage = slackJobProperty.getCustomMessage(); + + try { + //property section is not used anymore - remove + p.removeProperty(SlackJobProperty.class); + p.save(); + logger.info("Configuration updated successfully"); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } } From af8e4ebd2a653d719e107487ce32332b4472e3c2 Mon Sep 17 00:00:00 2001 From: Sergiy Kopchalyuk Date: Mon, 23 Nov 2015 20:27:24 +0100 Subject: [PATCH 2/3] logged IOException --- .../java/jenkins/plugins/slack/SlackNotifier.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/jenkins/plugins/slack/SlackNotifier.java b/src/main/java/jenkins/plugins/slack/SlackNotifier.java index 1010aed2..781f38d0 100755 --- a/src/main/java/jenkins/plugins/slack/SlackNotifier.java +++ b/src/main/java/jenkins/plugins/slack/SlackNotifier.java @@ -1,7 +1,12 @@ package jenkins.plugins.slack; -import hudson.*; -import hudson.model.*; +import hudson.EnvVars; +import hudson.Extension; +import hudson.Launcher; +import hudson.model.AbstractBuild; +import hudson.model.AbstractProject; +import hudson.model.BuildListener; +import hudson.model.Descriptor; import hudson.model.listeners.ItemListener; import hudson.tasks.BuildStepDescriptor; import hudson.tasks.BuildStepMonitor; @@ -19,6 +24,7 @@ import java.io.IOException; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; public class SlackNotifier extends Notifier { @@ -500,7 +506,7 @@ public void onLoaded() { p.save(); logger.info("Configuration updated successfully"); } catch (IOException e) { - e.printStackTrace(); + logger.log(Level.SEVERE, e.getMessage(), e); } } } From a18c6f5381aa30611ea5ede2b86d93be03f8a621 Mon Sep 17 00:00:00 2001 From: Owen Berry Date: Mon, 7 Dec 2015 18:16:18 -0500 Subject: [PATCH 3/3] [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 --- .../jenkins/plugins/slack/SlackNotifier.java | 60 +++--- ...wordsCompatible_1_8_SlackNotifierTest.java | 180 ++++++++++++++++++ .../testBasicMigration/config.xml | 3 + .../jobs/Test_Slack_Plugin/config.xml | 46 +++++ .../config.xml | 3 + .../jenkins.plugins.slack.SlackNotifier.xml | 7 + .../jobs/Test_Slack_Plugin/config.xml | 46 +++++ .../testGlobalSettingsOverriden/config.xml | 3 + .../jenkins.plugins.slack.SlackNotifier.xml | 7 + .../jobs/Test_Slack_Plugin/config.xml | 46 +++++ .../testMigrationFromNoPlugin/config.xml | 3 + .../jobs/Test_01/config.xml | 25 +++ .../jobs/Test_02/config.xml | 32 ++++ .../jobs/Test_02/nextBuildNumber | 1 + .../jobs/Test_03/config.xml | 35 ++++ .../testMigrationOfSomeJobs/config.xml | 3 + .../jenkins.plugins.slack.SlackNotifier.xml | 7 + .../jobs/Test_01/config.xml | 25 +++ .../jobs/Test_02/config.xml | 55 ++++++ .../jobs/Test_03/config.xml | 35 ++++ .../testMigrationWithNoNotifier/config.xml | 3 + .../jobs/Test_01/config.xml | 43 +++++ 22 files changed, 646 insertions(+), 22 deletions(-) create mode 100644 src/test/java/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest.java create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/jobs/Test_Slack_Plugin/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jenkins.plugins.slack.SlackNotifier.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jobs/Test_Slack_Plugin/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jenkins.plugins.slack.SlackNotifier.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jobs/Test_Slack_Plugin/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_01/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/nextBuildNumber create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_03/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jenkins.plugins.slack.SlackNotifier.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_01/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_02/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_03/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/config.xml create mode 100644 src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/jobs/Test_01/config.xml diff --git a/src/main/java/jenkins/plugins/slack/SlackNotifier.java b/src/main/java/jenkins/plugins/slack/SlackNotifier.java index 781f38d0..a9628b31 100755 --- a/src/main/java/jenkins/plugins/slack/SlackNotifier.java +++ b/src/main/java/jenkins/plugins/slack/SlackNotifier.java @@ -474,31 +474,47 @@ public void onLoaded() { final SlackJobProperty slackJobProperty = p.getProperty(SlackJobProperty.class); - if(slackJobProperty == null) { - logger.info("Configuration is already uptodate, exiting migration"); - return; + if (slackJobProperty == null) { + logger.info(String + .format("Configuration is already up to date for \"%s\", skipping migration", + p.getName())); + continue; } SlackNotifier slackNotifier = p.getPublishersList().get(SlackNotifier.class); - - //map settings - slackNotifier.teamDomain = slackJobProperty.getTeamDomain(); - slackNotifier.authToken = slackJobProperty.getToken(); - slackNotifier.room = slackJobProperty.getRoom(); - slackNotifier.startNotification = slackJobProperty.getStartNotification(); - - slackNotifier.notifyAborted = slackJobProperty.getNotifyAborted(); - slackNotifier.notifyFailure = slackJobProperty.getNotifyFailure(); - slackNotifier.notifyNotBuilt = slackJobProperty.getNotifyNotBuilt(); - slackNotifier.notifySuccess = slackJobProperty.getNotifySuccess(); - slackNotifier.notifyUnstable = slackJobProperty.getNotifyUnstable(); - slackNotifier.notifyBackToNormal = slackJobProperty.getNotifyBackToNormal(); - slackNotifier.notifyRepeatedFailure = slackJobProperty.getNotifyRepeatedFailure(); - - slackNotifier.includeTestSummary = slackJobProperty.includeTestSummary(); - slackNotifier.commitInfoChoice = slackJobProperty.getShowCommitList() ? CommitInfoChoice.AUTHORS_AND_TITLES : CommitInfoChoice.NONE; - slackNotifier.includeCustomMessage = slackJobProperty.includeCustomMessage(); - slackNotifier.customMessage = slackJobProperty.getCustomMessage(); + + if (slackNotifier == null) { + logger.info(String + .format("Configuration does not have a notifier for \"%s\", not migrating settings", + p.getName())); + } else { + + //map settings + if (StringUtils.isBlank(slackNotifier.teamDomain)) { + slackNotifier.teamDomain = slackJobProperty.getTeamDomain(); + } + if (StringUtils.isBlank(slackNotifier.authToken)) { + slackNotifier.authToken = slackJobProperty.getToken(); + } + if (StringUtils.isBlank(slackNotifier.room)) { + slackNotifier.room = slackJobProperty.getRoom(); + } + + slackNotifier.startNotification = slackJobProperty.getStartNotification(); + + slackNotifier.notifyAborted = slackJobProperty.getNotifyAborted(); + slackNotifier.notifyFailure = slackJobProperty.getNotifyFailure(); + slackNotifier.notifyNotBuilt = slackJobProperty.getNotifyNotBuilt(); + slackNotifier.notifySuccess = slackJobProperty.getNotifySuccess(); + slackNotifier.notifyUnstable = slackJobProperty.getNotifyUnstable(); + slackNotifier.notifyBackToNormal = slackJobProperty.getNotifyBackToNormal(); + slackNotifier.notifyRepeatedFailure = slackJobProperty.getNotifyRepeatedFailure(); + + slackNotifier.includeTestSummary = slackJobProperty.includeTestSummary(); + slackNotifier.commitInfoChoice = slackJobProperty.getShowCommitList() ? CommitInfoChoice.AUTHORS_AND_TITLES : CommitInfoChoice.NONE; + slackNotifier.includeCustomMessage = slackJobProperty.includeCustomMessage(); + slackNotifier.customMessage = slackJobProperty.getCustomMessage(); + } try { //property section is not used anymore - remove diff --git a/src/test/java/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest.java b/src/test/java/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest.java new file mode 100644 index 00000000..d2fc9865 --- /dev/null +++ b/src/test/java/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest.java @@ -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)); + } +} diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/config.xml new file mode 100644 index 00000000..1420198b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/config.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/jobs/Test_Slack_Plugin/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/jobs/Test_Slack_Plugin/config.xml new file mode 100644 index 00000000..b5c573f8 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testBasicMigration/jobs/Test_Slack_Plugin/config.xml @@ -0,0 +1,46 @@ + + + + + false + + + + + + false + true + false + false + false + true + false + false + false + false + false + + + + + true + false + false + false + + false + + + echo "Hello World" + + + + + jenkins-slack-plugin + auth-token-for-test + http://localhost:8080/ + #slack-plugin-testing + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/config.xml new file mode 100644 index 00000000..1420198b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/config.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jenkins.plugins.slack.SlackNotifier.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jenkins.plugins.slack.SlackNotifier.xml new file mode 100644 index 00000000..b6c48a40 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jenkins.plugins.slack.SlackNotifier.xml @@ -0,0 +1,7 @@ + + + jenkins-slack-plugin-global + auth-token-for-test-global + #slack-plugin-testing-global + http://localhost:8080/global/ + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jobs/Test_Slack_Plugin/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jobs/Test_Slack_Plugin/config.xml new file mode 100644 index 00000000..73edbacb --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsNotOverridden/jobs/Test_Slack_Plugin/config.xml @@ -0,0 +1,46 @@ + + + + + false + + + + + + false + true + false + false + false + true + false + false + false + false + false + + + + + true + false + false + false + + false + + + echo "Hello World" + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/config.xml new file mode 100644 index 00000000..1420198b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/config.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jenkins.plugins.slack.SlackNotifier.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jenkins.plugins.slack.SlackNotifier.xml new file mode 100644 index 00000000..b6c48a40 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jenkins.plugins.slack.SlackNotifier.xml @@ -0,0 +1,7 @@ + + + jenkins-slack-plugin-global + auth-token-for-test-global + #slack-plugin-testing-global + http://localhost:8080/global/ + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jobs/Test_Slack_Plugin/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jobs/Test_Slack_Plugin/config.xml new file mode 100644 index 00000000..b5c573f8 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testGlobalSettingsOverriden/jobs/Test_Slack_Plugin/config.xml @@ -0,0 +1,46 @@ + + + + + false + + + + + + false + true + false + false + false + true + false + false + false + false + false + + + + + true + false + false + false + + false + + + echo "Hello World" + + + + + jenkins-slack-plugin + auth-token-for-test + http://localhost:8080/ + #slack-plugin-testing + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/config.xml new file mode 100644 index 00000000..1420198b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/config.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_01/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_01/config.xml new file mode 100644 index 00000000..8133821d --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_01/config.xml @@ -0,0 +1,25 @@ + + + + + false + + + true + false + false + false + + + H * * * * + + + false + + + echo "Test" + + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/config.xml new file mode 100644 index 00000000..78911423 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/config.xml @@ -0,0 +1,32 @@ + + + + + false + + + true + false + false + false + + + + Test_01 + + SUCCESS + 0 + BLUE + true + + + + false + + + echo "Test" + + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/nextBuildNumber b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/nextBuildNumber new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_02/nextBuildNumber @@ -0,0 +1 @@ +1 diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_03/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_03/config.xml new file mode 100644 index 00000000..afa7de3b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationFromNoPlugin/jobs/Test_03/config.xml @@ -0,0 +1,35 @@ + + + + + false + + + true + false + false + false + + false + + + + echo "Test" + + + + + Test_02 + + UNSTABLE + 1 + YELLOW + true + + + + + + false + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/config.xml new file mode 100644 index 00000000..1420198b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/config.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jenkins.plugins.slack.SlackNotifier.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jenkins.plugins.slack.SlackNotifier.xml new file mode 100644 index 00000000..b6c48a40 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jenkins.plugins.slack.SlackNotifier.xml @@ -0,0 +1,7 @@ + + + jenkins-slack-plugin-global + auth-token-for-test-global + #slack-plugin-testing-global + http://localhost:8080/global/ + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_01/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_01/config.xml new file mode 100644 index 00000000..8133821d --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_01/config.xml @@ -0,0 +1,25 @@ + + + + + false + + + true + false + false + false + + + H * * * * + + + false + + + echo "Test" + + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_02/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_02/config.xml new file mode 100644 index 00000000..40ff1817 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_02/config.xml @@ -0,0 +1,55 @@ + + + + + false + + + + + + true + true + true + true + true + true + true + true + true + true + true + Custom message for 1.8 plugin. + + + + true + false + false + false + + + + Test_01 + + SUCCESS + 0 + BLUE + true + + + + false + + + echo "Test" + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_03/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_03/config.xml new file mode 100644 index 00000000..afa7de3b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationOfSomeJobs/jobs/Test_03/config.xml @@ -0,0 +1,35 @@ + + + + + false + + + true + false + false + false + + false + + + + echo "Test" + + + + + Test_02 + + UNSTABLE + 1 + YELLOW + true + + + + + + false + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/config.xml new file mode 100644 index 00000000..1420198b --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/config.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/jobs/Test_01/config.xml b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/jobs/Test_01/config.xml new file mode 100644 index 00000000..477394d2 --- /dev/null +++ b/src/test/resources/jenkins/plugins/slack/config/BackwordsCompatible_1_8_SlackNotifierTest/testMigrationWithNoNotifier/jobs/Test_01/config.xml @@ -0,0 +1,43 @@ + + + + + false + + + + + + false + false + false + false + false + false + false + false + false + false + false + + + + + true + false + false + false + + + H * * * * + + + false + + + echo "Test" + + + + + \ No newline at end of file