[bs-62] Add assertions to CLI integration tests

[Fixes #48658503]
pull/1/merge
Dave Syer 12 years ago
parent bcf86b320e
commit 61fa55b524

@ -15,15 +15,23 @@
*/
package org.springframework.bootstrap.cli;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.apache.ivy.util.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer
*
@ -32,6 +40,25 @@ public class SampleIntegrationTests {
private RunCommand command;
private PrintStream savedOutput;
private ByteArrayOutputStream output;
@Before
public void init() {
this.savedOutput = System.out;
this.output = new ByteArrayOutputStream();
System.setOut(new PrintStream(this.output));
}
@After
public void clear() {
System.setOut(this.savedOutput);
}
private String getOutput() {
return this.output.toString();
}
private void start(final String sample) throws Exception {
Future<RunCommand> future = Executors.newSingleThreadExecutor().submit(
new Callable<RunCommand>() {
@ -61,26 +88,39 @@ public class SampleIntegrationTests {
@Test
public void appSample() throws Exception {
start("samples/app.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello World"));
}
@Test
public void jobSample() throws Exception {
start("samples/job.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output,
output.contains("completed with the following parameters"));
}
@Test
public void webSample() throws Exception {
start("samples/web.groovy");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertEquals("World!", result);
}
@Test
public void serviceSample() throws Exception {
start("samples/service.groovy");
String result = FileUtil.readEntirely(new URL("http://localhost:8080")
.openStream());
assertEquals("{\"message\":\"Hello World!\"}", result);
}
@Test
public void integrationSample() throws Exception {
start("samples/integration.groovy");
String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello, World"));
}
}

@ -4,28 +4,22 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class SimpleBootstrapApplicationTests {
private static PrintStream savedOutput;
private static ByteArrayOutputStream output;
private PrintStream savedOutput;
private ByteArrayOutputStream output;
private String profiles;
@BeforeClass
public static void init() {
savedOutput = System.out;
output = new ByteArrayOutputStream();
System.setOut(new PrintStream(output));
}
@Before
public void before() {
public void init() {
this.savedOutput = System.out;
this.output = new ByteArrayOutputStream();
System.setOut(new PrintStream(this.output));
this.profiles = System.getProperty("spring.profiles.active");
}
@ -36,15 +30,11 @@ public class SimpleBootstrapApplicationTests {
} else {
System.clearProperty("spring.profiles.active");
}
System.setOut(this.savedOutput);
}
@AfterClass
public static void clear() {
System.setOut(savedOutput);
}
private static String getOutput() {
return output.toString();
private String getOutput() {
return this.output.toString();
}
@Test

Loading…
Cancel
Save