diff --git a/test/src/test/java/hudson/cli/CLIActionTest.java b/test/src/test/java/hudson/cli/CLIActionTest.java index 7333c3418b8a816cbdac4a42ade939b27ae6db30..6aa84782750f5e8fd9fe7e88360e58018f98b093 100644 --- a/test/src/test/java/hudson/cli/CLIActionTest.java +++ b/test/src/test/java/hudson/cli/CLIActionTest.java @@ -87,7 +87,7 @@ public class CLIActionTest { } - @SuppressWarnings({"unchecked", "rawtypes"}) // intentionally passing an unreifiable argument here + @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) // intentionally passing an unreifiable argument here; Remoting-based constructor intentional @Test public void security218_take2() throws Exception { pool = Executors.newCachedThreadPool(); diff --git a/test/src/test/java/hudson/model/ComputerSetTest.java b/test/src/test/java/hudson/model/ComputerSetTest.java index 56878bf4cda64f08e3b3bdfeedffb893aadb3734..38418e9cc00cc175a3bb909f3ca3e0ab7bb95e84 100644 --- a/test/src/test/java/hudson/model/ComputerSetTest.java +++ b/test/src/test/java/hudson/model/ComputerSetTest.java @@ -23,18 +23,13 @@ */ package hudson.model; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertTrue; - -import hudson.cli.CLI; +import com.gargoylesoftware.htmlunit.html.HtmlForm; +import hudson.cli.CLICommandInvoker; import hudson.slaves.DumbSlave; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; import org.junit.Rule; import org.junit.Test; -import com.gargoylesoftware.htmlunit.html.HtmlForm; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; import org.jvnet.hudson.test.JenkinsRule.WebClient; @@ -69,14 +64,12 @@ public class ComputerSetTest { public void nodeOfflineCli() throws Exception { DumbSlave s = j.createSlave(); - try (CLI cli = new CLI(j.getURL())) { - assertTrue(cli.execute("wait-node-offline","xxx")!=0); - assertTrue(cli.execute("wait-node-online",s.getNodeName())==0); + assertThat(new CLICommandInvoker(j, "wait-node-offline").invokeWithArgs("xxx"), CLICommandInvoker.Matcher.failedWith(/* IllegalArgumentException from NodeOptionHandler */ 3)); + assertThat(new CLICommandInvoker(j, "wait-node-online").invokeWithArgs(s.getNodeName()), CLICommandInvoker.Matcher.succeededSilently()); - s.toComputer().disconnect().get(); + s.toComputer().disconnect(null).get(); - assertTrue(cli.execute("wait-node-offline",s.getNodeName())==0); - } + assertThat(new CLICommandInvoker(j, "wait-node-offline").invokeWithArgs(s.getNodeName()), CLICommandInvoker.Matcher.succeededSilently()); } @Test diff --git a/test/src/test/java/hudson/model/listeners/ItemListenerTest.java b/test/src/test/java/hudson/model/listeners/ItemListenerTest.java index bf19e6ea0d513c78cdf55a9301f05cb01d3a41c0..85d3160154a9fcc2a9c4df416b96181506f8c08b 100644 --- a/test/src/test/java/hudson/model/listeners/ItemListenerTest.java +++ b/test/src/test/java/hudson/model/listeners/ItemListenerTest.java @@ -23,21 +23,15 @@ */ package hudson.model.listeners; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import hudson.cli.CLI; +import hudson.cli.CLICommandInvoker; import hudson.model.Item; +import java.io.ByteArrayInputStream; +import static org.junit.Assert.*; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.util.Arrays; - /** * Tests for ItemListener events. * @author Alan.Harder@sun.com @@ -64,16 +58,11 @@ public class ItemListenerTest { @Test public void onCreatedViaCLI() throws Exception { - ByteArrayOutputStream buf = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(buf); - try (CLI cli = new CLI(j.getURL())) { - cli.execute(Arrays.asList("create-job", "testJob"), - new ByteArrayInputStream(("" - + "").getBytes()), - out, out); - out.flush(); - assertNotNull("job should be created: " + buf, j.jenkins.getItem("testJob")); - assertEquals("onCreated event should be triggered: " + buf, "C", events.toString()); - } + CLICommandInvoker.Result result = new CLICommandInvoker(j, "create-job"). + withStdin(new ByteArrayInputStream(("").getBytes())). + invokeWithArgs("testJob"); + assertThat(result, CLICommandInvoker.Matcher.succeeded()); + assertNotNull("job should be created: " + result, j.jenkins.getItem("testJob")); + assertEquals("onCreated event should be triggered: " + result, "C", events.toString()); } } diff --git a/test/src/test/java/hudson/security/CliAuthenticationTest.java b/test/src/test/java/hudson/security/CliAuthenticationTest.java index 52b17fc9ebfe3bb4bf1906ff276a4b0c9ffe3acc..bdddf14407b1058805b1ed8b0b86832846ebf424 100644 --- a/test/src/test/java/hudson/security/CliAuthenticationTest.java +++ b/test/src/test/java/hudson/security/CliAuthenticationTest.java @@ -7,9 +7,6 @@ import static org.junit.Assert.assertTrue; import hudson.cli.CLI; import hudson.cli.CLICommand; -import hudson.cli.ClientAuthenticationCache; -import hudson.cli.LoginCommand; -import hudson.cli.LogoutCommand; import jenkins.model.Jenkins; import org.acegisecurity.Authentication; import org.apache.commons.io.input.NullInputStream; @@ -25,6 +22,7 @@ import java.util.Arrays; /** * @author Kohsuke Kawaguchi */ +@SuppressWarnings("deprecation") // Remoting-based CLI usages intentional public class CliAuthenticationTest { @Rule @@ -88,7 +86,7 @@ public class CliAuthenticationTest { } @Test - @For({LoginCommand.class, LogoutCommand.class, ClientAuthenticationCache.class}) + @For({hudson.cli.LoginCommand.class, hudson.cli.LogoutCommand.class, hudson.cli.ClientAuthenticationCache.class}) public void login() throws Exception { j.jenkins.setSecurityRealm(j.createDummySecurityRealm()); diff --git a/test/src/test/java/jenkins/security/Security218BlackBoxTest.java b/test/src/test/java/jenkins/security/Security218BlackBoxTest.java index 4776ee92e42bf627a844c5b5567352fe7e0137a3..05bd4069d7cdaf3fed9f5b9117a03fa7426ac44f 100644 --- a/test/src/test/java/jenkins/security/Security218BlackBoxTest.java +++ b/test/src/test/java/jenkins/security/Security218BlackBoxTest.java @@ -85,7 +85,7 @@ public class Security218BlackBoxTest { @Rule public JenkinsRule r = new JenkinsRule(); - @SuppressWarnings("deprecation") // really mean to use getPage(String) + @SuppressWarnings("deprecation") // really mean to use getPage(String), and Remoting-based CLI @PresetData(PresetData.DataSet.ANONYMOUS_READONLY) // TODO userContent inaccessible without authentication otherwise @Test public void probe() throws Exception { diff --git a/test/src/test/java/jenkins/security/Security218CliTest.java b/test/src/test/java/jenkins/security/Security218CliTest.java index f9f39c4d46d3388a1039d6275c6d0d18f11161a0..cfa0002d7114389c8887a94c8218ff557d0bfc06 100644 --- a/test/src/test/java/jenkins/security/Security218CliTest.java +++ b/test/src/test/java/jenkins/security/Security218CliTest.java @@ -41,6 +41,7 @@ import org.jvnet.hudson.test.TestExtension; import org.jvnet.hudson.test.recipes.PresetData; import org.kohsuke.args4j.Argument; +@SuppressWarnings("deprecation") // Remoting-based CLI usages intentional public class Security218CliTest { @Rule @@ -197,8 +198,8 @@ public class Security218CliTest { @Argument(metaVar = "command", usage = "Command to be launched by the payload", required = true, index = 1) public String command; - + @Override protected int run() throws Exception { Payload payloadItem = Payload.valueOf(this.payload); PayloadCaller callable = new PayloadCaller(payloadItem, command);