diff --git a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java index e002dd056..ef4947c3e 100644 --- a/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java +++ b/src/main/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/GerritTrigger.java @@ -1949,6 +1949,7 @@ public void setSilentMode(boolean silentMode) { /** * Enable or disable Topic Association option. + * Replaced by {@link #setTopicAssociation(TopicAssociation)} () * * @param enable true or false. */ @@ -2232,11 +2233,8 @@ public Object readResolve() throws ObjectStreamException { if (projectListIsReady == null) { projectListIsReady = new CountDownLatch(0); } - - if (enableTopicAssociation) { + if (topicAssociation == null && enableTopicAssociation) { topicAssociation = new TopicAssociation(); - } else { - topicAssociation = null; } return super.readResolve(); diff --git a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/data/TopicAssociationTest.java b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/data/TopicAssociationTest.java index f8a9910c1..d66de7915 100644 --- a/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/data/TopicAssociationTest.java +++ b/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/hudsontrigger/data/TopicAssociationTest.java @@ -24,12 +24,18 @@ package com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.data; +import com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger; +import com.sonyericsson.hudson.plugins.gerrit.trigger.mock.Setup; import com.sonymobile.tools.gerrit.gerritevents.dto.GerritChangeStatus; import com.sonymobile.tools.gerrit.gerritevents.dto.attr.Change; +import hudson.model.FreeStyleProject; +import org.junit.Rule; import org.junit.Test; +import org.jvnet.hudson.test.JenkinsSessionRule; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; /** * Tests the TopicAssociation method. @@ -37,6 +43,13 @@ */ public class TopicAssociationTest { + + /** + * Jenkins Session Rule for testing. + */ + //CS IGNORE VisibilityModifier FOR NEXT 1 LINES. REASON: JenkinsSessionRule must be public. + @Rule public JenkinsSessionRule session = new JenkinsSessionRule(); + /** * Create a custom change for testing. * @@ -75,4 +88,32 @@ public void testIsInterestingChange() { assertFalse(topicAssociation.isInterestingChangeStatus(c)); } + /** + * Test TopicAssociation field set after Jenkins restart. + * + * @throws Throwable on failure + */ + @Test + public void testTopicAssociationSetAfterRestart() throws Throwable { + session.then(j -> { + FreeStyleProject foo = j.createFreeStyleProject("foo"); + GerritTrigger trigger = Setup.createDefaultTrigger(foo); + TopicAssociation ta = new TopicAssociation(); + ta.setIgnoreMergedChangeStatus(true); + ta.setIgnoreAbandonedChangeStatus(true); + trigger.setTopicAssociation(ta); + foo.save(); + }); + + session.then(j -> { + FreeStyleProject foo = j.jenkins.getItemByFullName("foo", FreeStyleProject.class); + assertNotNull(foo); + GerritTrigger trigger = foo.getTrigger(GerritTrigger.class); + TopicAssociation ta = trigger.getTopicAssociation(); + assertNotNull(ta); + assertFalse(ta.isIgnoreNewChangeStatus()); + assertTrue(ta.isIgnoreMergedChangeStatus()); + assertTrue(ta.isIgnoreAbandonedChangeStatus()); + }); + } }