();
- if (file.isDirectory()) {
- for (File inDir : file.listFiles()) {
- files.addAll(recursiveList(inDir));
- }
- }
- files.add(file);
- return files;
- }
-
- /**
- * Copies the data read from the given {@code source} {@link URL} to the given
- * {@code target} {@link File}.
- * @param source The source to copy from
- * @param target The target to copy to
- */
- public static void copy(URL source, File target) {
- InputStream input = null;
- OutputStream output = null;
- try {
- input = source.openStream();
- output = new FileOutputStream(target);
- IoUtils.copy(input, output);
- }
- catch (IOException ex) {
- throw new IllegalStateException("Failed to copy '" + source + "' to '"
- + target + "'", ex);
- }
- finally {
- IoUtils.closeQuietly(input, output);
- }
- }
-}
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/IoUtils.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/IoUtils.java
deleted file mode 100644
index 3882ba88fe9..00000000000
--- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/util/IoUtils.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright 2012-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.cli.util;
-
-import java.io.BufferedReader;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.URI;
-
-/**
- * General IO utility methods
- *
- * @author Andy Wilkinson
- */
-public class IoUtils {
-
- private IoUtils() {
-
- }
-
- /**
- * Reads the entire contents of the resource referenced by {@code uri} and returns
- * them as a String.
- * @param uri The resource to read
- * @return The contents of the resource
- */
- public static String readEntirely(String uri) {
- try {
- InputStream stream = URI.create(uri).toURL().openStream();
- BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
- String line;
- StringBuilder result = new StringBuilder();
- while ((line = reader.readLine()) != null) {
- result.append(line);
- }
- return result.toString();
- }
- catch (Exception ex) {
- throw new IllegalStateException(ex);
- }
- }
-
- /**
- * Copies the data read from {@code input} into {@code output}.
- *
- * Note: it is the caller's responsibility to close the streams
- * @param input The stream to read data from
- * @param output The stream to write data to
- * @throws IOException if the copy fails
- */
- public static void copy(InputStream input, OutputStream output) throws IOException {
- byte[] buffer = new byte[4096];
- int read;
- while ((read = input.read(buffer)) >= 0) {
- output.write(buffer, 0, read);
- }
- }
-
- /**
- * Quietly closes the given {@link Closeable Closeables}. Any exceptions thrown by
- * {@link Closeable#close() close()} are swallowed. Any {@code null}
- * {@code Closeables} are ignored.
- * @param closeables The {@link Closeable closeables} to close
- */
- public static void closeQuietly(Closeable... closeables) {
- for (Closeable closeable : closeables) {
- if (closeable != null) {
- try {
- closeable.close();
- }
- catch (IOException ioe) {
- // Closing quietly
- }
- }
- }
-
- }
-}
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java
new file mode 100644
index 00000000000..09eb0c32658
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.groovy;
+
+import org.junit.internal.TextListener;
+import org.junit.runner.JUnitCore;
+import org.springframework.boot.cli.testrunner.TestRunner;
+
+/**
+ * Delegate test runner to launch tests in user application classpath.
+ *
+ * @author Phillip Webb
+ * @see TestRunner
+ */
+public class DelegateTestRunner {
+
+ public static void run(Class>[] testClasses) {
+ JUnitCore jUnitCore = new JUnitCore();
+ jUnitCore.addListener(new TextListener(System.out));
+ jUnitCore.run(testClasses);
+ }
+
+}
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableDeviceResolver.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableDeviceResolver.java
new file mode 100644
index 00000000000..e8c3075843b
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableDeviceResolver.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.groovy;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface EnableDeviceResolver {
+
+}
\ No newline at end of file
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableIntegrationPatterns.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableIntegrationPatterns.java
new file mode 100644
index 00000000000..ff40972ecf0
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableIntegrationPatterns.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.groovy;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface EnableIntegrationPatterns {
+
+}
\ No newline at end of file
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableJmsMessaging.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableJmsMessaging.java
new file mode 100644
index 00000000000..0a40997b819
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/EnableJmsMessaging.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.groovy;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface EnableJmsMessaging {
+
+}
\ No newline at end of file
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/template/GroovyTemplate.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/GroovyTemplate.java
similarity index 73%
rename from spring-boot-cli/src/main/java/org/springframework/boot/cli/template/GroovyTemplate.java
rename to spring-boot-cli/src/main/java/org/springframework/boot/groovy/GroovyTemplate.java
index a253497922f..b9d7fd3bf23 100644
--- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/template/GroovyTemplate.java
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/GroovyTemplate.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.cli.template;
+package org.springframework.boot.groovy;
import groovy.text.GStringTemplateEngine;
import groovy.text.Template;
@@ -39,23 +39,25 @@ public abstract class GroovyTemplate {
public static String template(String name, Map model) throws IOException,
CompilationFailedException, ClassNotFoundException {
+ return getTemplate(name).make(model).toString();
+ }
+
+ private static Template getTemplate(String name) throws CompilationFailedException,
+ ClassNotFoundException, IOException {
GStringTemplateEngine engine = new GStringTemplateEngine();
+
File file = new File("templates", name);
- URL resource = GroovyTemplate.class.getClassLoader().getResource(
- "templates/" + name);
- Template template;
if (file.exists()) {
- template = engine.createTemplate(file);
+ return engine.createTemplate(file);
}
- else {
- if (resource != null) {
- template = engine.createTemplate(resource);
- }
- else {
- template = engine.createTemplate(name);
- }
+
+ ClassLoader classLoader = GroovyTemplate.class.getClassLoader();
+ URL resource = classLoader.getResource("templates/" + name);
+ if (resource != null) {
+ return engine.createTemplate(resource);
}
- return template.make(model).toString();
+
+ return engine.createTemplate(name);
}
}
diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/package-info.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/package-info.java
new file mode 100644
index 00000000000..c0cfd3ca8cd
--- /dev/null
+++ b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Groovy util classes that are "shared" between the CLI and user applications. Classes is
+ * this package can be loaded from compiled user code. Not under the cli package in case
+ * we want to extract into a separate jar at a future date.
+ */
+package org.springframework.boot.groovy;
+
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/ClassLoaderIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/ClassLoaderIntegrationTests.java
new file mode 100644
index 00000000000..37c53341fca
--- /dev/null
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/ClassLoaderIntegrationTests.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.cli;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for CLI Classloader issues.
+ *
+ * @author Phillip Webb
+ */
+public class ClassLoaderIntegrationTests {
+
+ @Rule
+ public CliTester cli = new CliTester();
+
+ @Test
+ public void runWithIsolatedClassLoader() throws Exception {
+ // CLI classes or dependencies should not be exposed to the app
+ String output = this.cli.run("src/test/resources/classloader-test-app.groovy",
+ SpringCli.class.getName());
+ assertThat(output, containsString("HasClasses-false-true-false"));
+ }
+}
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java
index 5b9a0a53215..66559f468fc 100644
--- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java
@@ -27,8 +27,10 @@ import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.springframework.boot.OutputCapture;
+import org.springframework.boot.cli.command.AbstractCommand;
import org.springframework.boot.cli.command.CleanCommand;
import org.springframework.boot.cli.command.RunCommand;
+import org.springframework.boot.cli.command.TestCommand;
/**
* {@link TestRule} that can be used to invoke CLI commands.
@@ -41,7 +43,7 @@ public class CliTester implements TestRule {
private long timeout = TimeUnit.MINUTES.toMillis(6);
- private List commands = new ArrayList();
+ private List commands = new ArrayList();
public void setTimeout(long timeout) {
this.timeout = timeout;
@@ -61,6 +63,20 @@ public class CliTester implements TestRule {
return getOutput();
}
+ public String test(final String... args) throws Exception {
+ Future future = Executors.newSingleThreadExecutor().submit(
+ new Callable() {
+ @Override
+ public TestCommand call() throws Exception {
+ TestCommand command = new TestCommand();
+ command.run(args);
+ return command;
+ }
+ });
+ this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS));
+ return getOutput();
+ }
+
public String getOutput() {
return this.outputCapture.toString();
}
@@ -87,9 +103,9 @@ public class CliTester implements TestRule {
this.base.evaluate();
}
finally {
- for (RunCommand command : CliTester.this.commands) {
- if (command != null) {
- command.stop();
+ for (AbstractCommand command : CliTester.this.commands) {
+ if (command != null && command instanceof RunCommand) {
+ ((RunCommand) command).stop();
}
}
System.clearProperty("disableSpringSnapshotRepos");
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java
index 34efacf4328..0d3f173131a 100644
--- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/SampleIntegrationTests.java
@@ -16,14 +16,17 @@
package org.springframework.boot.cli;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URI;
+import org.codehaus.plexus.util.FileUtils;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
-import org.springframework.boot.cli.util.FileUtils;
-import org.springframework.boot.cli.util.IoUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -38,14 +41,14 @@ import static org.junit.Assert.assertTrue;
*/
public class SampleIntegrationTests {
+ @Rule
+ public CliTester cli = new CliTester();
+
@BeforeClass
public static void cleanGrapes() throws Exception {
GrapesCleaner.cleanIfNecessary();
}
- @Rule
- public CliTester cli = new CliTester();
-
@Test
public void appSample() throws Exception {
String output = this.cli.run("samples/app.groovy");
@@ -61,7 +64,6 @@ public class SampleIntegrationTests {
@Test
public void jobSample() throws Exception {
String output = this.cli.run("samples/job.groovy", "foo=bar");
- System.out.println(output);
assertTrue("Wrong output: " + output,
output.contains("completed with the following parameters"));
}
@@ -83,30 +85,30 @@ public class SampleIntegrationTests {
"foo=bar");
assertTrue("Wrong output: " + output,
output.contains("completed with the following parameters"));
- String result = IoUtils.readEntirely("http://localhost:8080");
+ String result = readEntirely("http://localhost:8080");
assertEquals("World!", result);
}
@Test
public void webSample() throws Exception {
this.cli.run("samples/web.groovy");
- String result = IoUtils.readEntirely("http://localhost:8080");
+ String result = readEntirely("http://localhost:8080");
assertEquals("World!", result);
}
@Test
public void uiSample() throws Exception {
this.cli.run("samples/ui.groovy", "--classpath=.:src/test/resources");
- String result = IoUtils.readEntirely("http://localhost:8080");
+ String result = readEntirely("http://localhost:8080");
assertTrue("Wrong output: " + result, result.contains("Hello World"));
- result = IoUtils.readEntirely("http://localhost:8080/css/bootstrap.min.css");
+ result = readEntirely("http://localhost:8080/css/bootstrap.min.css");
assertTrue("Wrong output: " + result, result.contains("container"));
}
@Test
public void actuatorSample() throws Exception {
this.cli.run("samples/actuator.groovy");
- String result = IoUtils.readEntirely("http://localhost:8080");
+ String result = readEntirely("http://localhost:8080");
assertEquals("{\"message\":\"Hello World!\"}", result);
}
@@ -139,7 +141,7 @@ public class SampleIntegrationTests {
String output = this.cli.run("samples/jms.groovy");
assertTrue("Wrong output: " + output,
output.contains("Received Greetings from Spring Boot via ActiveMQ"));
- FileUtils.recursiveDelete(new File("activemq-data")); // cleanup ActiveMQ cruft
+ FileUtils.deleteDirectory(new File("activemq-data"));// cleanup ActiveMQ cruft
}
@Test
@@ -154,8 +156,24 @@ public class SampleIntegrationTests {
@Test
public void deviceSample() throws Exception {
this.cli.run("samples/device.groovy");
- String result = IoUtils.readEntirely("http://localhost:8080");
+ String result = readEntirely("http://localhost:8080");
assertEquals("Hello Normal Device!", result);
}
+ private static String readEntirely(String uri) {
+ try {
+ InputStream stream = URI.create(uri).toURL().openStream();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
+ String line;
+ StringBuilder result = new StringBuilder();
+ while ((line = reader.readLine()) != null) {
+ result.append(line);
+ }
+ return result.toString();
+ }
+ catch (Exception ex) {
+ throw new IllegalStateException(ex);
+ }
+ }
+
}
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java
index 06dfee13b7c..41bb9414208 100644
--- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java
@@ -19,22 +19,29 @@ package org.springframework.boot.cli;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.springframework.boot.cli.command.CleanCommand;
import org.springframework.boot.cli.command.TestCommand;
-import org.springframework.boot.cli.command.tester.TestResults;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.hamcrest.Matchers.containsString;
+import static org.junit.Assert.assertThat;
/**
* Integration tests to exercise the CLI's test command.
*
* @author Greg Turnquist
+ * @author Phillip Webb
*/
public class TestCommandIntegrationTests {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Rule
+ public CliTester cli = new CliTester();
+
@BeforeClass
public static void cleanGrapes() throws Exception {
GrapesCleaner.cleanIfNecessary();
@@ -53,84 +60,53 @@ public class TestCommandIntegrationTests {
@Test
public void noTests() throws Throwable {
- TestCommand command = new TestCommand();
- command.run("test-samples/book.groovy");
- TestResults results = command.getResults();
- assertEquals(0, results.getRunCount());
- assertEquals(0, results.getFailureCount());
- assertTrue(results.wasSuccessful());
+ String output = this.cli.test("test-samples/book.groovy");
+ assertThat(output, containsString("No tests found"));
}
@Test
public void empty() throws Exception {
- TestCommand command = new TestCommand();
- command.run("test-samples/empty.groovy");
- TestResults results = command.getResults();
- assertEquals(0, results.getRunCount());
- assertEquals(0, results.getFailureCount());
- assertTrue(results.wasSuccessful());
+ String output = this.cli.test("test-samples/empty.groovy");
+ assertThat(output, containsString("No tests found"));
}
- @Test(expected = RuntimeException.class)
+ @Test
public void noFile() throws Exception {
- try {
- TestCommand command = new TestCommand();
- command.run("test-samples/nothing.groovy");
- }
- catch (RuntimeException ex) {
- assertEquals("Can't find test-samples/nothing.groovy", ex.getMessage());
- throw ex;
- }
+ TestCommand command = new TestCommand();
+ this.thrown.expect(RuntimeException.class);
+ this.thrown.expectMessage("Can't find test-samples/nothing.groovy");
+ command.run("test-samples/nothing.groovy");
}
@Test
public void appAndTestsInOneFile() throws Exception {
- TestCommand command = new TestCommand();
- command.run("test-samples/book_and_tests.groovy");
- TestResults results = command.getResults();
- assertEquals(1, results.getRunCount());
- assertEquals(0, results.getFailureCount());
- assertTrue(results.wasSuccessful());
+ String output = this.cli.test("test-samples/book_and_tests.groovy");
+ assertThat(output, containsString("OK (1 test)"));
}
@Test
public void appInOneFileTestsInAnotherFile() throws Exception {
- TestCommand command = new TestCommand();
- command.run("test-samples/book.groovy", "test-samples/test.groovy");
- TestResults results = command.getResults();
- assertEquals(1, results.getRunCount());
- assertEquals(0, results.getFailureCount());
- assertTrue(results.wasSuccessful());
+ String output = this.cli.test("test-samples/book.groovy",
+ "test-samples/test.groovy");
+ assertThat(output, containsString("OK (1 test)"));
}
@Test
public void spockTester() throws Exception {
- TestCommand command = new TestCommand();
- command.run("test-samples/spock.groovy");
- TestResults results = command.getResults();
- assertEquals(1, results.getRunCount());
- assertEquals(0, results.getFailureCount());
- assertTrue(results.wasSuccessful());
+ String output = this.cli.test("test-samples/spock.groovy");
+ assertThat(output, containsString("OK (1 test)"));
}
@Test
public void spockAndJunitTester() throws Exception {
- TestCommand command = new TestCommand();
- command.run("test-samples/spock.groovy", "test-samples/book_and_tests.groovy");
- TestResults results = command.getResults();
- assertEquals(2, results.getRunCount());
- assertEquals(0, results.getFailureCount());
- assertTrue(results.wasSuccessful());
+ String output = this.cli.test("test-samples/spock.groovy",
+ "test-samples/book_and_tests.groovy");
+ assertThat(output, containsString("OK (2 tests)"));
}
@Test
public void verifyFailures() throws Exception {
- TestCommand command = new TestCommand();
- command.run("test-samples/failures.groovy");
- TestResults results = command.getResults();
- assertEquals(5, results.getRunCount());
- assertEquals(3, results.getFailureCount());
- assertFalse(results.wasSuccessful());
+ String output = this.cli.test("test-samples/failures.groovy");
+ assertThat(output, containsString("Tests run: 5, Failures: 3"));
}
-
}
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestTest.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestTest.java
new file mode 100644
index 00000000000..267b67a30f0
--- /dev/null
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.cli;
+
+import org.junit.Test;
+import org.junit.internal.TextListener;
+import org.junit.runner.JUnitCore;
+
+import static org.junit.Assert.fail;
+
+/**
+ * @author pwebb
+ */
+public class TestTest {
+
+ @Test
+ public void testName() throws Exception {
+ fail("Arse");
+ }
+
+ public static void main(String[] args) {
+ JUnitCore core = new JUnitCore();
+ core.addListener(new TextListener(System.out));
+ core.run(TestTest.class);
+
+ }
+}
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/ScriptCommandTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/ScriptCommandTests.java
deleted file mode 100644
index ed121654f8c..00000000000
--- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/ScriptCommandTests.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright 2012-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.boot.cli.command;
-
-import groovy.lang.GroovyObjectSupport;
-import groovy.lang.Script;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.springframework.boot.cli.GrapesCleaner;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for {@link ScriptCommand}.
- *
- * @author Dave Syer
- */
-public class ScriptCommandTests {
-
- public static boolean executed = false;
-
- @BeforeClass
- public static void cleanGrapes() throws Exception {
- GrapesCleaner.cleanIfNecessary();
- }
-
- @Test(expected = IllegalStateException.class)
- public void testMissing() throws Exception {
- ScriptCommand command = new ScriptCommand("missing");
- command.run("World");
- }
-
- @Test
- public void testScript() throws Exception {
- ScriptCommand command = new ScriptCommand("script");
- command.run("World");
- assertEquals("World",
- ((String[]) ((Script) command.getMain()).getProperty("args"))[0]);
- }
-
- @Test
- public void testLocateFile() throws Exception {
- ScriptCommand command = new ScriptCommand(
- "src/test/resources/commands/script.groovy");
- command.setPaths(new String[] { "." });
- command.run("World");
- assertEquals("World",
- ((String[]) ((Script) command.getMain()).getProperty("args"))[0]);
- }
-
- @Test
- public void testRunnable() throws Exception {
- ScriptCommand command = new ScriptCommand("runnable");
- command.run("World");
- assertTrue(executed);
- }
-
- @Test
- public void testClosure() throws Exception {
- ScriptCommand command = new ScriptCommand("closure");
- command.run("World");
- assertTrue(executed);
- }
-
- @Test
- public void testCommand() throws Exception {
- ScriptCommand command = new ScriptCommand("command");
- assertEquals("My script command", command.getUsageHelp());
- command.run("World");
- assertTrue(executed);
- }
-
- @Test
- public void testDuplicateClassName() throws Exception {
- ScriptCommand command1 = new ScriptCommand("handler");
- ScriptCommand command2 = new ScriptCommand("command");
- assertNotSame(command1.getMain().getClass(), command2.getMain().getClass());
- assertEquals(command1.getMain().getClass().getName(), command2.getMain()
- .getClass().getName());
- }
-
- @Test
- public void testOptions() throws Exception {
- ScriptCommand command = new ScriptCommand("handler");
- String out = ((OptionHandler) command.getMain()).getHelp();
- assertTrue("Wrong output: " + out, out.contains("--foo"));
- command.run("World", "--foo");
- assertTrue(executed);
- }
-
- @Test
- public void testMixin() throws Exception {
- ScriptCommand command = new ScriptCommand("mixin");
- GroovyObjectSupport object = (GroovyObjectSupport) command.getMain();
- String out = (String) object.getProperty("help");
- assertTrue("Wrong output: " + out, out.contains("--foo"));
- command.run("World", "--foo");
- assertTrue(executed);
- }
-
- @Test
- public void testMixinWithBlock() throws Exception {
- ScriptCommand command = new ScriptCommand("test");
- GroovyObjectSupport object = (GroovyObjectSupport) command.getMain();
- String out = (String) object.getProperty("help");
- System.err.println(out);
- assertTrue("Wrong output: " + out, out.contains("--foo"));
- command.run("World", "--foo", "--bar=2");
- assertTrue(executed);
- }
-
-}
diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java
new file mode 100644
index 00000000000..76e97af497f
--- /dev/null
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/ExtendedGroovyClassLoaderTests.java
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2012-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.boot.cli.compiler;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import static org.hamcrest.Matchers.sameInstance;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link ExtendedGroovyClassLoader}.
+ *
+ * @author Phillip Webb
+ */
+public class ExtendedGroovyClassLoaderTests {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ private ClassLoader contextClassLoader;
+
+ private ExtendedGroovyClassLoader defaultScopeGroovyClassLoader;
+
+ @Before
+ public void setup() {
+ this.contextClassLoader = Thread.currentThread().getContextClassLoader();
+ this.defaultScopeGroovyClassLoader = new ExtendedGroovyClassLoader(
+ GroovyCompilerScope.DEFAULT);
+ }
+
+ @Test
+ public void loadsGroovyFromSameClassLoader() throws Exception {
+ Class> c1 = this.contextClassLoader.loadClass("groovy.lang.Script");
+ Class> c2 = this.defaultScopeGroovyClassLoader.loadClass("groovy.lang.Script");
+ assertThat(c1.getClassLoader(), sameInstance(c2.getClassLoader()));
+ }
+
+ @Test
+ public void filteresNonGroovy() throws Exception {
+ this.contextClassLoader.loadClass("org.springframework.util.StringUtils");
+ this.thrown.expect(ClassNotFoundException.class);
+ this.defaultScopeGroovyClassLoader
+ .loadClass("org.springframework.util.StringUtils");
+ }
+
+ @Test
+ public void loadsJavaTypes() throws Exception {
+ this.defaultScopeGroovyClassLoader.loadClass("java.lang.Boolean");
+ }
+
+}
diff --git a/spring-boot-cli-grape/src/test/java/org/springframework/boot/cli/compiler/AetherGrapeEngineTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
similarity index 94%
rename from spring-boot-cli-grape/src/test/java/org/springframework/boot/cli/compiler/AetherGrapeEngineTests.java
rename to spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
index a4654ad37fa..0403afda200 100644
--- a/spring-boot-cli-grape/src/test/java/org/springframework/boot/cli/compiler/AetherGrapeEngineTests.java
+++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/compiler/grape/AetherGrapeEngineTests.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package org.springframework.boot.cli.compiler;
+package org.springframework.boot.cli.compiler.grape;
import groovy.lang.GroovyClassLoader;
@@ -26,6 +26,8 @@ import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
+ * Tests for {@link AetherGrapeEngine}.
+ *
* @author Andy Wilkinson
*/
public class AetherGrapeEngineTests {
@@ -33,7 +35,7 @@ public class AetherGrapeEngineTests {
private final GroovyClassLoader groovyClassLoader = new GroovyClassLoader();
private final AetherGrapeEngine grapeEngine = new AetherGrapeEngine(
- this.groovyClassLoader, null, null, null);
+ this.groovyClassLoader);
@Test
public void dependencyResolution() {
@@ -75,7 +77,7 @@ public class AetherGrapeEngineTests {
Map args = new HashMap();
System.setProperty("disableSpringSnapshotRepos", "true");
try {
- new AetherGrapeEngine(this.groovyClassLoader, null, null, null).grab(args,
+ new AetherGrapeEngine(this.groovyClassLoader).grab(args,
createDependency("org.springframework", "spring-jdbc", "3.2.0.M1"));
}
finally {
diff --git a/spring-boot-cli/src/test/resources/classloader-test-app.groovy b/spring-boot-cli/src/test/resources/classloader-test-app.groovy
new file mode 100644
index 00000000000..96e002a9539
--- /dev/null
+++ b/spring-boot-cli/src/test/resources/classloader-test-app.groovy
@@ -0,0 +1,13 @@
+import org.springframework.util.*
+
+@Component
+public class Test implements CommandLineRunner {
+
+ public void run(String... args) throws Exception {
+ println "HasClasses-" + ClassUtils.isPresent("missing", null) + "-" +
+ ClassUtils.isPresent("org.springframework.boot.SpringApplication", null) + "-" +
+ ClassUtils.isPresent(args[0], null);
+ }
+
+}
+
diff --git a/spring-boot-full-build/pom.xml b/spring-boot-full-build/pom.xml
index 984e4e58923..e40acbb0a98 100644
--- a/spring-boot-full-build/pom.xml
+++ b/spring-boot-full-build/pom.xml
@@ -16,7 +16,6 @@
../spring-boot-actuator
../spring-boot-starters
../spring-boot-cli
- ../spring-boot-cli-grape
../spring-boot-samples
../spring-boot-integration-tests
../spring-boot-javadoc