提交 5b5cf3a1 编写于 作者: K kohsuke

Added the first test case for Hudson CLI.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@21320 71c3de6d-444a-0410-be80-ed276b4c234a
上级 d934a5da
......@@ -128,6 +128,14 @@ public class CLI {
new RemoteOutputStream(stderr));
}
public int execute(List<String> args) {
return execute(args,System.in,System.out,System.err);
}
public int execute(String... args) {
return execute(Arrays.asList(args));
}
public static void main(final String[] _args) throws Exception {
List<String> args = Arrays.asList(_args);
......
......@@ -57,7 +57,6 @@ import hudson.model.RootAction;
import hudson.model.UpdateCenter.UpdateCenterConfiguration;
import hudson.model.Node.Mode;
import hudson.security.csrf.CrumbIssuer;
import hudson.security.csrf.CrumbIssuerDescriptor;
import hudson.slaves.CommandLauncher;
import hudson.slaves.DumbSlave;
import hudson.slaves.RetentionStrategy;
......@@ -115,7 +114,6 @@ import org.kohsuke.stapler.MetaClass;
import org.kohsuke.stapler.MetaClassLoader;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.Stapler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.security.HashUserRealm;
......@@ -483,7 +481,15 @@ public abstract class HudsonTestCase extends TestCase {
public DumbSlave createSlave(Label l) throws Exception {
return createSlave(l, null);
}
/**
* Returns the URL of the webapp top page.
* URL ends with '/'.
*/
public URL getURL() throws IOException {
return new URL("http://localhost:"+localPort+contextPath+"/");
}
/**
* Creates a slave with certain additional environment variables
*/
......@@ -1022,8 +1028,8 @@ public abstract class HudsonTestCase extends TestCase {
* Returns the URL of the webapp top page.
* URL ends with '/'.
*/
public String getContextPath() {
return "http://localhost:"+localPort+contextPath+"/";
public String getContextPath() throws IOException {
return getURL().toExternalForm();
}
/**
......@@ -1042,7 +1048,7 @@ public abstract class HudsonTestCase extends TestCase {
/**
* Creates a URL with crumb parameters relative to {{@link #getContextPath()}
*/
public URL createCrumbedUrl(String relativePath) throws MalformedURLException {
public URL createCrumbedUrl(String relativePath) throws IOException {
CrumbIssuer issuer = hudson.getCrumbIssuer();
String crumbName = issuer.getDescriptor().getCrumbRequestField();
String crumb = issuer.getCrumb(null);
......
package hudson.cli
import org.jvnet.hudson.test.HudsonTestCase
/**
*
*
* @author Kohsuke Kawaguchi
*/
public class EnableJobCommandTest extends HudsonTestCase {
void test1() {
def p = createFreeStyleProject();
def cli = new CLI(getURL())
cli.execute(["disable-job",p.name])
assertTrue(p.disabled)
cli.execute(["enable-job",p.name])
assertFalse(p.disabled)
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册