提交 5a08cf48 编写于 作者: T tfennelly

Dependency exclusions for http commons + some test fixes

上级 f189af85
......@@ -64,6 +64,16 @@ THE SOFTWARE.
<groupId>${project.groupId}</groupId>
<artifactId>maven-plugin</artifactId>
<version>${maven-plugin.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
......
......@@ -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 &lt;input type="submit"> elements in this form.
*/
public static List<HtmlSubmitInput> getSubmitButtons(final HtmlForm htmlForm) throws ElementNotFoundException {
final List<HtmlSubmitInput> list = htmlForm.getElementsByAttribute("input", "type", "submit");
public static List<HtmlButton> getSubmitButtons(final HtmlForm htmlForm) throws ElementNotFoundException {
final List<HtmlButton> 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 &lt;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<HtmlButton> 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);
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册