Skip to content

Commit

Permalink
Merge pull request #484 from ckreisl/fix-topic-association-not-set-af…
Browse files Browse the repository at this point in the history
…ter-jenkins-restart

[JENKINS-70558] Fix TopicAssociation not set after Jenkins restart
  • Loading branch information
rsandell authored Mar 3, 2023
2 parents 2b7cf8c + 6ff92cd commit 27d6cdc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,32 @@

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.
* @author Christoph Kreisl
*/
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.
*
Expand Down Expand Up @@ -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());
});
}
}

0 comments on commit 27d6cdc

Please sign in to comment.