Skip to content

Commit

Permalink
Add testTopicAssociationSetAfterJenkinsRestart
Browse files Browse the repository at this point in the history
  • Loading branch information
dev committed Feb 26, 2023
1 parent 74d5826 commit 6ff92cd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,6 @@ public void setSilentMode(boolean silentMode) {
* @param enable true or false.
*/
@Deprecated
@DataBoundSetter
public void setEnableTopicAssociation(boolean enable) {
if (enable) {
topicAssociation = new TopicAssociation();
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 6ff92cd

Please sign in to comment.