提交 5531c112 编写于 作者: J Jesse Glick

JUnit 4.

上级 61e4f6f5
...@@ -23,7 +23,10 @@ ...@@ -23,7 +23,10 @@
*/ */
package hudson.cli package hudson.cli
import org.jvnet.hudson.test.HudsonTestCase import org.jvnet.hudson.test.JenkinsRule
import org.junit.Rule
import org.junit.Test
import static org.junit.Assert.*
import hudson.tasks.Shell import hudson.tasks.Shell
import hudson.util.OneShotEvent import hudson.util.OneShotEvent
import org.jvnet.hudson.test.TestBuilder import org.jvnet.hudson.test.TestBuilder
...@@ -40,12 +43,15 @@ import org.apache.commons.io.output.TeeOutputStream ...@@ -40,12 +43,15 @@ import org.apache.commons.io.output.TeeOutputStream
* *
* @author Kohsuke Kawaguchi * @author Kohsuke Kawaguchi
*/ */
public class BuildCommandTest extends HudsonTestCase { public class BuildCommandTest {
@Rule public JenkinsRule j = new JenkinsRule();
/** /**
* Just schedules a build and return. * Just schedules a build and return.
*/ */
void testAsync() { @Test void async() {
def p = createFreeStyleProject(); def p = j.createFreeStyleProject();
def started = new OneShotEvent(); def started = new OneShotEvent();
def completed = new OneShotEvent(); def completed = new OneShotEvent();
p.buildersList.add([perform: {AbstractBuild build, Launcher launcher, BuildListener listener -> p.buildersList.add([perform: {AbstractBuild build, Launcher launcher, BuildListener listener ->
...@@ -55,7 +61,7 @@ public class BuildCommandTest extends HudsonTestCase { ...@@ -55,7 +61,7 @@ public class BuildCommandTest extends HudsonTestCase {
}] as TestBuilder); }] as TestBuilder);
// this should be asynchronous // this should be asynchronous
def cli = new CLI(getURL()) def cli = new CLI(j.URL)
try { try {
assertEquals(0,cli.execute(["build", p.name])) assertEquals(0,cli.execute(["build", p.name]))
started.block() started.block()
...@@ -70,11 +76,11 @@ public class BuildCommandTest extends HudsonTestCase { ...@@ -70,11 +76,11 @@ public class BuildCommandTest extends HudsonTestCase {
/** /**
* Tests synchronous execution. * Tests synchronous execution.
*/ */
void testSync() { @Test void sync() {
def p = createFreeStyleProject(); def p = j.createFreeStyleProject();
p.buildersList.add(new Shell("sleep 3")); p.buildersList.add(new Shell("sleep 3"));
def cli = new CLI(getURL()) def cli = new CLI(j.URL)
try { try {
cli.execute(["build","-s",p.name]) cli.execute(["build","-s",p.name])
assertFalse(p.getBuildByNumber(1).isBuilding()) assertFalse(p.getBuildByNumber(1).isBuilding())
...@@ -87,11 +93,11 @@ public class BuildCommandTest extends HudsonTestCase { ...@@ -87,11 +93,11 @@ public class BuildCommandTest extends HudsonTestCase {
/** /**
* Tests synchronous execution with retried verbose output * Tests synchronous execution with retried verbose output
*/ */
void testSyncWOutputStreaming() { @Test void syncWOutputStreaming() {
def p = createFreeStyleProject(); def p = j.createFreeStyleProject();
p.buildersList.add(new Shell("sleep 3")); p.buildersList.add(new Shell("sleep 3"));
def cli =new CLI(getURL()) def cli =new CLI(j.URL)
try { try {
cli.execute(["build","-s","-v","-r","5",p.name]) cli.execute(["build","-s","-v","-r","5",p.name])
assertFalse(p.getBuildByNumber(1).isBuilding()) assertFalse(p.getBuildByNumber(1).isBuilding())
...@@ -100,28 +106,28 @@ public class BuildCommandTest extends HudsonTestCase { ...@@ -100,28 +106,28 @@ public class BuildCommandTest extends HudsonTestCase {
} }
} }
void testParameters() { @Test void parameters() {
def p = createFreeStyleProject(); def p = j.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty([new StringParameterDefinition("key",null)])); p.addProperty(new ParametersDefinitionProperty([new StringParameterDefinition("key",null)]));
def cli = new CLI(getURL()) def cli = new CLI(j.URL)
try { try {
cli.execute(["build","-s","-p","key=foobar",p.name]) cli.execute(["build","-s","-p","key=foobar",p.name])
def b = assertBuildStatusSuccess(p.getBuildByNumber(1)) def b = j.assertBuildStatusSuccess(p.getBuildByNumber(1))
assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value) assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value)
} finally { } finally {
cli.close(); cli.close();
} }
} }
void testDefaultParameters() { @Test void defaultParameters() {
def p = createFreeStyleProject(); def p = j.createFreeStyleProject();
p.addProperty(new ParametersDefinitionProperty([new StringParameterDefinition("key","default"), new StringParameterDefinition("key2","default2") ])); p.addProperty(new ParametersDefinitionProperty([new StringParameterDefinition("key","default"), new StringParameterDefinition("key2","default2") ]));
def cli = new CLI(getURL()) def cli = new CLI(j.URL)
try { try {
cli.execute(["build","-s","-p","key=foobar",p.name]) cli.execute(["build","-s","-p","key=foobar",p.name])
def b = assertBuildStatusSuccess(p.getBuildByNumber(1)) def b = j.assertBuildStatusSuccess(p.getBuildByNumber(1))
assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value) assertEquals("foobar",b.getAction(ParametersAction.class).getParameter("key").value)
assertEquals("default2",b.getAction(ParametersAction.class).getParameter("key2").value) assertEquals("default2",b.getAction(ParametersAction.class).getParameter("key2").value)
} finally { } finally {
...@@ -129,13 +135,13 @@ public class BuildCommandTest extends HudsonTestCase { ...@@ -129,13 +135,13 @@ public class BuildCommandTest extends HudsonTestCase {
} }
} }
void testConsoleOutput() { @Test void consoleOutput() {
def p = createFreeStyleProject() def p = j.createFreeStyleProject()
def cli = new CLI(getURL()) def cli = new CLI(j.URL)
try { try {
def o = new ByteArrayOutputStream() def o = new ByteArrayOutputStream()
cli.execute(["build","-s","-v",p.name],System.in,new TeeOutputStream(System.out,o),System.err) cli.execute(["build","-s","-v",p.name],System.in,new TeeOutputStream(System.out,o),System.err)
assertBuildStatusSuccess(p.getBuildByNumber(1)) j.assertBuildStatusSuccess(p.getBuildByNumber(1))
assertTrue(o.toString(), o.toString().contains("Started by command line by anonymous")) assertTrue(o.toString(), o.toString().contains("Started by command line by anonymous"))
assertTrue(o.toString().contains("Finished: SUCCESS")) assertTrue(o.toString().contains("Finished: SUCCESS"))
} finally { } finally {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册