From 0af98fe7163a821710f8be0dbc11086d4acd8bf2 Mon Sep 17 00:00:00 2001 From: Wadeck Follonier Date: Tue, 5 Nov 2019 07:19:33 +0100 Subject: [PATCH] [JENKINS-55062] Correct tests (#4332) * [JENKINS-55062] Correct tests - demonstrate failure * [JENKINS-55062] Adjust test class name to have the expected behavior * Revert constant change --- ...sLoading.java => HudsonIsLoadingTest.java} | 22 ++++++++++++++----- ...rting.java => HudsonIsRestartingTest.java} | 21 +++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) rename test/src/test/java/hudson/util/{HudsonIsLoading.java => HudsonIsLoadingTest.java} (51%) rename test/src/test/java/hudson/util/{HudsonIsRestarting.java => HudsonIsRestartingTest.java} (51%) diff --git a/test/src/test/java/hudson/util/HudsonIsLoading.java b/test/src/test/java/hudson/util/HudsonIsLoadingTest.java similarity index 51% rename from test/src/test/java/hudson/util/HudsonIsLoading.java rename to test/src/test/java/hudson/util/HudsonIsLoadingTest.java index 10c11adfbf91..f0efc3e2699b 100644 --- a/test/src/test/java/hudson/util/HudsonIsLoading.java +++ b/test/src/test/java/hudson/util/HudsonIsLoadingTest.java @@ -7,10 +7,12 @@ import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; +import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -public class HudsonIsLoading { +public class HudsonIsLoadingTest { @Rule public JenkinsRule j = new JenkinsRule(); @@ -18,12 +20,20 @@ public class HudsonIsLoading { @Issue("JENKINS-55062") public void withPrefix() throws Exception { j.jenkins.servletContext.setAttribute("app", new HudsonIsLoading()); - JenkinsRule.WebClient wc = j.createWebClient(); - wc.getOptions().setThrowExceptionOnFailingStatusCode(false); // this is a failure page already - wc.getOptions().setJavaScriptEnabled(false); + JenkinsRule.WebClient wc = j.createWebClient() + // this is a failure page already + .withThrowExceptionOnFailingStatusCode(false) + .withJavaScriptEnabled(false); - Page p = wc.goTo("", "text/html"); - assertTrue( p.isHtmlPage() ); + checkingPage(wc, ""); + checkingPage(wc, "anyRandomString"); + checkingPage(wc, "multiple/layer/ofRelative.xml"); + } + + private void checkingPage(JenkinsRule.WebClient wc, String relativePath) throws Exception { + Page p = wc.goTo(relativePath, "text/html"); + assertTrue(p.isHtmlPage()); + assertEquals(SC_SERVICE_UNAVAILABLE, p.getWebResponse().getStatusCode()); String body = p.getWebResponse().getContentAsString(); assertThat(body, CoreMatchers.containsString("data-resurl=\"")); assertThat(body, CoreMatchers.containsString("data-rooturl=\"")); diff --git a/test/src/test/java/hudson/util/HudsonIsRestarting.java b/test/src/test/java/hudson/util/HudsonIsRestartingTest.java similarity index 51% rename from test/src/test/java/hudson/util/HudsonIsRestarting.java rename to test/src/test/java/hudson/util/HudsonIsRestartingTest.java index 3b0d8f76b232..25ea8bac8699 100644 --- a/test/src/test/java/hudson/util/HudsonIsRestarting.java +++ b/test/src/test/java/hudson/util/HudsonIsRestartingTest.java @@ -7,9 +7,10 @@ import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; +import static javax.servlet.http.HttpServletResponse.SC_SERVICE_UNAVAILABLE; import static org.junit.Assert.*; -public class HudsonIsRestarting { +public class HudsonIsRestartingTest { @Rule public JenkinsRule j = new JenkinsRule(); @@ -18,12 +19,20 @@ public class HudsonIsRestarting { @Issue("JENKINS-55062") public void withPrefix() throws Exception { j.jenkins.servletContext.setAttribute("app", new HudsonIsRestarting()); - JenkinsRule.WebClient wc = j.createWebClient(); - wc.getOptions().setThrowExceptionOnFailingStatusCode(false); // this is a failure page already - wc.getOptions().setJavaScriptEnabled(false); + JenkinsRule.WebClient wc = j.createWebClient() + // this is a failure page already + .withThrowExceptionOnFailingStatusCode(false) + .withJavaScriptEnabled(false); - Page p = wc.goTo("", "text/html"); - assertTrue( p.isHtmlPage() ); + checkingPage(wc, ""); + checkingPage(wc, "anyRandomString"); + checkingPage(wc, "multiple/layer/ofRelative.xml"); + } + + private void checkingPage(JenkinsRule.WebClient wc, String relativePath) throws Exception { + Page p = wc.goTo(relativePath, "text/html"); + assertTrue(p.isHtmlPage()); + assertEquals(SC_SERVICE_UNAVAILABLE, p.getWebResponse().getStatusCode()); String body = p.getWebResponse().getContentAsString(); assertThat(body, CoreMatchers.containsString("data-resurl=\"")); assertThat(body, CoreMatchers.containsString("data-rooturl=\""));