提交 3bb56b81 编写于 作者: W Wadeck Follonier

[JENKINS-53511] Bump of JTH to include new methods in WebClient

- And thus, adapt the code due to the breaking changes in JTH sub-lib
上级 bc028237
......@@ -54,7 +54,7 @@ THE SOFTWARE.
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jenkins-test-harness</artifactId>
<version>2.41.1</version>
<version>2.42</version>
<scope>test</scope>
<exclusions>
<exclusion>
......
......@@ -34,6 +34,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.xml.XmlPage;
import java.io.File;
import java.nio.charset.StandardCharsets;
import jenkins.model.Jenkins;
import hudson.slaves.DumbSlave;
......@@ -109,7 +110,7 @@ public class ComputerTest {
private void verifyOfflineCause(Computer computer) throws Exception {
XmlPage page = j.createWebClient().goToXml("computer/" + computer.getName() + "/config.xml");
String content = page.getWebResponse().getContentAsString("UTF-8");
String content = page.getWebResponse().getContentAsString(StandardCharsets.UTF_8);
assertThat(content, containsString("temporaryOfflineCause"));
assertThat(content, containsString("<userId>username</userId>"));
assertThat(content, not(containsString("ApiTokenProperty")));
......
......@@ -25,6 +25,7 @@ package hudson.model;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.javascript.host.event.Event;
import hudson.*;
import hudson.model.queue.QueueTaskFuture;
import hudson.security.AccessDeniedException2;
......@@ -252,7 +253,8 @@ public class ProjectTest {
assertEquals("Scm retry count should be the same as global scm retry count.", 6, p.getScmCheckoutRetryCount());
HtmlForm form = j.createWebClient().goTo(p.getUrl() + "/configure").getFormByName("config");
((HtmlElement)form.getByXPath("//div[@class='advancedLink']//button").get(0)).click();
form.getInputByName("hasCustomScmCheckoutRetryCount").click();
// required due to the new default behavior of click
form.getInputByName("hasCustomScmCheckoutRetryCount").click(new Event(), true);
form.getInputByName("scmCheckoutRetryCount").setValueAttribute("7");
j.submit(form);
assertEquals("Scm retry count was set.", 7, p.getScmCheckoutRetryCount());
......
......@@ -246,7 +246,7 @@ public class ViewTest {
ListView view = listView("v");
view.description = "one";
WebClient wc = j.createWebClient();
String xml = wc.goToXml("view/v/config.xml").getContent();
String xml = wc.goToXml("view/v/config.xml").getWebResponse().getContentAsString();
assertTrue(xml, xml.contains("<description>one</description>"));
xml = xml.replace("<description>one</description>", "<description>two</description>");
WebRequest req = new WebRequest(wc.createCrumbedUrl("view/v/config.xml"), HttpMethod.POST);
......
......@@ -24,7 +24,6 @@
package hudson.tools;
import com.gargoylesoftware.htmlunit.HttpMethod;
import com.gargoylesoftware.htmlunit.InteractivePage;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
......@@ -148,7 +147,7 @@ public class ZipExtractionInstallerTest {
}
@Override
public Object callFunction(InteractivePage page, Function function, Scriptable scope, Scriptable thisObject, Object[] args) {
public Object callFunction(HtmlPage page, Function function, Scriptable scope, Scriptable thisObject, Object[] args) {
if (thisObject instanceof XMLHttpRequest) {
try {
WebRequest request = getPrivateWebRequestField((XMLHttpRequest) thisObject);
......
......@@ -41,7 +41,10 @@ public class Jenkins19124Test {
JenkinsRule.WebClient wc = j.createWebClient();
HtmlPage c = wc.getPage(p, "configure");
HtmlTextInput alpha = c.getElementByName("_.alpha");
// the fireEvent is required as setValueAttribute's new behavior is not triggering the onChange event anymore
alpha.setValueAttribute("hello");
alpha.fireEvent("change");
WebClientUtil.waitForJSExec(wc);
assertEquals("hello", d.alpha);
assertEquals("2", d.bravo);
......
......@@ -11,7 +11,6 @@ import hudson.Util;
import hudson.util.Secret;
import hudson.util.SecretHelper;
import org.apache.commons.io.FileUtils;
import org.hamcrest.CoreMatchers;
import org.jvnet.hudson.test.HudsonTestCase;
import org.jvnet.hudson.test.recipes.Recipe.Runner;
import org.xml.sax.SAXException;
......@@ -22,8 +21,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.regex.Pattern;
import static org.junit.Assert.assertThat;
import java.util.stream.Stream;
/**
* @author Kohsuke Kawaguchi
......@@ -132,7 +130,18 @@ public class RekeySecretAdminMonitorTest extends HudsonTestCase {
}
private HtmlButton getButton(HtmlForm form, int index) {
return form.<HtmlButton>getHtmlElementsByTagName("button").get(index);
// due to the removal of method HtmlElement.getHtmlElementsByTagName
Stream<HtmlButton> buttonStream = form.getElementsByTagName("button").stream()
.filter(HtmlButton.class::isInstance)
.map(HtmlButton.class::cast);
if (index > 0) {
buttonStream = buttonStream.skip(index - 1);
}
return buttonStream
.findFirst()
.orElse(null);
}
public void testScanOnBoot() throws Exception {
......
......@@ -148,7 +148,7 @@ public class PasswordTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String pName = p.getFullName();
getJobCommand.main(Collections.singletonList(pName), Locale.ENGLISH, System.in, new PrintStream(baos), System.err);
assertEquals(xmlAdmin, baos.toString(configXml.getWebResponse().getContentCharset()));
assertEquals(xmlAdmin, baos.toString(configXml.getWebResponse().getContentCharset().name()));
CopyJobCommand copyJobCommand = new CopyJobCommand();
copyJobCommand.setTransportAuth(adminAuth);
String pAdminName = pName + "-admin";
......@@ -171,7 +171,7 @@ public class PasswordTest {
getJobCommand.setTransportAuth(devAuth);
baos = new ByteArrayOutputStream();
getJobCommand.main(Collections.singletonList(pName), Locale.ENGLISH, System.in, new PrintStream(baos), System.err);
assertEquals(xmlDev, baos.toString(configXml.getWebResponse().getContentCharset()));
assertEquals(xmlDev, baos.toString(configXml.getWebResponse().getContentCharset().name()));
copyJobCommand = new CopyJobCommand();
copyJobCommand.setTransportAuth(devAuth);
String pDevName = pName + "-dev";
......@@ -194,7 +194,9 @@ public class PasswordTest {
}
VulnerableProperty.DescriptorImpl.incomingURL = null;
String secret = "s3cr3t";
// the fireEvent is required as setText's new behavior is not triggering the onChange event anymore
field.setText(secret);
field.fireEvent("change");
while (VulnerableProperty.DescriptorImpl.incomingURL == null) {
Thread.sleep(100); // form validation of edited value
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册