diff --git a/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SampleIntegrationTests.java b/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SampleIntegrationTests.java index c7c4e3086e..004adcc654 100644 --- a/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SampleIntegrationTests.java +++ b/spring-bootstrap-cli/src/test/java/org/springframework/bootstrap/cli/SampleIntegrationTests.java @@ -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 future = Executors.newSingleThreadExecutor().submit( new Callable() { @@ -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")); } } diff --git a/spring-bootstrap-samples/spring-bootstrap-simple-sample/src/test/java/org/springframework/bootstrap/sample/simple/SimpleBootstrapApplicationTests.java b/spring-bootstrap-samples/spring-bootstrap-simple-sample/src/test/java/org/springframework/bootstrap/sample/simple/SimpleBootstrapApplicationTests.java index e18924e6d5..e0a33f5785 100644 --- a/spring-bootstrap-samples/spring-bootstrap-simple-sample/src/test/java/org/springframework/bootstrap/sample/simple/SimpleBootstrapApplicationTests.java +++ b/spring-bootstrap-samples/spring-bootstrap-simple-sample/src/test/java/org/springframework/bootstrap/sample/simple/SimpleBootstrapApplicationTests.java @@ -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