Merge branch '1.2.x'

This commit is contained in:
Phillip Webb
2015-10-07 23:34:08 -07:00
507 changed files with 2659 additions and 2478 deletions

View File

@@ -160,8 +160,8 @@ public class CliTester implements TestRule {
@Override
public Statement apply(final Statement base, final Description description) {
final Statement statement = CliTester.this.outputCapture.apply(
new RunLauncherStatement(base), description);
final Statement statement = CliTester.this.outputCapture
.apply(new RunLauncherStatement(base), description);
return new Statement() {
@Override
@@ -181,8 +181,8 @@ public class CliTester implements TestRule {
public String getHttpOutput(String uri) {
try {
InputStream stream = URI.create("http://localhost:" + this.port + uri)
.toURL().openStream();
InputStream stream = URI.create("http://localhost:" + this.port + uri).toURL()
.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
StringBuilder result = new StringBuilder();

View File

@@ -155,8 +155,8 @@ public class CommandRunnerTests {
willThrow(new NullPointerException()).given(this.regularCommand).run();
int status = this.commandRunner.runAndHandleErrors("command");
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE,
Call.PRINT_STACK_TRACE)));
assertThat(this.calls, equalTo(
(Set<Call>) EnumSet.of(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE)));
}
@Test
@@ -165,8 +165,8 @@ public class CommandRunnerTests {
int status = this.commandRunner.runAndHandleErrors("command", "-d");
assertEquals("true", System.getProperty("debug"));
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE,
Call.PRINT_STACK_TRACE)));
assertThat(this.calls, equalTo(
(Set<Call>) EnumSet.of(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE)));
}
@Test
@@ -175,8 +175,8 @@ public class CommandRunnerTests {
int status = this.commandRunner.runAndHandleErrors("command", "--debug");
assertEquals("true", System.getProperty("debug"));
assertThat(status, equalTo(1));
assertThat(this.calls, equalTo((Set<Call>) EnumSet.of(Call.ERROR_MESSAGE,
Call.PRINT_STACK_TRACE)));
assertThat(this.calls, equalTo(
(Set<Call>) EnumSet.of(Call.ERROR_MESSAGE, Call.PRINT_STACK_TRACE)));
}
@Test

View File

@@ -87,8 +87,8 @@ public abstract class AbstractHttpClientMockTests {
CloseableHttpResponse response = mock(CloseableHttpResponse.class);
mockHttpEntity(response, request.content, request.contentType);
mockStatus(response, 200);
String header = (request.fileName != null ? contentDispositionValue(request.fileName)
: null);
String header = (request.fileName != null
? contentDispositionValue(request.fileName) : null);
mockHttpHeader(response, "Content-Disposition", header);
given(this.http.execute(argThat(getForNonMetadata()))).willReturn(response);
}
@@ -117,8 +117,8 @@ public abstract class AbstractHttpClientMockTests {
try {
HttpEntity entity = mock(HttpEntity.class);
given(entity.getContent()).willReturn(new ByteArrayInputStream(content));
Header contentTypeHeader = contentType != null ? new BasicHeader(
"Content-Type", contentType) : null;
Header contentTypeHeader = contentType != null
? new BasicHeader("Content-Type", contentType) : null;
given(entity.getContentType()).willReturn(contentTypeHeader);
given(response.getEntity()).willReturn(entity);
return entity;

View File

@@ -242,7 +242,8 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
MockHttpProjectGenerationRequest request = new MockHttpProjectGenerationRequest(
"application/zip", file.getAbsolutePath());
mockSuccessfulProjectGeneration(request);
assertEquals("Should not have failed", ExitStatus.OK, this.command.run("--force"));
assertEquals("Should not have failed", ExitStatus.OK,
this.command.run("--force"));
assertTrue("File should have changed", fileLength != file.length());
}
@@ -379,8 +380,8 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
return bos.toByteArray();
}
private static class TestableInitCommandOptionHandler extends
InitCommand.InitOptionHandler {
private static class TestableInitCommandOptionHandler
extends InitCommand.InitOptionHandler {
private boolean disableProjectGeneration;

View File

@@ -62,8 +62,8 @@ public class InitializrServiceMetadataTests {
// Security description
assertEquals("AOP", metadata.getDependency("aop").getName());
assertEquals("Security", metadata.getDependency("security").getName());
assertEquals("Security description", metadata.getDependency("security")
.getDescription());
assertEquals("Security description",
metadata.getDependency("security").getDescription());
assertEquals("JDBC", metadata.getDependency("jdbc").getName());
assertEquals("JPA", metadata.getDependency("data-jpa").getName());
assertEquals("MongoDB", metadata.getDependency("data-mongodb").getName());
@@ -88,12 +88,12 @@ public class InitializrServiceMetadataTests {
}
private static JSONObject readJson(String version) throws IOException {
Resource resource = new ClassPathResource("metadata/service-metadata-" + version
+ ".json");
Resource resource = new ClassPathResource(
"metadata/service-metadata-" + version + ".json");
InputStream stream = resource.getInputStream();
try {
return new JSONObject(StreamUtils.copyToString(stream,
Charset.forName("UTF-8")));
return new JSONObject(
StreamUtils.copyToString(stream, Charset.forName("UTF-8")));
}
finally {
stream.close();

View File

@@ -57,7 +57,8 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
MockHttpProjectGenerationRequest mockHttpRequest = new MockHttpProjectGenerationRequest(
"application/xml", "foo.zip");
ProjectGenerationResponse entity = generateProject(request, mockHttpRequest);
assertProjectEntity(entity, mockHttpRequest.contentType, mockHttpRequest.fileName);
assertProjectEntity(entity, mockHttpRequest.contentType,
mockHttpRequest.fileName);
}
@Test
@@ -158,8 +159,8 @@ public class InitializrServiceTests extends AbstractHttpClientMockTests {
assertNull("No content type expected", entity.getContentType());
}
else {
assertEquals("wrong mime type", mimeType, entity.getContentType()
.getMimeType());
assertEquals("wrong mime type", mimeType,
entity.getContentType().getMimeType());
}
assertEquals("wrong filename", fileName, entity.getFileName());
}

View File

@@ -60,8 +60,9 @@ public class ProjectGenerationRequestTests {
String customServerUrl = "http://foo:8080/initializr";
this.request.setServiceUrl(customServerUrl);
this.request.getDependencies().add("security");
assertEquals(new URI(customServerUrl
+ "/starter.zip?dependencies=security&type=test-type"),
assertEquals(
new URI(customServerUrl
+ "/starter.zip?dependencies=security&type=test-type"),
this.request.generateUrl(createDefaultMetadata()));
}
@@ -108,8 +109,9 @@ public class ProjectGenerationRequestTests {
InitializrServiceMetadata metadata = new InitializrServiceMetadata(projectType);
this.request.setType("custom");
this.request.getDependencies().add("data-rest");
assertEquals(new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL
+ "/foo?dependencies=data-rest&type=custom"),
assertEquals(
new URI(ProjectGenerationRequest.DEFAULT_SERVICE_URL
+ "/foo?dependencies=data-rest&type=custom"),
this.request.generateUrl(metadata));
}
@@ -249,8 +251,8 @@ public class ProjectGenerationRequestTests {
private static InitializrServiceMetadata readMetadata(String version) {
try {
Resource resource = new ClassPathResource("metadata/service-metadata-"
+ version + ".json");
Resource resource = new ClassPathResource(
"metadata/service-metadata-" + version + ".json");
String content = StreamUtils.copyToString(resource.getInputStream(),
Charset.forName("UTF-8"));
JSONObject json = new JSONObject(content);

View File

@@ -85,16 +85,16 @@ public class GroovyGrabDependencyResolverTests {
@Test
public void resolveArtifactWithNoDependencies() throws Exception {
List<File> resolved = this.resolver.resolve(Arrays
.asList("commons-logging:commons-logging:1.1.3"));
List<File> resolved = this.resolver
.resolve(Arrays.asList("commons-logging:commons-logging:1.1.3"));
assertThat(resolved, hasSize(1));
assertThat(getNames(resolved), hasItems("commons-logging-1.1.3.jar"));
}
@Test
public void resolveArtifactWithDependencies() throws Exception {
List<File> resolved = this.resolver.resolve(Arrays
.asList("org.springframework:spring-core:4.1.1.RELEASE"));
List<File> resolved = this.resolver
.resolve(Arrays.asList("org.springframework:spring-core:4.1.1.RELEASE"));
assertThat(resolved, hasSize(2));
assertThat(getNames(resolved),
hasItems("commons-logging-1.1.3.jar", "spring-core-4.1.1.RELEASE.jar"));
@@ -114,10 +114,8 @@ public class GroovyGrabDependencyResolverTests {
List<File> resolved = this.resolver.resolve(Arrays.asList("junit:junit:4.11",
"commons-logging:commons-logging:1.1.3"));
assertThat(resolved, hasSize(3));
assertThat(
getNames(resolved),
hasItems("junit-4.11.jar", "commons-logging-1.1.3.jar",
"hamcrest-core-1.3.jar"));
assertThat(getNames(resolved), hasItems("junit-4.11.jar",
"commons-logging-1.1.3.jar", "hamcrest-core-1.3.jar"));
}
public Set<String> getNames(Collection<File> files) {

View File

@@ -84,18 +84,18 @@ public class InstallerTests {
File alpha = createTemporaryFile("alpha.jar");
File bravo = createTemporaryFile("bravo.jar");
File charlie = createTemporaryFile("charlie.jar");
given(this.resolver.resolve(Arrays.asList("bravo"))).willReturn(
Arrays.asList(bravo, alpha));
given(this.resolver.resolve(Arrays.asList("charlie"))).willReturn(
Arrays.asList(charlie, alpha));
given(this.resolver.resolve(Arrays.asList("bravo")))
.willReturn(Arrays.asList(bravo, alpha));
given(this.resolver.resolve(Arrays.asList("charlie")))
.willReturn(Arrays.asList(charlie, alpha));
this.installer.install(Arrays.asList("bravo"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "bravo.jar", ".installed"));
this.installer.install(Arrays.asList("charlie"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "bravo.jar", "charlie.jar", ".installed"));
assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar",
"charlie.jar", ".installed"));
this.installer.uninstall(Arrays.asList("bravo"));
assertThat(getNamesOfFilesInLib(),
@@ -111,15 +111,15 @@ public class InstallerTests {
File bravo = createTemporaryFile("bravo.jar");
File charlie = createTemporaryFile("charlie.jar");
given(this.resolver.resolve(Arrays.asList("bravo"))).willReturn(
Arrays.asList(bravo, alpha));
given(this.resolver.resolve(Arrays.asList("charlie"))).willReturn(
Arrays.asList(charlie, alpha));
given(this.resolver.resolve(Arrays.asList("bravo")))
.willReturn(Arrays.asList(bravo, alpha));
given(this.resolver.resolve(Arrays.asList("charlie")))
.willReturn(Arrays.asList(charlie, alpha));
this.installer.install(Arrays.asList("bravo"));
this.installer.install(Arrays.asList("charlie"));
assertThat(getNamesOfFilesInLib(),
containsInAnyOrder("alpha.jar", "bravo.jar", "charlie.jar", ".installed"));
assertThat(getNamesOfFilesInLib(), containsInAnyOrder("alpha.jar", "bravo.jar",
"charlie.jar", ".installed"));
this.installer.uninstallAll();
assertThat(getNamesOfFilesInLib(), containsInAnyOrder(".installed"));

View File

@@ -45,10 +45,11 @@ public class ResourceMatcherTests {
@Test
public void nonExistentRoot() throws IOException {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("alpha/**",
"bravo/*", "*"), Arrays.asList(".*", "alpha/**/excluded"));
List<MatchedResource> matchedResources = resourceMatcher.find(Arrays
.asList(new File("does-not-exist")));
ResourceMatcher resourceMatcher = new ResourceMatcher(
Arrays.asList("alpha/**", "bravo/*", "*"),
Arrays.asList(".*", "alpha/**/excluded"));
List<MatchedResource> matchedResources = resourceMatcher
.find(Arrays.asList(new File("does-not-exist")));
assertEquals(0, matchedResources.size());
}
@@ -67,18 +68,18 @@ public class ResourceMatcherTests {
public void excludedWins() throws Exception {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("*"),
Arrays.asList("**/*.jar"));
List<MatchedResource> found = resourceMatcher.find(Arrays.asList(new File(
"src/test/resources")));
List<MatchedResource> found = resourceMatcher
.find(Arrays.asList(new File("src/test/resources")));
assertThat(found, not(hasItem(new FooJarMatcher(MatchedResource.class))));
}
@SuppressWarnings("unchecked")
@Test
public void includedDeltas() throws Exception {
ResourceMatcher resourceMatcher = new ResourceMatcher(
Arrays.asList("-static/**"), Arrays.asList(""));
Collection<String> includes = (Collection<String>) ReflectionTestUtils.getField(
resourceMatcher, "includes");
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("-static/**"),
Arrays.asList(""));
Collection<String> includes = (Collection<String>) ReflectionTestUtils
.getField(resourceMatcher, "includes");
assertTrue(includes.contains("templates/**"));
assertFalse(includes.contains("static/**"));
}
@@ -86,10 +87,10 @@ public class ResourceMatcherTests {
@SuppressWarnings("unchecked")
@Test
public void includedDeltasAndNewEntries() throws Exception {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("-static/**",
"foo.jar"), Arrays.asList("-**/*.jar"));
Collection<String> includes = (Collection<String>) ReflectionTestUtils.getField(
resourceMatcher, "includes");
ResourceMatcher resourceMatcher = new ResourceMatcher(
Arrays.asList("-static/**", "foo.jar"), Arrays.asList("-**/*.jar"));
Collection<String> includes = (Collection<String>) ReflectionTestUtils
.getField(resourceMatcher, "includes");
assertTrue(includes.contains("foo.jar"));
assertTrue(includes.contains("templates/**"));
assertFalse(includes.contains("static/**"));
@@ -110,8 +111,9 @@ public class ResourceMatcherTests {
public void jarFileAlwaysMatches() throws Exception {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("*"),
Arrays.asList("**/*.jar"));
List<MatchedResource> found = resourceMatcher.find(Arrays.asList(new File(
"src/test/resources/templates"), new File("src/test/resources/foo.jar")));
List<MatchedResource> found = resourceMatcher
.find(Arrays.asList(new File("src/test/resources/templates"),
new File("src/test/resources/foo.jar")));
FooJarMatcher matcher = new FooJarMatcher(MatchedResource.class);
assertThat(found, hasItem(matcher));
// A jar file is always treated as a dependency (stick it in /lib)
@@ -120,12 +122,13 @@ public class ResourceMatcherTests {
@Test
public void resourceMatching() throws IOException {
ResourceMatcher resourceMatcher = new ResourceMatcher(Arrays.asList("alpha/**",
"bravo/*", "*"), Arrays.asList(".*", "alpha/**/excluded"));
List<MatchedResource> matchedResources = resourceMatcher.find(Arrays.asList(
new File("src/test/resources/resource-matcher/one"), new File(
"src/test/resources/resource-matcher/two"), new File(
"src/test/resources/resource-matcher/three")));
ResourceMatcher resourceMatcher = new ResourceMatcher(
Arrays.asList("alpha/**", "bravo/*", "*"),
Arrays.asList(".*", "alpha/**/excluded"));
List<MatchedResource> matchedResources = resourceMatcher
.find(Arrays.asList(new File("src/test/resources/resource-matcher/one"),
new File("src/test/resources/resource-matcher/two"),
new File("src/test/resources/resource-matcher/three")));
System.out.println(matchedResources);
List<String> paths = new ArrayList<String>();
for (MatchedResource resource : matchedResources) {

View File

@@ -35,8 +35,8 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
@Test
public void simple() throws Exception {
String s = "one two";
assertThat(this.delimiter.delimit(s, 0).getArguments(), equalTo(new String[] {
"one", "two" }));
assertThat(this.delimiter.delimit(s, 0).getArguments(),
equalTo(new String[] { "one", "two" }));
assertThat(this.delimiter.parseArguments(s),
equalTo(new String[] { "one", "two" }));
assertThat(this.delimiter.isDelimiter(s, 2), equalTo(false));
@@ -47,8 +47,8 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
@Test
public void escaped() throws Exception {
String s = "o\\ ne two";
assertThat(this.delimiter.delimit(s, 0).getArguments(), equalTo(new String[] {
"o\\ ne", "two" }));
assertThat(this.delimiter.delimit(s, 0).getArguments(),
equalTo(new String[] { "o\\ ne", "two" }));
assertThat(this.delimiter.parseArguments(s),
equalTo(new String[] { "o ne", "two" }));
assertThat(this.delimiter.isDelimiter(s, 2), equalTo(false));
@@ -60,28 +60,28 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
@Test
public void quoted() throws Exception {
String s = "'o ne' 't w o'";
assertThat(this.delimiter.delimit(s, 0).getArguments(), equalTo(new String[] {
"'o ne'", "'t w o'" }));
assertThat(this.delimiter.parseArguments(s), equalTo(new String[] { "o ne",
"t w o" }));
assertThat(this.delimiter.delimit(s, 0).getArguments(),
equalTo(new String[] { "'o ne'", "'t w o'" }));
assertThat(this.delimiter.parseArguments(s),
equalTo(new String[] { "o ne", "t w o" }));
}
@Test
public void doubleQuoted() throws Exception {
String s = "\"o ne\" \"t w o\"";
assertThat(this.delimiter.delimit(s, 0).getArguments(), equalTo(new String[] {
"\"o ne\"", "\"t w o\"" }));
assertThat(this.delimiter.parseArguments(s), equalTo(new String[] { "o ne",
"t w o" }));
assertThat(this.delimiter.delimit(s, 0).getArguments(),
equalTo(new String[] { "\"o ne\"", "\"t w o\"" }));
assertThat(this.delimiter.parseArguments(s),
equalTo(new String[] { "o ne", "t w o" }));
}
@Test
public void nestedQuotes() throws Exception {
String s = "\"o 'n''e\" 't \"w o'";
assertThat(this.delimiter.delimit(s, 0).getArguments(), equalTo(new String[] {
"\"o 'n''e\"", "'t \"w o'" }));
assertThat(this.delimiter.parseArguments(s), equalTo(new String[] { "o 'n''e",
"t \"w o" }));
assertThat(this.delimiter.delimit(s, 0).getArguments(),
equalTo(new String[] { "\"o 'n''e\"", "'t \"w o'" }));
assertThat(this.delimiter.parseArguments(s),
equalTo(new String[] { "o 'n''e", "t \"w o" }));
}
@Test
@@ -95,7 +95,8 @@ public class EscapeAwareWhiteSpaceArgumentDelimiterTests {
@Test
public void escapes() throws Exception {
String s = "\\ \\\\.\\\\\\t";
assertThat(this.delimiter.parseArguments(s), equalTo(new String[] { " \\.\\\t" }));
assertThat(this.delimiter.parseArguments(s),
equalTo(new String[] { " \\.\\\t" }));
}
}

View File

@@ -58,38 +58,36 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
@Test
public void noLocalRepositoryWhenNoGrapeRoot() {
given(
this.repositorySystem.newLocalRepositoryManager(eq(this.session),
any(LocalRepository.class))).willAnswer(
new Answer<LocalRepositoryManager>() {
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session),
any(LocalRepository.class)))
.willAnswer(new Answer<LocalRepositoryManager>() {
@Override
public LocalRepositoryManager answer(InvocationOnMock invocation)
throws Throwable {
LocalRepository localRepository = invocation.getArgumentAt(1,
LocalRepository.class);
return new SimpleLocalRepositoryManagerFactory()
.newInstance(
GrapeRootRepositorySystemSessionAutoConfigurationTests.this.session,
localRepository);
}
});
@Override
public LocalRepositoryManager answer(
InvocationOnMock invocation) throws Throwable {
LocalRepository localRepository = invocation
.getArgumentAt(1, LocalRepository.class);
return new SimpleLocalRepositoryManagerFactory()
.newInstance(
GrapeRootRepositorySystemSessionAutoConfigurationTests.this.session,
localRepository);
}
});
new GrapeRootRepositorySystemSessionAutoConfiguration().apply(this.session,
this.repositorySystem);
verify(this.repositorySystem, times(0)).newLocalRepositoryManager(
eq(this.session), any(LocalRepository.class));
verify(this.repositorySystem, times(0))
.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class));
assertThat(this.session.getLocalRepository(), is(nullValue()));
}
@Test
public void grapeRootConfiguresLocalRepositoryLocation() {
given(
this.repositorySystem.newLocalRepositoryManager(eq(this.session),
any(LocalRepository.class))).willAnswer(
new LocalRepositoryManagerAnswer());
given(this.repositorySystem.newLocalRepositoryManager(eq(this.session),
any(LocalRepository.class)))
.willAnswer(new LocalRepositoryManagerAnswer());
System.setProperty("grape.root", "foo");
try {
@@ -100,8 +98,8 @@ public class GrapeRootRepositorySystemSessionAutoConfigurationTests {
System.clearProperty("grape.root");
}
verify(this.repositorySystem, times(1)).newLocalRepositoryManager(
eq(this.session), any(LocalRepository.class));
verify(this.repositorySystem, times(1))
.newLocalRepositoryManager(eq(this.session), any(LocalRepository.class));
assertThat(this.session.getLocalRepository(), is(notNullValue()));
assertThat(this.session.getLocalRepository().getBasedir().getAbsolutePath(),