diff --git a/pom.xml b/pom.xml index 495376ed..55a26fc8 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins plugin - 2.17 + 2.29 promoted-builds @@ -12,10 +12,10 @@ hpi Jenkins promoted builds plugin - http://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin + https://wiki.jenkins-ci.org/display/JENKINS/Promoted+Builds+Plugin - 1.565 + 1.609.3 6 @@ -48,34 +48,15 @@ - - - jenkins-releases - http://repo.jenkins-ci.org/releases/ - - true - - - false - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - true - - - false - + https://repo.jenkins-ci.org/public/ - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ + https://repo.jenkins-ci.org/public/ @@ -83,7 +64,7 @@ org.jenkins-ci.main maven-plugin - 2.0 + 2.13 com.sonyericsson.hudson.plugins.rebuild @@ -106,7 +87,7 @@ org.jenkins-ci.plugins token-macro - 1.10 + 1.12.1 true @@ -124,7 +105,7 @@ org.jenkins-ci.plugins script-security - 1.16 + 1.26 org.jvnet.hudson @@ -135,19 +116,19 @@ org.jenkins-ci.plugins parameterized-trigger - 2.30 + 2.33 test org.jenkins-ci.plugins matrix-auth - 1.0 + 1.6 test org.jenkins-ci.plugins matrix-project - 1.0 + 1.11 test diff --git a/src/main/java/hudson/plugins/promoted_builds/JobPropertyImpl.java b/src/main/java/hudson/plugins/promoted_builds/JobPropertyImpl.java index f3ac59d2..5413d0ce 100644 --- a/src/main/java/hudson/plugins/promoted_builds/JobPropertyImpl.java +++ b/src/main/java/hudson/plugins/promoted_builds/JobPropertyImpl.java @@ -12,6 +12,7 @@ import java.util.logging.Level; import java.util.logging.Logger; +import jenkins.security.MasterToSlaveCallable; import org.apache.commons.lang.StringUtils; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; @@ -35,7 +36,6 @@ import hudson.model.JobProperty; import hudson.model.JobPropertyDescriptor; import hudson.model.listeners.ItemListener; -import hudson.remoting.Callable; import hudson.util.IOUtils; import javax.annotation.CheckForNull; import jenkins.model.Jenkins; @@ -305,7 +305,7 @@ public PromotionProcess createProcessFromXml(final String name, InputStream xml) } try { IOUtils.copy(xml, configXml); - PromotionProcess result = Items.whileUpdatingByXml(new Callable() { + PromotionProcess result = Items.whileUpdatingByXml(new MasterToSlaveCallable() { @Override public PromotionProcess call() throws IOException { setOwner(owner); return getItem(name); diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java index a910b3b9..9cd12411 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java @@ -4,19 +4,29 @@ import hudson.model.FreeStyleProject; import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition; import hudson.tasks.JavadocArchiver; -import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; + +import static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; /** * @author Seiji Sogabe */ -public class ConfigurationDoCheckTest extends HudsonTestCase { +public class ConfigurationDoCheckTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); - @Bug(7972) + @Issue("JENKINS-7972") + @Test public void testCheckProcessNameRequired() throws Exception { - FreeStyleProject down = createFreeStyleProject(); + FreeStyleProject down = j.createFreeStyleProject(); - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); JobPropertyImpl pp = new JobPropertyImpl(p); p.addProperty(pp); @@ -26,18 +36,20 @@ public void testCheckProcessNameRequired() throws Exception { proc.getBuildSteps().add(new JavadocArchiver("somedir",true)); proc.icon = "star-blue"; - WebClient client = new WebClient(); + JenkinsRule.WebClient client = j.createWebClient(); client.getOptions().setThrowExceptionOnFailingStatusCode(false); - HtmlPage page = submit(client.getPage(p, "configure").getFormByName("config")); + + HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config")); assertTrue(page.asText().contains("No name is specified")); } - @Bug(7972) + @Issue("JENKINS-7972") + @Test public void testCheckInvalidProcessName() throws Exception { - FreeStyleProject down = createFreeStyleProject(); + FreeStyleProject down = j.createFreeStyleProject(); - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); JobPropertyImpl pp = new JobPropertyImpl(p); p.addProperty(pp); @@ -47,9 +59,10 @@ public void testCheckInvalidProcessName() throws Exception { proc.getBuildSteps().add(new JavadocArchiver("somedir",true)); proc.icon = "star-blue"; - WebClient client = new WebClient(); + JenkinsRule.WebClient client = j.createWebClient(); client.getOptions().setThrowExceptionOnFailingStatusCode(false); - HtmlPage page = submit(client.getPage(p, "configure").getFormByName("config")); + + HtmlPage page = (HtmlPage) submit(client.getPage(p, "configure").getFormByName("config")); assertTrue(page.asText().contains("unsafe character")); } diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java index 30d14fd6..51d8c4eb 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java @@ -26,21 +26,33 @@ import hudson.model.FreeStyleProject; import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition; import hudson.tasks.JavadocArchiver; -import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.recipes.LocalData; +import static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + /** * @author Kohsuke Kawaguchi */ -public class ConfigurationRoundtripTest extends HudsonTestCase { +public class ConfigurationRoundtripTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + /** * Configuration roundtrip test to detect data loss. */ + @Test public void testRoundtrip() throws Exception { - FreeStyleProject down = createFreeStyleProject(); + FreeStyleProject down = j.createFreeStyleProject(); - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); JobPropertyImpl pp = new JobPropertyImpl(p); p.addProperty(pp); @@ -51,7 +63,8 @@ public void testRoundtrip() throws Exception { proc.icon = "star-blue"; // round trip - submit(new WebClient().getPage(p,"configure").getFormByName("config")); + JenkinsRule.WebClient wc = j.createWebClient(); + submit(wc.getPage(p,"configure").getFormByName("config")); // assert that the configuration is still intact pp = p.getProperty(JobPropertyImpl.class); @@ -68,11 +81,12 @@ public void testRoundtrip() throws Exception { } @LocalData - @Bug(17341) + @Issue("JENKINS-17341") + @Test public void testLoad() throws Exception { - FreeStyleProject j = jenkins.getItemByFullName("j", FreeStyleProject.class); - assertNotNull(j); - Promotion p = j.getProperty(JobPropertyImpl.class).getItem("OK").getBuildByNumber(1); + FreeStyleProject jProj = j.jenkins.getItemByFullName("j", FreeStyleProject.class); + assertNotNull(jProj); + Promotion p = jProj.getProperty(JobPropertyImpl.class).getItem("OK").getBuildByNumber(1); assertNotNull(p); } diff --git a/src/test/java/hudson/plugins/promoted_builds/KeepBuildForeverActionTest.java b/src/test/java/hudson/plugins/promoted_builds/KeepBuildForeverActionTest.java index 7c293ee6..84b7d93b 100644 --- a/src/test/java/hudson/plugins/promoted_builds/KeepBuildForeverActionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/KeepBuildForeverActionTest.java @@ -14,7 +14,9 @@ import hudson.tasks.ArtifactArchiver; import hudson.tasks.Fingerprinter; import hudson.tasks.Recorder; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.TestBuilder; import java.io.IOException; @@ -22,9 +24,16 @@ import java.util.List; import static hudson.plugins.promoted_builds.util.ItemListenerHelper.fireItemListeners; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; -public class KeepBuildForeverActionTest extends HudsonTestCase { - +public class KeepBuildForeverActionTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Test public void testCanMarkBuildKeepForever() throws Exception { FreeStyleProject upJob = createProject("up"); upJob.getBuildersList().add(successfulBuilder()); @@ -37,14 +46,15 @@ public void testCanMarkBuildKeepForever() throws Exception { // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+ fireItemListeners(); - FreeStyleBuild upBuild = assertBuildStatusSuccess(upJob.scheduleBuild2(0).get()); + FreeStyleBuild upBuild = j.assertBuildStatusSuccess(upJob.scheduleBuild2(0).get()); assertFalse(upBuild.isKeepLog()); - assertBuildStatusSuccess(downJob.scheduleBuild2(0).get()); + j.assertBuildStatusSuccess(downJob.scheduleBuild2(0).get()); waitForBuild(promotionJob, 1); assertTrue(upBuild.isKeepLog()); } - + + @Test public void testDoesNotMarkBuildIfPromotionNotGoodEnough() throws Exception { FreeStyleProject upJob = createProject("up"); upJob.getBuildersList().add(successfulBuilder()); @@ -58,14 +68,15 @@ public void testDoesNotMarkBuildIfPromotionNotGoodEnough() throws Exception { // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+ fireItemListeners(); - FreeStyleBuild upBuild = assertBuildStatusSuccess(upJob.scheduleBuild2(0).get()); + FreeStyleBuild upBuild = j.assertBuildStatusSuccess(upJob.scheduleBuild2(0).get()); assertFalse(upBuild.isKeepLog()); - assertBuildStatusSuccess(downJob.scheduleBuild2(0).get()); + j.assertBuildStatusSuccess(downJob.scheduleBuild2(0).get()); waitForBuild(promotionJob, 1); assertFalse(upBuild.isKeepLog()); } + @Test public void testDoesNotCareAboutResultOfOriginalBuild() throws Exception { FreeStyleProject upJob = createProject("up"); upJob.getBuildersList().add(new FixedResultBuilder(Result.FAILURE)); @@ -78,14 +89,15 @@ public void testDoesNotCareAboutResultOfOriginalBuild() throws Exception { // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+ fireItemListeners(); - FreeStyleBuild upBuild = assertBuildStatus(Result.FAILURE, upJob.scheduleBuild2(0).get()); + FreeStyleBuild upBuild = j.assertBuildStatus(Result.FAILURE, upJob.scheduleBuild2(0).get()); assertFalse(upBuild.isKeepLog()); - assertBuildStatusSuccess(downJob.scheduleBuild2(0).get()); + j.assertBuildStatusSuccess(downJob.scheduleBuild2(0).get()); waitForBuild(promotionJob, 1); assertTrue(upBuild.isKeepLog()); } + @Test public void testDoesNotMarkBuildIfBuildNotPromotion() throws Exception { FreeStyleProject job = createProject("job"); job.getBuildersList().add(successfulBuilder()); @@ -94,7 +106,7 @@ public void testDoesNotMarkBuildIfBuildNotPromotion() throws Exception { // fire ItemListeners, this includes ArtifactArchiver,Migrator to make this test compatible with jenkins 1.575+ fireItemListeners(); - FreeStyleBuild build = assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); + FreeStyleBuild build = j.assertBuildStatus(Result.FAILURE, job.scheduleBuild2(0).get()); assertFalse(build.isKeepLog()); } @@ -135,16 +147,15 @@ private PromotionProcess createDownstreamSuccessPromotion(FreeStyleProject upStr } private FreeStyleProject createProject(String name) throws Exception { - FreeStyleProject project = createFreeStyleProject(name); + FreeStyleProject project = j.createFreeStyleProject(name); project.getPublishersList().replaceBy(createFingerprinters()); return project; } private List createFingerprinters() { - return Arrays.asList( - new ArtifactArchiver("*", null, false), - new Fingerprinter("", true) - ); + Recorder r1 = new ArtifactArchiver("*", null, false); + Recorder r2 = new Fingerprinter("", true); + return Arrays.asList(r1, r2); } private FixedResultBuilder successfulBuilder() { diff --git a/src/test/java/hudson/plugins/promoted_builds/PromotedBuildActionTest.java b/src/test/java/hudson/plugins/promoted_builds/PromotedBuildActionTest.java index 0f39a6c1..adb19d51 100644 --- a/src/test/java/hudson/plugins/promoted_builds/PromotedBuildActionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/PromotedBuildActionTest.java @@ -6,23 +6,32 @@ import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.util.IOException2; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; import java.io.IOException; import java.util.List; +import static org.junit.Assert.assertTrue; + /** * @author Kohsuke Kawaguchi */ -public class PromotedBuildActionTest extends HudsonTestCase { +public class PromotedBuildActionTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Test public void testDeletedPromotionProcess() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); JobPropertyImpl base = new JobPropertyImpl(p); p.addProperty(base); PromotionProcess foo = base.addProcess("foo"); // promote a build - FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0)); + FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); foo.promote(b1,new UserCause(),new ManualPromotionBadge()); // now delete the promotion process @@ -31,7 +40,7 @@ public void testDeletedPromotionProcess() throws Exception { assertTrue(base.getActiveItems().isEmpty()); // make sure that the page renders OK without any error - HtmlPage page = createWebClient().getPage(p); + HtmlPage page = j.createWebClient().getPage(p); List candidates = page.getByXPath("//IMG"); for (Object candidate : candidates) { if (!(candidate instanceof HtmlImage)) { diff --git a/src/test/java/hudson/plugins/promoted_builds/PromotionProcessTest.java b/src/test/java/hudson/plugins/promoted_builds/PromotionProcessTest.java index a3e620d6..956284bb 100644 --- a/src/test/java/hudson/plugins/promoted_builds/PromotionProcessTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/PromotionProcessTest.java @@ -15,7 +15,9 @@ import hudson.tasks.Shell; import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition; import net.sf.json.JSONObject; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; import org.kohsuke.stapler.Stapler; import java.util.ArrayList; @@ -24,18 +26,24 @@ import java.util.concurrent.Callable; import static hudson.plugins.promoted_builds.util.ItemListenerHelper.fireItemListeners; +import static org.junit.Assert.*; /** * @author Kohsuke Kawaguchi */ -public class PromotionProcessTest extends HudsonTestCase { +public class PromotionProcessTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Test public void test1() throws Exception { - FreeStyleProject up = createFreeStyleProject("up"); - FreeStyleProject down = createFreeStyleProject(); + FreeStyleProject up = j.createFreeStyleProject("up"); + FreeStyleProject down = j.createFreeStyleProject(); - List recorders = Arrays.asList( - new ArtifactArchiver("a.jar", null, false), - new Fingerprinter("", true)); + Recorder r1 = new ArtifactArchiver("a.jar", null, false); + Recorder r2 = new Fingerprinter("", true); + List recorders = Arrays.asList(r1, r2); // upstream job up.getBuildersList().add(new Shell("date > a.jar")); @@ -48,7 +56,7 @@ public void test1() throws Exception { proc.conditions.add(new DownstreamPassCondition(down.getName())); // this is the test job - String baseUrl = new WebClient().getContextPath() + "job/up/lastSuccessfulBuild"; + String baseUrl = j.createWebClient().getContextPath() + "job/up/lastSuccessfulBuild"; down.getBuildersList().add(new Shell( "wget -N "+baseUrl+"/artifact/a.jar \\\n"+ " || curl "+baseUrl+"/artifact/a.jar > a.jar\n"+ @@ -60,13 +68,13 @@ public void test1() throws Exception { fireItemListeners(); // not yet promoted while the downstream is failing - FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get()); - assertBuildStatus(Result.FAILURE,down.scheduleBuild2(0).get()); + FreeStyleBuild up1 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get()); + j.assertBuildStatus(Result.FAILURE,down.scheduleBuild2(0).get()); Thread.sleep(1000); // give it a time to not promote assertEquals(0,proc.getBuilds().size()); // a successful downstream build promotes upstream - assertBuildStatusSuccess(down.scheduleBuild2(0).get()); + j.assertBuildStatusSuccess(down.scheduleBuild2(0).get()); Thread.sleep(1000); // give it a time to promote assertEquals(1,proc.getBuilds().size()); @@ -78,16 +86,16 @@ public void test1() throws Exception { } // make sure the UI persists the setup - configRoundtrip(up); - + j.configRoundtrip(up); } /** * Tests a promotion induced by the pseudo upstream/downstream cause relationship */ + @Test public void testPromotionWithoutFingerprint() throws Exception { - FreeStyleProject up = createFreeStyleProject("up"); - FreeStyleProject down = createFreeStyleProject(); + FreeStyleProject up = j.createFreeStyleProject("up"); + FreeStyleProject down = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(up); @@ -97,7 +105,7 @@ public void testPromotionWithoutFingerprint() throws Exception { // trigger downstream automatically to create relationship up.getPublishersList().add(new BuildTrigger(down.getName(), Result.SUCCESS)); - hudson.rebuildDependencyGraph(); + j.jenkins.rebuildDependencyGraph(); // this is the downstream job down.getBuildersList().add(new Shell( @@ -105,12 +113,12 @@ public void testPromotionWithoutFingerprint() throws Exception { )); // not yet promoted while the downstream is failing - FreeStyleBuild up1 = assertBuildStatusSuccess(up.scheduleBuild2(0).get()); + FreeStyleBuild up1 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get()); waitForCompletion(down,1); assertEquals(0,proc.getBuilds().size()); // do it one more time and this time it should work - FreeStyleBuild up2 = assertBuildStatusSuccess(up.scheduleBuild2(0).get()); + FreeStyleBuild up2 = j.assertBuildStatusSuccess(up.scheduleBuild2(0).get()); waitForCompletion(down,2); assertEquals(1,proc.getBuilds().size()); @@ -126,12 +134,13 @@ private void waitForCompletion(FreeStyleProject down, int n) throws Exception { // wait for the build completion while (down.getBuildByNumber(n)==null) Thread.sleep(100); - waitUntilNoActivity(); + j.waitUntilNoActivity(); assertFalse(down.getBuildByNumber(n).isBuilding()); } + @Test public void testCaptureXml() throws Exception { - executeOnServer(new Callable() { + j.executeOnServer(new Callable() { public Object call() throws Exception { JSONObject o = new JSONObject() .accumulate("name", "foo") @@ -150,32 +159,39 @@ public Object call() throws Exception { } }); } - + + @Test public void testIsVisibleByDefault() throws Exception { - FreeStyleProject project = createFreeStyleProject("project"); + FreeStyleProject project = j.createFreeStyleProject("project"); JobPropertyImpl jobProperty = new JobPropertyImpl(project); project.addProperty(jobProperty); PromotionProcess promotionProcess = jobProperty.addProcess( "Promotion"); assertTrue(promotionProcess.isVisible()); } + + @Test public void testIsVisibleFalseReturnsNotVisible() throws Exception{ - FreeStyleProject project = createFreeStyleProject("project"); + FreeStyleProject project = j.createFreeStyleProject("project"); JobPropertyImpl jobProperty = new JobPropertyImpl(project); project.addProperty(jobProperty); PromotionProcess promotionProcess = jobProperty.addProcess( "Promotion"); promotionProcess.isVisible = "false"; assertFalse(promotionProcess.isVisible()); } + + @Test public void testIsVisibleTrueReturnsVisible() throws Exception{ - FreeStyleProject project = createFreeStyleProject("project"); + FreeStyleProject project = j.createFreeStyleProject("project"); JobPropertyImpl jobProperty = new JobPropertyImpl(project); project.addProperty(jobProperty); PromotionProcess promotionProcess = jobProperty.addProcess( "Promotion"); promotionProcess.isVisible = "true"; assertTrue(promotionProcess.isVisible()); } + + @Test public void testIsVisibleResolvesDefaultParameterValue() throws Exception{ - FreeStyleProject project = createFreeStyleProject("project"); + FreeStyleProject project = j.createFreeStyleProject("project"); final List parameters = new ArrayList(); ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters); parameters.add(new StringParameterDefinition("Visibility", "false")); @@ -186,8 +202,10 @@ public void testIsVisibleResolvesDefaultParameterValue() throws Exception{ promotionProcess.isVisible = "${Visibility}"; assertFalse(promotionProcess.isVisible()); } + + @Test public void testIsVisibleResolvesDefaultParameterValueIndirectly() throws Exception{ - FreeStyleProject project = createFreeStyleProject("project"); + FreeStyleProject project = j.createFreeStyleProject("project"); final List parameters = new ArrayList(); ParametersDefinitionProperty parametersProperty = new ParametersDefinitionProperty(parameters); parameters.add(new StringParameterDefinition("IndirectVisibility", "false")); diff --git a/src/test/java/hudson/plugins/promoted_builds/PromotionTargetActionTest.java b/src/test/java/hudson/plugins/promoted_builds/PromotionTargetActionTest.java index e8c7e22f..c657017f 100644 --- a/src/test/java/hudson/plugins/promoted_builds/PromotionTargetActionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/PromotionTargetActionTest.java @@ -5,21 +5,30 @@ import hudson.model.ParameterValue; import hudson.plugins.promoted_builds.conditions.ManualCondition; import hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; import java.util.Collections; +import static org.junit.Assert.assertSame; + /** * @author Kohsuke Kawaguchi */ -public class PromotionTargetActionTest extends HudsonTestCase { +public class PromotionTargetActionTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + /** * When a project is created, built, and renamed, then the old build is created, * that results in NPE. */ + @Test public void test1() throws Exception { - FreeStyleProject up = createFreeStyleProject("up"); - up.setCustomWorkspace(createTmpDir().getPath()); + FreeStyleProject up = j.createFreeStyleProject("up"); + up.setCustomWorkspace(j.createTmpDir().getPath()); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(up); @@ -27,13 +36,13 @@ public void test1() throws Exception { PromotionProcess proc = promotion.addProcess("promo"); proc.conditions.add(new ManualCondition()); - FreeStyleBuild b = assertBuildStatusSuccess(up.scheduleBuild2(0)); + FreeStyleBuild b = j.assertBuildStatusSuccess(up.scheduleBuild2(0)); b.addAction(new ManualApproval(proc.getName(), Collections.emptyList())); b.save(); // check for promotion - Promotion p = assertBuildStatusSuccess(proc.considerPromotion2(b)); + Promotion p = j.assertBuildStatusSuccess(proc.considerPromotion2(b)); up.renameTo("up2"); diff --git a/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java b/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java index a1200619..65dd8e44 100644 --- a/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java @@ -42,11 +42,11 @@ import org.junit.Test; import static org.junit.Assert.*; import org.junit.Rule; -import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; /** Verifies use of REST API to manipulate promotions. */ -@Bug(8963) +@Issue("JENKINS-8963") public class RemoteApiTest { @Rule public JenkinsRule r = new JenkinsRule(); diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/DownstreamPassConditionTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/DownstreamPassConditionTest.java index 048d7f92..6cdac784 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/DownstreamPassConditionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/DownstreamPassConditionTest.java @@ -26,7 +26,7 @@ import static org.junit.Assert.*; import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; import hudson.model.FreeStyleBuild; @@ -37,7 +37,6 @@ import hudson.plugins.promoted_builds.PromotionProcess; import hudson.plugins.promoted_builds.Status; import hudson.tasks.BuildTrigger; -import jenkins.model.Jenkins; public final class DownstreamPassConditionTest { @@ -45,7 +44,7 @@ public final class DownstreamPassConditionTest { public JenkinsRule j = new JenkinsRule(); @Test - @Bug(7739) + @Issue("JENKINS-7739") public void shouldEvaluateUpstreamRecursively() throws Exception { final FreeStyleProject job1 = j.createFreeStyleProject("job1"); final FreeStyleProject job2 = j.createFreeStyleProject("job2"); diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java index af1fd8a5..7558fd2a 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java @@ -16,17 +16,26 @@ import java.io.IOException; import java.util.List; -import jenkins.model.Jenkins; - -import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; + +import static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; + +@Issue("JENKINS-22005") +public class ManualConditionBug22005 { + + @Rule + public JenkinsRule j = new JenkinsRule(); -@Bug(22005) -public class ManualConditionBug22005 extends HudsonTestCase { private PromotionProcess createPromotionProcess(JobPropertyImpl parent, String name) throws IOException{ PromotionProcess prom0 = parent.addProcess(name); ManualCondition prom0ManualCondition=new ManualCondition(); @@ -35,11 +44,12 @@ private PromotionProcess createPromotionProcess(JobPropertyImpl parent, String n prom0.conditions.add(prom0ManualCondition); return prom0; } - + + @Test public void testPromotionProcess() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); - ExtensionList list = hudson.getExtensionList(Descriptor.class); + ExtensionList list = j.jenkins.getExtensionList(Descriptor.class); list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); JobPropertyImpl base = new JobPropertyImpl(p); p.addProperty(base); @@ -50,16 +60,16 @@ public void testPromotionProcess() throws Exception { PromotionProcess prom2=createPromotionProcess(base, "PROM2"); ManualCondition prom2Condition=prom2.conditions.get(ManualCondition.class); - FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0)); - Promotion p0b1=assertBuildStatusSuccess(prom0Condition.approve(b1, prom0)); + FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); + Promotion p0b1=j.assertBuildStatusSuccess(prom0Condition.approve(b1, prom0)); assertEquals(2,p0b1.getParameterValues().size()); assertEquals(2,p0b1.getParameterDefinitionsWithValue().size()); - Promotion p1b1=assertBuildStatusSuccess(prom1Condition.approve(b1, prom1)); + Promotion p1b1=j.assertBuildStatusSuccess(prom1Condition.approve(b1, prom1)); assertEquals(2,p1b1.getParameterValues().size()); assertEquals(2,p1b1.getParameterDefinitionsWithValue().size()); - Promotion p2b1=assertBuildStatusSuccess(prom2Condition.approve(b1, prom2)); + Promotion p2b1=j.assertBuildStatusSuccess(prom2Condition.approve(b1, prom2)); assertEquals(2,p2b1.getParameterValues().size()); assertEquals(2,p2b1.getParameterDefinitionsWithValue().size()); @@ -75,12 +85,13 @@ public void testPromotionProcess() throws Exception { List lastBuildParameters=lastBuild.getParameterDefinitionsWithValue(); assertEquals(2, lastBuildParameters.size()); } - } + + @Test public void testPromotionProcessViaWebClient() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); - ExtensionList list = hudson.getExtensionList(Descriptor.class); + ExtensionList list = j.jenkins.getExtensionList(Descriptor.class); list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); JobPropertyImpl base = new JobPropertyImpl(p); p.addProperty(base); @@ -89,9 +100,9 @@ public void testPromotionProcessViaWebClient() throws Exception { createPromotionProcess(base, "PROM2"); - FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0)); + FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertNull(b1.getAction(ManualApproval.class)); - HtmlPage page=createWebClient().getPage(b1, "promotion"); + HtmlPage page=j.createWebClient().getPage(b1, "promotion"); //Approve Promotion List forms=ManualConditionTest.getFormsByName(page, "approve"); assertFalse(forms.isEmpty()); @@ -101,7 +112,7 @@ public void testPromotionProcessViaWebClient() throws Exception { } //reload promotions page - page=createWebClient().getPage(b1, "promotion"); + page=j.createWebClient().getPage(b1, "promotion"); forms=ManualConditionTest.getFormsByName(page,"build"); for (HtmlForm form:forms){ List parameters=ManualConditionTest.getFormParameters(form); diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionTest.java index f4c71304..e7149367 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionTest.java @@ -12,8 +12,6 @@ import hudson.plugins.promoted_builds.Promotion; import hudson.plugins.promoted_builds.PromotionProcess; import hudson.plugins.promoted_builds.Status; -import hudson.plugins.promoted_builds.JobPropertyImpl.DescriptorImpl; -import hudson.plugins.promoted_builds.conditions.ManualCondition; import hudson.plugins.promoted_builds.conditions.ManualCondition.ManualApproval; import java.util.ArrayList; @@ -21,21 +19,27 @@ import java.util.List; import java.util.SortedMap; -import jenkins.model.Jenkins; - -import org.jvnet.hudson.test.HudsonTestCase; - import com.gargoylesoftware.htmlunit.html.HtmlElement; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.model.StringParameterValue; import hudson.model.TaskListener; +import org.junit.Rule; +import org.junit.Test; import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; + +import static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit; +import static org.junit.Assert.*; /** * @author Kohsuke Kawaguchi */ -public class ManualConditionTest extends HudsonTestCase { +public class ManualConditionTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + public static List getFormsByName(HtmlPage page, String name){ List forms=new ArrayList(); for (HtmlForm f:page.getForms()){ @@ -48,11 +52,12 @@ public static List getFormsByName(HtmlPage page, String name){ public static List getFormParameters(HtmlForm form){ return form.getElementsByAttribute("div", "name", "parameter"); } - + + @Test public void testManualPromotionProcess() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); - ExtensionList list = hudson.getExtensionList(Descriptor.class); + ExtensionList list = j.jenkins.getExtensionList(Descriptor.class); list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); JobPropertyImpl base = new JobPropertyImpl(p); p.addProperty(base); @@ -63,7 +68,7 @@ public void testManualPromotionProcess() throws Exception { condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter")); foo.conditions.add(condition); - FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0)); + FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); // promote a build @@ -71,7 +76,7 @@ public void testManualPromotionProcess() throws Exception { //try to add duplicate values paramValues.addAll(condition.createDefaultValues()); - assertBuildStatusSuccess(condition.approve(b1, foo, paramValues)); + j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues)); ManualApproval manualApproval=b1.getAction(ManualApproval.class); assertNotNull(manualApproval); @@ -82,12 +87,13 @@ public void testManualPromotionProcess() throws Exception { } @Issue("SECURITY-170") + @Test /** * Verify that the plugin is tolerant against SECURITY-170 in Manual conditions */ public void testManualPromotionProcessWithInvalidParam() throws Exception { - FreeStyleProject p = createFreeStyleProject(); - ExtensionList list = hudson.getExtensionList(Descriptor.class); + FreeStyleProject p = j.createFreeStyleProject(); + ExtensionList list = j.jenkins.getExtensionList(Descriptor.class); list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); JobPropertyImpl base = new JobPropertyImpl(p); p.addProperty(base); @@ -97,12 +103,12 @@ public void testManualPromotionProcessWithInvalidParam() throws Exception { condition.getParameterDefinitions().add(new StringParameterDefinition("FOO", "BAR", "Test parameter")); foo.conditions.add(condition); - FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0)); + FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); // Promote a build. Also add one invalid parameter List paramValues = condition.createDefaultValues(); paramValues.add(new StringParameterValue("INVALID_PARAM", "hacked!")); - assertBuildStatusSuccess(condition.approve(b1, foo, paramValues)); + j.assertBuildStatusSuccess(condition.approve(b1, foo, paramValues)); ManualApproval manualApproval = b1.getAction(ManualApproval.class); assertNotNull(manualApproval); List parameterValues = manualApproval.badge.getParameterValues(); @@ -116,11 +122,12 @@ public void testManualPromotionProcessWithInvalidParam() throws Exception { assertNotNull("INVALID_PARAM should not be injected into the environment", pb.getEnvironment(TaskListener.NULL).get("INVALID_PARAM", null)); } - + + @Test public void testManualPromotionProcessViaWebClient() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); - ExtensionList list = hudson.getExtensionList(Descriptor.class); + ExtensionList list = j.jenkins.getExtensionList(Descriptor.class); list.add(new JobPropertyImpl.DescriptorImpl(JobPropertyImpl.class)); JobPropertyImpl base = new JobPropertyImpl(p); p.addProperty(base); @@ -130,9 +137,9 @@ public void testManualPromotionProcessViaWebClient() throws Exception { condition.getParameterDefinitions().add(new StringParameterDefinition("bogus_string_param_2", "bogus_value_2", "Bog parameter")); foo.conditions.add(condition); - FreeStyleBuild b1 = assertBuildStatusSuccess(p.scheduleBuild2(0)); + FreeStyleBuild b1 = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertNull(b1.getAction(ManualApproval.class)); - HtmlPage page=createWebClient().getPage(b1, "promotion"); + HtmlPage page=j.createWebClient().getPage(b1, "promotion"); //Approve Promotion List forms=getFormsByName(page, "approve"); assertFalse(forms.isEmpty()); @@ -154,7 +161,7 @@ public void testManualPromotionProcessViaWebClient() throws Exception { assertTrue(builds.size()==1); //Re-Execute approved promotion - page=createWebClient().getPage(b1, "promotion"); + page=j.createWebClient().getPage(b1, "promotion"); forms=getFormsByName(page,"build"); assertFalse(forms.isEmpty()); assertTrue(forms.size()==1); diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java index 3ad559c9..f6b0e827 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java @@ -13,15 +13,24 @@ import hudson.plugins.promoted_builds.PromotedBuildAction; import hudson.plugins.promoted_builds.Promotion; import hudson.plugins.promoted_builds.PromotionProcess; -import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.Issue; +import org.jvnet.hudson.test.JenkinsRule; + +import static org.junit.Assert.*; /** * @author Kohsuke Kawaguchi */ -public class SelfPromotionTest extends HudsonTestCase { +public class SelfPromotionTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Test public void testBasic() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(p); @@ -34,14 +43,14 @@ public void testBasic() throws Exception { promo2.conditions.add(new SelfPromotionCondition(false)); // ensure that the data survives the roundtrip - configRoundtrip(p); + j.configRoundtrip(p); // rebind promotion = p.getProperty(JobPropertyImpl.class); promo1 = promotion.getItem("promo1"); promo2 = promotion.getItem("promo2"); - FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0)); + FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0)); // internally, the promotion is still an asynchronous process. It just happens // right away after the build is complete. Thread.sleep(1000); @@ -58,8 +67,9 @@ public void testBasic() throws Exception { assertTrue(badge.contains(promo2)); } + @Test public void testUnstable() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(p); @@ -72,7 +82,7 @@ public void testUnstable() throws Exception { promo2.conditions.add(new SelfPromotionCondition(true)); // ensure that the data survives the roundtrip - configRoundtrip(p); + j.configRoundtrip(p); // rebind promotion = p.getProperty(JobPropertyImpl.class); @@ -80,7 +90,7 @@ public void testUnstable() throws Exception { promo2 = promotion.getItem("promo2"); p.getBuildersList().add(unstableBuilder()); - FreeStyleBuild b = assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); + FreeStyleBuild b = j.assertBuildStatus(Result.UNSTABLE, p.scheduleBuild2(0).get()); // internally, the promotion is still an asynchronous process. It just happens // right away after the build is complete. Thread.sleep(1000); @@ -96,9 +106,9 @@ public void testUnstable() throws Exception { assertTrue(badge.contains(promo2)); } - + @Test public void testFailure() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(p); @@ -111,7 +121,7 @@ public void testFailure() throws Exception { promo2.conditions.add(new SelfPromotionCondition(true)); // ensure that the data survives the roundtrip - configRoundtrip(p); + j.configRoundtrip(p); // rebind promotion = p.getProperty(JobPropertyImpl.class); @@ -119,7 +129,7 @@ public void testFailure() throws Exception { promo2 = promotion.getItem("promo2"); p.getBuildersList().add(failureBuilder()); - FreeStyleBuild b = assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); + FreeStyleBuild b = j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0).get()); // internally, the promotion is still an asynchronous process. It just happens // right away after the build is complete. @@ -134,12 +144,13 @@ public void testFailure() throws Exception { assertFalse(badge.contains(promo2)); } - @Bug(22679) - // @Bug(34826) // Can be reproduced in Jenkins 2.3 + + @Issue("JENKINS-22679") + @Test + // @Issue("JENKINS-34826") // Can be reproduced in Jenkins 2.3 + public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param"; - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); p.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition(paramName, ""))); // promote if the downstream passes @@ -150,14 +161,14 @@ public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Excep promo1.conditions.add(new SelfPromotionCondition(false)); // ensure that the data survives the roundtrip - configRoundtrip(p); + j.configRoundtrip(p); // rebind promotion = p.getProperty(JobPropertyImpl.class); promo1 = promotion.getItem("promo1"); String paramValue = "someString"; - FreeStyleBuild b = assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserCause(), + FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0, new Cause.UserCause(), new ParametersAction(new StringParameterValue(paramName, paramValue)))); // internally, the promotion is still an asynchronous process. It just happens // right away after the build is complete. diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java index 73eb44a0..94c8ff8e 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/DownstreamPassConditionInheritanceTest.java @@ -26,7 +26,6 @@ import static org.junit.Assert.*; import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.Bug; import hudson.model.Result; import hudson.plugins.project_inheritance.projects.InheritanceBuild; @@ -39,7 +38,7 @@ import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectRule; import hudson.plugins.promoted_builds.inheritance.helpers.InheritanceProjectsPair; import hudson.tasks.BuildTrigger; -import jenkins.model.Jenkins; +import org.jvnet.hudson.test.Issue; public final class DownstreamPassConditionInheritanceTest { @@ -47,7 +46,7 @@ public final class DownstreamPassConditionInheritanceTest { public InheritanceProjectRule j = new InheritanceProjectRule(); @Test - @Bug(7739) + @Issue("JENKINS-7739") public void shouldEvaluateUpstreamRecursively() throws Exception { final InheritanceProjectsPair pair1 = j.createInheritanceProjectDerivedWithBase(); final InheritanceProjectsPair pair2 = j.createInheritanceProjectDerivedWithBase(); diff --git a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java index 0c7ad0cf..119f6ff5 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/inheritance/SelfPromotionInheritanceTest.java @@ -26,7 +26,7 @@ import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.Issue; /** @@ -169,7 +169,7 @@ public void testFailure() throws Exception { } @Test - @Bug(22679) + @Issue("JENKINS-22679") public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param"; diff --git a/src/test/java/hudson/plugins/promoted_builds/integrations/jobdsl/PromotionsDslContextExtensionTest.java b/src/test/java/hudson/plugins/promoted_builds/integrations/jobdsl/PromotionsDslContextExtensionTest.java index 38639f98..1febde21 100644 --- a/src/test/java/hudson/plugins/promoted_builds/integrations/jobdsl/PromotionsDslContextExtensionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/integrations/jobdsl/PromotionsDslContextExtensionTest.java @@ -14,22 +14,26 @@ import javaposse.jobdsl.plugin.ExecuteDslScripts; import org.apache.commons.io.FileUtils; +import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.HudsonTestCase; +import org.jvnet.hudson.test.JenkinsRule; -public class PromotionsDslContextExtensionTest extends HudsonTestCase { +public class PromotionsDslContextExtensionTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); @Test public void testShouldGenerateTheDefindedJob() throws Exception { // Given String dsl = FileUtils.readFileToString(new File("src/test/resources/example-dsl.groovy")); - FreeStyleProject seedJob = createFreeStyleProject(); + FreeStyleProject seedJob = j.createFreeStyleProject(); seedJob.getBuildersList().add( new ExecuteDslScripts(new ExecuteDslScripts.ScriptLocation(Boolean.TRUE.toString(), null, dsl), false, RemovedJobAction.DELETE)); // When QueueTaskFuture scheduleBuild2 = seedJob.scheduleBuild2(0); // Then - assertBuildStatusSuccess(scheduleBuild2); + j.assertBuildStatusSuccess(scheduleBuild2); } @@ -37,28 +41,28 @@ public void testShouldGenerateTheDefindedJob() throws Exception { public void testShouldGenerateTheDefindedComplexJob() throws Exception { // Given String dsl = FileUtils.readFileToString(new File("src/test/resources/complex-example-dsl.groovy")); - FreeStyleProject seedJob = createFreeStyleProject(); + FreeStyleProject seedJob = j.createFreeStyleProject(); seedJob.getBuildersList().add( new ExecuteDslScripts(new ExecuteDslScripts.ScriptLocation(Boolean.TRUE.toString(), null, dsl), false, RemovedJobAction.DELETE)); // When QueueTaskFuture scheduleBuild2 = seedJob.scheduleBuild2(0); // Then - assertBuildStatusSuccess(scheduleBuild2); + j.assertBuildStatusSuccess(scheduleBuild2); } @Test public void testShouldGenerateTheCopyArtifactsJob() throws Exception { // Given String dsl = FileUtils.readFileToString(new File("src/test/resources/copyartifacts-example-dsl.groovy")); - FreeStyleProject seedJob = createFreeStyleProject(); + FreeStyleProject seedJob = j.createFreeStyleProject(); seedJob.getBuildersList().add( new ExecuteDslScripts(new ExecuteDslScripts.ScriptLocation(Boolean.TRUE.toString(), null, dsl), false, RemovedJobAction.DELETE)); // When QueueTaskFuture scheduleBuild2 = seedJob.scheduleBuild2(0); // Then (unstable b/c we aren't including the CopyArtifacts dependency) - assertBuildStatus(Result.UNSTABLE, scheduleBuild2.get()); + j.assertBuildStatus(Result.UNSTABLE, scheduleBuild2.get()); - TopLevelItem item = jenkins.getItem("copy-artifacts-test"); + TopLevelItem item = j.jenkins.getItem("copy-artifacts-test"); File config = new File(item.getRootDir(), "promotions/Development/config.xml"); String content = Files.toString(config, Charset.forName("UTF-8")); assert content.contains("");