Skip to content

Commit

Permalink
[JENKINS-55062] Correct tests (#4332)
Browse files Browse the repository at this point in the history
* [JENKINS-55062] Correct tests
- demonstrate failure

* [JENKINS-55062] Adjust test class name to have the expected behavior

* Revert constant change
  • Loading branch information
Wadeck authored and oleg-nenashev committed Nov 5, 2019
1 parent 46fe8be commit 0af98fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,33 @@
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();

@Test
@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=\""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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=\""));
Expand Down

0 comments on commit 0af98fe

Please sign in to comment.