From e323a6d0bac90cb852a5b1aa48328d87eab3f592 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evaristo=20Gutie=CC=81rrez?= Date: Mon, 15 May 2017 12:40:00 +0200 Subject: [PATCH 1/6] [JENKINS-44266] Include tests dependency necessary when running against newer core versions (PCT). --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index 495376ed..37c703a3 100644 --- a/pom.xml +++ b/pom.xml @@ -150,6 +150,12 @@ 1.0 test + + org.jenkins-ci.plugins + subversion + 2.5.7 + test + org.apache.httpcomponents httpclient From c9c11d8ab3697a589b181870c589be4b558a77e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evaristo=20Gutie=CC=81rrez?= Date: Fri, 9 Jun 2017 15:01:08 +0200 Subject: [PATCH 2/6] [JENKINS-44266] Bump core and dependencies. --- pom.xml | 56 +++---------------- .../promoted_builds/JobPropertyImpl.java | 4 +- 2 files changed, 11 insertions(+), 49 deletions(-) diff --git a/pom.xml b/pom.xml index 37c703a3..bae417a2 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 @@ -47,43 +47,11 @@ - - - - jenkins-releases - http://repo.jenkins-ci.org/releases/ - - true - - - false - - - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - true - - - false - - - - - - - - repo.jenkins-ci.org - http://repo.jenkins-ci.org/public/ - - - org.jenkins-ci.main maven-plugin - 2.0 + 2.13 com.sonyericsson.hudson.plugins.rebuild @@ -106,7 +74,7 @@ org.jenkins-ci.plugins token-macro - 1.10 + 1.12.1 true @@ -124,7 +92,7 @@ org.jenkins-ci.plugins script-security - 1.16 + 1.26 org.jvnet.hudson @@ -135,25 +103,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 - test - - - org.jenkins-ci.plugins - subversion - 2.5.7 + 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); From c76d279a7ff95f30123468b421a27c4d60530a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evaristo=20Gutie=CC=81rrez?= Date: Fri, 9 Jun 2017 15:01:28 +0200 Subject: [PATCH 3/6] [JENKINS-44266] Stop using HudsonTestCase. --- .../ConfigurationDoCheckTest.java | 34 ++++++--- .../ConfigurationRoundtripTest.java | 30 +++++--- .../KeepBuildForeverActionTest.java | 43 +++++++----- .../PromotedBuildActionTest.java | 19 +++-- .../promoted_builds/PromotionProcessTest.java | 70 ++++++++++++------- .../PromotionTargetActionTest.java | 21 ++++-- .../conditions/ManualConditionBug22005.java | 45 +++++++----- .../conditions/ManualConditionTest.java | 51 ++++++++------ .../conditions/SelfPromotionTest.java | 35 ++++++---- .../PromotionsDslContextExtensionTest.java | 22 +++--- 10 files changed, 237 insertions(+), 133 deletions(-) diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java index a910b3b9..119f8141 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java @@ -1,22 +1,33 @@ package hudson.plugins.promoted_builds; +import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.model.FreeStyleProject; import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition; import hudson.tasks.JavadocArchiver; +import org.junit.Rule; +import org.junit.Test; import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +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) + @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 +37,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) + @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 +60,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..fcf3154d 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.junit.Rule; +import org.junit.Test; import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +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); @@ -69,10 +82,11 @@ public void testRoundtrip() throws Exception { @LocalData @Bug(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/conditions/ManualConditionBug22005.java b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java index af1fd8a5..e003a575 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.junit.Rule; +import org.junit.Test; import org.jvnet.hudson.test.Bug; -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 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; @Bug(22005) -public class ManualConditionBug22005 extends HudsonTestCase { +public class ManualConditionBug22005 { + + @Rule + public JenkinsRule j = new JenkinsRule(); + 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..4bd3c3d1 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,22 @@ import hudson.plugins.promoted_builds.PromotedBuildAction; import hudson.plugins.promoted_builds.Promotion; import hudson.plugins.promoted_builds.PromotionProcess; +import org.junit.Rule; import org.jvnet.hudson.test.Bug; -import org.jvnet.hudson.test.HudsonTestCase; +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(); + public void testBasic() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(p); @@ -34,14 +41,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); @@ -59,7 +66,7 @@ public void testBasic() throws Exception { } public void testUnstable() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(p); @@ -72,7 +79,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 +87,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); @@ -98,7 +105,7 @@ public void testUnstable() throws Exception { public void testFailure() throws Exception { - FreeStyleProject p = createFreeStyleProject(); + FreeStyleProject p = j.createFreeStyleProject(); // promote if the downstream passes JobPropertyImpl promotion = new JobPropertyImpl(p); @@ -111,7 +118,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 +126,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. @@ -139,7 +146,7 @@ public void testFailure() throws Exception { 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 +157,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/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(""); From e163ab3a91f94700849e76cb755d8c502a6c16ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evaristo=20Gutie=CC=81rrez?= Date: Fri, 9 Jun 2017 15:33:20 +0200 Subject: [PATCH 4/6] [JENKINS-44266] Add @Test annotation. --- .../promoted_builds/conditions/SelfPromotionTest.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 4bd3c3d1..5c97a4e4 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java @@ -14,6 +14,7 @@ import hudson.plugins.promoted_builds.Promotion; import hudson.plugins.promoted_builds.PromotionProcess; import org.junit.Rule; +import org.junit.Test; import org.jvnet.hudson.test.Bug; import org.jvnet.hudson.test.JenkinsRule; @@ -27,6 +28,7 @@ public class SelfPromotionTest { @Rule public JenkinsRule j = new JenkinsRule(); + @Test public void testBasic() throws Exception { FreeStyleProject p = j.createFreeStyleProject(); @@ -65,6 +67,7 @@ public void testBasic() throws Exception { assertTrue(badge.contains(promo2)); } + @Test public void testUnstable() throws Exception { FreeStyleProject p = j.createFreeStyleProject(); @@ -103,7 +106,7 @@ public void testUnstable() throws Exception { assertTrue(badge.contains(promo2)); } - + @Test public void testFailure() throws Exception { FreeStyleProject p = j.createFreeStyleProject(); @@ -142,6 +145,7 @@ public void testFailure() throws Exception { } @Bug(22679) + @Test // @Bug(34826) // Can be reproduced in Jenkins 2.3 + public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param"; From 5a810cf8b2824fdd2f65824e32f28730f6f5ac8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evaristo=20Gutie=CC=81rrez?= Date: Mon, 12 Jun 2017 09:28:35 +0200 Subject: [PATCH 5/6] [JENKINS-44266] Add back repositories tag in POM and replace @Bug for @Issue. --- pom.xml | 13 +++++++++++++ .../promoted_builds/ConfigurationDoCheckTest.java | 7 +++---- .../promoted_builds/ConfigurationRoundtripTest.java | 4 ++-- .../plugins/promoted_builds/RemoteApiTest.java | 4 ++-- .../conditions/DownstreamPassConditionTest.java | 5 ++--- .../conditions/ManualConditionBug22005.java | 4 ++-- .../conditions/SelfPromotionTest.java | 6 +++--- .../DownstreamPassConditionInheritanceTest.java | 5 ++--- .../inheritance/SelfPromotionInheritanceTest.java | 4 ++-- 9 files changed, 31 insertions(+), 21 deletions(-) diff --git a/pom.xml b/pom.xml index bae417a2..55a26fc8 100644 --- a/pom.xml +++ b/pom.xml @@ -47,6 +47,19 @@ + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + org.jenkins-ci.main diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java index 119f8141..12f07f20 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java @@ -1,13 +1,12 @@ package hudson.plugins.promoted_builds; -import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.html.HtmlPage; import hudson.model.FreeStyleProject; import hudson.plugins.promoted_builds.conditions.DownstreamPassCondition; import hudson.tasks.JavadocArchiver; 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 static com.gargoylesoftware.htmlunit.html.HtmlFormUtil.submit; @@ -22,7 +21,7 @@ public class ConfigurationDoCheckTest { @Rule public JenkinsRule j = new JenkinsRule(); - @Bug(7972) + @Issue("7972") @Test public void testCheckProcessNameRequired() throws Exception { FreeStyleProject down = j.createFreeStyleProject(); @@ -45,7 +44,7 @@ public void testCheckProcessNameRequired() throws Exception { } - @Bug(7972) + @Issue("7972") @Test public void testCheckInvalidProcessName() throws Exception { FreeStyleProject down = j.createFreeStyleProject(); diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java index fcf3154d..39f99b4e 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java @@ -28,7 +28,7 @@ import hudson.tasks.JavadocArchiver; 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 org.jvnet.hudson.test.recipes.LocalData; @@ -81,7 +81,7 @@ public void testRoundtrip() throws Exception { } @LocalData - @Bug(17341) + @Issue("17341") @Test public void testLoad() throws Exception { FreeStyleProject jProj = j.jenkins.getItemByFullName("j", FreeStyleProject.class); diff --git a/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java b/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java index a1200619..e547912e 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("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..3c0a64ab 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("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 e003a575..9ef8113a 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java @@ -18,11 +18,11 @@ import org.junit.Rule; import org.junit.Test; -import org.jvnet.hudson.test.Bug; 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; @@ -30,7 +30,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -@Bug(22005) +@Issue("22005") public class ManualConditionBug22005 { @Rule 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 5c97a4e4..ed01e694 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java @@ -15,7 +15,7 @@ import hudson.plugins.promoted_builds.PromotionProcess; 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 static org.junit.Assert.*; @@ -144,9 +144,9 @@ public void testFailure() throws Exception { assertFalse(badge.contains(promo2)); } - @Bug(22679) + @Issue("22679") @Test - // @Bug(34826) // Can be reproduced in Jenkins 2.3 + + // @Issue("34826") // Can be reproduced in Jenkins 2.3 + public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param"; 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..5a40766d 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("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..43057363 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("22679") public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param"; From ec9c429dc7e35a7cb50631e7aad2cba9f00d22e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Evaristo=20Gutie=CC=81rrez?= Date: Mon, 12 Jun 2017 10:20:12 +0200 Subject: [PATCH 6/6] [JENKINS-44266] Use full ids for issues. --- .../plugins/promoted_builds/ConfigurationDoCheckTest.java | 4 ++-- .../plugins/promoted_builds/ConfigurationRoundtripTest.java | 2 +- .../java/hudson/plugins/promoted_builds/RemoteApiTest.java | 2 +- .../conditions/DownstreamPassConditionTest.java | 2 +- .../promoted_builds/conditions/ManualConditionBug22005.java | 2 +- .../plugins/promoted_builds/conditions/SelfPromotionTest.java | 4 ++-- .../inheritance/DownstreamPassConditionInheritanceTest.java | 2 +- .../conditions/inheritance/SelfPromotionInheritanceTest.java | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java index 12f07f20..9cd12411 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationDoCheckTest.java @@ -21,7 +21,7 @@ public class ConfigurationDoCheckTest { @Rule public JenkinsRule j = new JenkinsRule(); - @Issue("7972") + @Issue("JENKINS-7972") @Test public void testCheckProcessNameRequired() throws Exception { FreeStyleProject down = j.createFreeStyleProject(); @@ -44,7 +44,7 @@ public void testCheckProcessNameRequired() throws Exception { } - @Issue("7972") + @Issue("JENKINS-7972") @Test public void testCheckInvalidProcessName() throws Exception { FreeStyleProject down = j.createFreeStyleProject(); diff --git a/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java b/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java index 39f99b4e..51d8c4eb 100644 --- a/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/ConfigurationRoundtripTest.java @@ -81,7 +81,7 @@ public void testRoundtrip() throws Exception { } @LocalData - @Issue("17341") + @Issue("JENKINS-17341") @Test public void testLoad() throws Exception { FreeStyleProject jProj = j.jenkins.getItemByFullName("j", FreeStyleProject.class); diff --git a/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java b/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java index e547912e..65dd8e44 100644 --- a/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/RemoteApiTest.java @@ -46,7 +46,7 @@ import org.jvnet.hudson.test.JenkinsRule; /** Verifies use of REST API to manipulate promotions. */ -@Issue("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 3c0a64ab..6cdac784 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/DownstreamPassConditionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/DownstreamPassConditionTest.java @@ -44,7 +44,7 @@ public final class DownstreamPassConditionTest { public JenkinsRule j = new JenkinsRule(); @Test - @Issue("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 9ef8113a..7558fd2a 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/ManualConditionBug22005.java @@ -30,7 +30,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; -@Issue("22005") +@Issue("JENKINS-22005") public class ManualConditionBug22005 { @Rule 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 ed01e694..f6b0e827 100644 --- a/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java +++ b/src/test/java/hudson/plugins/promoted_builds/conditions/SelfPromotionTest.java @@ -144,9 +144,9 @@ public void testFailure() throws Exception { assertFalse(badge.contains(promo2)); } - @Issue("22679") + @Issue("JENKINS-22679") @Test - // @Issue("34826") // Can be reproduced in Jenkins 2.3 + + // @Issue("JENKINS-34826") // Can be reproduced in Jenkins 2.3 + public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param"; 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 5a40766d..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 @@ -46,7 +46,7 @@ public final class DownstreamPassConditionInheritanceTest { public InheritanceProjectRule j = new InheritanceProjectRule(); @Test - @Issue("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 43057363..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 @@ -169,7 +169,7 @@ public void testFailure() throws Exception { } @Test - @Issue("22679") + @Issue("JENKINS-22679") public void testPromotionEnvironmentShouldIncludeTargetParameters() throws Exception { String paramName = "param";