From 5a08cf48b411f90565235921af6ae5f42aaba3c6 Mon Sep 17 00:00:00 2001 From: tfennelly Date: Thu, 23 Jul 2015 20:20:09 +0100 Subject: [PATCH] Dependency exclusions for http commons + some test fixes --- test/pom.xml | 10 +++++++ .../htmlunit/html/HtmlFormUtil.java | 27 +++++++++++-------- .../org/jvnet/hudson/test/HudsonTestCase.java | 4 +-- .../org/jvnet/hudson/test/JenkinsRule.java | 4 +-- .../java/hudson/bugs/LoginRedirectTest.java | 2 +- 5 files changed, 31 insertions(+), 16 deletions(-) diff --git a/test/pom.xml b/test/pom.xml index 0af213f6b9..34495fd778 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -64,6 +64,16 @@ THE SOFTWARE. ${project.groupId} maven-plugin ${maven-plugin.version} + + + org.apache.httpcomponents + httpclient + + + org.apache.httpcomponents + httpcore + + org.jenkins-ci.plugins diff --git a/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java b/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java index e08177881c..9ad296633e 100644 --- a/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java +++ b/test/src/main/java/com/gargoylesoftware/htmlunit/html/HtmlFormUtil.java @@ -38,14 +38,14 @@ public class HtmlFormUtil { * Plain {@link com.gargoylesoftware.htmlunit.html.HtmlForm#submit()} doesn't work correctly due to the use of YUI in Hudson. */ public static Page submit(final HtmlForm htmlForm) throws IOException { - final HtmlSubmitInput submitElement = getSubmitButton(htmlForm); + final HtmlButton submitElement = getSubmitButton(htmlForm); return submit(htmlForm, submitElement); } /** * Plain {@link com.gargoylesoftware.htmlunit.html.HtmlForm#submit()} doesn't work correctly due to the use of YUI in Hudson. */ - public static Page submit(HtmlForm htmlForm, HtmlSubmitInput submitElement) throws IOException { + public static Page submit(HtmlForm htmlForm, HtmlButton submitElement) throws IOException { if (submitElement != null) { // To make YUI event handling work, this combo seems to be necessary // the click will trigger _onClick in buton-*.js, but it doesn't submit the form @@ -63,13 +63,13 @@ public class HtmlFormUtil { /** * Returns all the <input type="submit"> elements in this form. */ - public static List getSubmitButtons(final HtmlForm htmlForm) throws ElementNotFoundException { - final List list = htmlForm.getElementsByAttribute("input", "type", "submit"); + public static List getSubmitButtons(final HtmlForm htmlForm) throws ElementNotFoundException { + final List list = htmlForm.getElementsByAttribute("input", "type", "submit"); // collect inputs from lost children for (final HtmlElement elt : htmlForm.getLostChildren()) { - if (elt instanceof HtmlSubmitInput) { - list.add((HtmlSubmitInput) elt); + if (elt instanceof HtmlButton) { + list.add((HtmlButton) elt); } } return list; @@ -78,14 +78,19 @@ public class HtmlFormUtil { /** * Gets the first <input type="submit"> element in this form. */ - public static HtmlSubmitInput getSubmitButton(final HtmlForm htmlForm) throws ElementNotFoundException { - return getSubmitButtons(htmlForm).get(0); + public static HtmlButton getSubmitButton(final HtmlForm htmlForm) throws ElementNotFoundException { + List submitButtons = getSubmitButtons(htmlForm); + if (!submitButtons.isEmpty()) { + return submitButtons.get(0); + } + return null; } - public static HtmlSubmitInput getButtonByCaption(final HtmlForm htmlForm, final String caption) throws ElementNotFoundException { + public static HtmlButton getButtonByCaption(final HtmlForm htmlForm, final String caption) throws ElementNotFoundException { for (HtmlElement b : htmlForm.getHtmlElementsByTagName("button")) { - if(b.getTextContent().trim().equals(caption)) - return (HtmlSubmitInput) b; + if(b instanceof HtmlButton && b.getTextContent().trim().equals(caption)) { + return (HtmlButton) b; + } } throw new ElementNotFoundException("button", "caption", caption); } diff --git a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java index efb54899b3..8717c27704 100644 --- a/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java +++ b/test/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java @@ -1175,8 +1175,8 @@ public abstract class HudsonTestCase extends TestCase implements RootAction { public HtmlPage submit(HtmlForm form, String name) throws Exception { for( HtmlElement e : form.getHtmlElementsByTagName("button")) { HtmlElement p = (HtmlElement)e.getParentNode().getParentNode(); - if(p.getAttribute("name").equals(name)) { - return (HtmlPage)HtmlFormUtil.submit(form, (HtmlSubmitInput) e); + if(e instanceof HtmlButton && p.getAttribute("name").equals(name)) { + return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e); } } throw new AssertionError("No such submit button with the name "+name); diff --git a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java index 5e38f9066c..20f4b87e40 100644 --- a/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java +++ b/test/src/main/java/org/jvnet/hudson/test/JenkinsRule.java @@ -1315,8 +1315,8 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction { public HtmlPage submit(HtmlForm form, String name) throws Exception { for( HtmlElement e : form.getHtmlElementsByTagName("button")) { HtmlElement p = (HtmlElement)e.getParentNode().getParentNode(); - if(p.getAttribute("name").equals(name)) { - return (HtmlPage)HtmlFormUtil.submit(form, (HtmlSubmitInput) e); + if(e instanceof HtmlButton && p.getAttribute("name").equals(name)) { + return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e); } } throw new AssertionError("No such submit button with the name "+name); diff --git a/test/src/test/java/hudson/bugs/LoginRedirectTest.java b/test/src/test/java/hudson/bugs/LoginRedirectTest.java index 033966cf18..c34a45c338 100644 --- a/test/src/test/java/hudson/bugs/LoginRedirectTest.java +++ b/test/src/test/java/hudson/bugs/LoginRedirectTest.java @@ -51,7 +51,7 @@ public class LoginRedirectTest extends HudsonTestCase { wc.getOptions().setThrowExceptionOnFailingStatusCode(false); HtmlPage p = wc.goTo("/"); - System.out.println(p.getDocumentURI()); + //System.out.println(p.getDocumentURI()); assertEquals(200, p.getWebResponse().getStatusCode()); HtmlForm form = p.getFormByName("login"); form.getInputByName("j_username").setValueAttribute("alice"); -- GitLab