diff --git a/test-pom/pom.xml b/test-pom/pom.xml index dbbda4bf2acb7d06b8d1c1283f8c768fdae03e7f..375f3ee1e44472ca2b627640eaffa9e68d5fba9a 100644 --- a/test-pom/pom.xml +++ b/test-pom/pom.xml @@ -54,7 +54,7 @@ THE SOFTWARE. ${project.groupId} jenkins-test-harness - 2.41.1 + 2.42 test diff --git a/test/src/test/java/hudson/model/ComputerTest.java b/test/src/test/java/hudson/model/ComputerTest.java index 8502a8983271750597c0141333726c77ede143aa..09119e01658df0570500c976cf18c76acf0613f9 100644 --- a/test/src/test/java/hudson/model/ComputerTest.java +++ b/test/src/test/java/hudson/model/ComputerTest.java @@ -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("username")); assertThat(content, not(containsString("ApiTokenProperty"))); diff --git a/test/src/test/java/hudson/model/ProjectTest.java b/test/src/test/java/hudson/model/ProjectTest.java index f966f4e56b967e13039b0613e6a2651e2f4ee52f..662807588d3bf27bdcb479fe3ef45d1cc1b6eb0f 100644 --- a/test/src/test/java/hudson/model/ProjectTest.java +++ b/test/src/test/java/hudson/model/ProjectTest.java @@ -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()); diff --git a/test/src/test/java/hudson/model/ViewTest.java b/test/src/test/java/hudson/model/ViewTest.java index 3d73a15d6d3262afaf561f45a92d4045cd7682d6..e7099a410072bb1e2ac55ffd15fdc8af19e62a2f 100644 --- a/test/src/test/java/hudson/model/ViewTest.java +++ b/test/src/test/java/hudson/model/ViewTest.java @@ -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("one")); xml = xml.replace("one", "two"); WebRequest req = new WebRequest(wc.createCrumbedUrl("view/v/config.xml"), HttpMethod.POST); diff --git a/test/src/test/java/hudson/tools/ZipExtractionInstallerTest.java b/test/src/test/java/hudson/tools/ZipExtractionInstallerTest.java index e1e882d10f01231c669a186a4d33ac9f6a7320ca..7663efdc93f6551d9a22f942e8f6523b1a95c44a 100644 --- a/test/src/test/java/hudson/tools/ZipExtractionInstallerTest.java +++ b/test/src/test/java/hudson/tools/ZipExtractionInstallerTest.java @@ -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); diff --git a/test/src/test/java/jenkins/bugs/Jenkins19124Test.java b/test/src/test/java/jenkins/bugs/Jenkins19124Test.java index 4f976f85bacedc3a93cb669fcf713d2fca2aff7a..4a66ffe7d1e6d4568219c21edcb01e6995ec1509 100644 --- a/test/src/test/java/jenkins/bugs/Jenkins19124Test.java +++ b/test/src/test/java/jenkins/bugs/Jenkins19124Test.java @@ -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); diff --git a/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java b/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java index 413b4a6eed3df74be40ca37d788a78d3ddfff6a3..5ce5f1b1695dd2e833f7ae29c343943cbfbd7c99 100644 --- a/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java +++ b/test/src/test/java/jenkins/security/RekeySecretAdminMonitorTest.java @@ -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.getHtmlElementsByTagName("button").get(index); + // due to the removal of method HtmlElement.getHtmlElementsByTagName + Stream 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 { diff --git a/test/src/test/java/lib/form/PasswordTest.java b/test/src/test/java/lib/form/PasswordTest.java index 316fdb20d34b4671e476b467e3764e462e3f2106..198b7b5254c85a1b575c6b012746ee1065ad6bed 100644 --- a/test/src/test/java/lib/form/PasswordTest.java +++ b/test/src/test/java/lib/form/PasswordTest.java @@ -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 }