Favor groovy.jar instead of groovy-all.jar

Update CLI application to use groovy.jar rather than groovy-all.jar.
This prevents classloading issues when a user project @Grabs groovy-ant.
This commit is contained in:
Phillip Webb
2013-11-05 09:56:59 -08:00
parent 557f69a449
commit aede0165a0
6 changed files with 115 additions and 47 deletions

View File

@@ -16,6 +16,10 @@
package org.springframework.boot.cli;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
@@ -86,6 +90,26 @@ public class CliTester implements TestRule {
return this.outputCapture.apply(new RunLauncherStatement(base), description);
}
public String getHttpOutput() {
return getHttpOutput("http://localhost:8080");
}
public String getHttpOutput(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);
}
}
private final class RunLauncherStatement extends Statement {
private final Statement base;

View File

@@ -0,0 +1,44 @@
/*
* 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;
/**
* Integration tests to exercise reproduce raised issues.
*
* @author Phillip Webb
*/
public class ReproIntegrationTests {
private static final String SRC = "src/test/resources/repro-samples";
@Rule
public CliTester cli = new CliTester();
@Test
public void grabAntBuilder() throws Exception {
this.cli.run(SRC + "/grab-ant-builder.groovy");
assertThat(this.cli.getHttpOutput(),
containsString("{\"message\":\"Hello World\"}"));
}
}

View File

@@ -16,11 +16,7 @@
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;
@@ -85,31 +81,29 @@ public class SampleIntegrationTests {
"foo=bar");
assertTrue("Wrong output: " + output,
output.contains("completed with the following parameters"));
String result = readEntirely("http://localhost:8080");
String result = this.cli.getHttpOutput();
assertEquals("World!", result);
}
@Test
public void webSample() throws Exception {
this.cli.run("samples/web.groovy");
String result = readEntirely("http://localhost:8080");
assertEquals("World!", result);
assertEquals("World!", this.cli.getHttpOutput());
}
@Test
public void uiSample() throws Exception {
this.cli.run("samples/ui.groovy", "--classpath=.:src/test/resources");
String result = readEntirely("http://localhost:8080");
String result = this.cli.getHttpOutput();
assertTrue("Wrong output: " + result, result.contains("Hello World"));
result = readEntirely("http://localhost:8080/css/bootstrap.min.css");
result = this.cli.getHttpOutput("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 = readEntirely("http://localhost:8080");
assertEquals("{\"message\":\"Hello World!\"}", result);
assertEquals("{\"message\":\"Hello World!\"}", this.cli.getHttpOutput());
}
@Test
@@ -156,24 +150,7 @@ public class SampleIntegrationTests {
@Test
public void deviceSample() throws Exception {
this.cli.run("samples/device.groovy");
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);
}
assertEquals("Hello Normal Device!", this.cli.getHttpOutput());
}
}