提交 dbe24a85 编写于 作者: J Jesse Glick

Using CLICommandInvoker in cases where we did not actually need to be testing Remoting-based CLI.

上级 94d5f96d
......@@ -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();
......
......@@ -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
......
......@@ -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(("<project><actions/><builders/><publishers/>"
+ "<buildWrappers/></project>").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(("<project><actions/><builders/><publishers/><buildWrappers/></project>").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());
}
}
......@@ -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());
......
......@@ -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 {
......
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册