Upgrade to spring javaformat 0.0.38

This commit is contained in:
Stephane Nicoll
2023-04-03 14:57:51 +02:00
parent 32b5db7a5a
commit 5e97a01e99
207 changed files with 2449 additions and 1746 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -144,7 +144,7 @@ public class InitializrAutoConfiguration {
ApplicationContext applicationContext) {
ProjectGenerationInvoker<ProjectRequest> projectGenerationInvoker = new ProjectGenerationInvoker<>(
applicationContext, new DefaultProjectRequestToDescriptionConverter(platformVersionTransformer
.getIfAvailable(DefaultProjectRequestPlatformVersionTransformer::new)));
.getIfAvailable(DefaultProjectRequestPlatformVersionTransformer::new)));
return new DefaultProjectGenerationController(metadataProvider, projectGenerationInvoker);
}
@@ -204,15 +204,16 @@ public class InitializrAutoConfiguration {
private void createMissingCache(javax.cache.CacheManager cacheManager, String cacheName,
Supplier<MutableConfiguration<Object, Object>> config) {
boolean cacheExist = StreamSupport.stream(cacheManager.getCacheNames().spliterator(), true)
.anyMatch((name) -> name.equals(cacheName));
.anyMatch((name) -> name.equals(cacheName));
if (!cacheExist) {
cacheManager.createCache(cacheName, config.get());
}
}
private MutableConfiguration<Object, Object> config() {
return new MutableConfiguration<>().setStoreByValue(false).setManagementEnabled(true)
.setStatisticsEnabled(true);
return new MutableConfiguration<>().setStoreByValue(false)
.setManagementEnabled(true)
.setStatisticsEnabled(true);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -61,7 +61,7 @@ public class InitializrWebConfig implements WebMvcConfigurer {
@Override
public List<MediaType> resolveMediaTypes(NativeWebRequest request) {
String path = this.urlPathHelper
.getPathWithinApplication(request.getNativeRequest(HttpServletRequest.class));
.getPathWithinApplication(request.getNativeRequest(HttpServletRequest.class));
if (!StringUtils.hasText(path) || !path.equals("/")) { // Only care about "/"
return MEDIA_TYPE_ALL_LIST;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -156,22 +156,23 @@ public abstract class ProjectGenerationController<R extends ProjectRequest> {
"." + fileExtension);
String wrapperScript = getWrapperScript(result.getProjectDescription());
try (ArchiveOutputStream output = archiveOutputStream.apply(Files.newOutputStream(archive))) {
Files.walk(result.getRootDirectory()).filter((path) -> !result.getRootDirectory().equals(path))
.forEach((path) -> {
try {
String entryName = getEntryName(result.getRootDirectory(), path);
T entry = archiveEntry.apply(path.toFile(), entryName);
setMode.accept(entry, getUnixMode(wrapperScript, entryName, path));
output.putArchiveEntry(entry);
if (!Files.isDirectory(path)) {
Files.copy(path, output);
}
output.closeArchiveEntry();
Files.walk(result.getRootDirectory())
.filter((path) -> !result.getRootDirectory().equals(path))
.forEach((path) -> {
try {
String entryName = getEntryName(result.getRootDirectory(), path);
T entry = archiveEntry.apply(path.toFile(), entryName);
setMode.accept(entry, getUnixMode(wrapperScript, entryName, path));
output.putArchiveEntry(entry);
if (!Files.isDirectory(path)) {
Files.copy(path, output);
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
});
output.closeArchiveEntry();
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
});
}
return archive;
}
@@ -220,8 +221,10 @@ public abstract class ProjectGenerationController<R extends ProjectRequest> {
private ResponseEntity<byte[]> createResponseEntity(byte[] content, String contentType, String fileName) {
String contentDispositionValue = "attachment; filename=\"" + fileName + "\"";
return ResponseEntity.ok().header("Content-Type", contentType)
.header("Content-Disposition", contentDispositionValue).body(content);
return ResponseEntity.ok()
.header("Content-Type", contentType)
.header("Content-Disposition", contentDispositionValue)
.body(content);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -137,8 +137,11 @@ public class ProjectMetadataController extends AbstractMetadataController {
}
DependencyMetadata dependencyMetadata = this.dependencyMetadataProvider.get(metadata, v);
String content = new DependencyMetadataV21JsonMapper().write(dependencyMetadata);
return ResponseEntity.ok().contentType(version.getMediaType()).eTag(createUniqueId(content))
.cacheControl(determineCacheControlFor(metadata)).body(content);
return ResponseEntity.ok()
.contentType(version.getMediaType())
.eTag(createUniqueId(content))
.cacheControl(determineCacheControlFor(metadata))
.body(content);
}
private ResponseEntity<String> serviceCapabilitiesFor(InitializrMetadataVersion version) {
@@ -149,8 +152,12 @@ public class ProjectMetadataController extends AbstractMetadataController {
String appUrl = generateAppUrl();
InitializrMetadata metadata = this.metadataProvider.get();
String content = getJsonMapper(version).write(metadata, appUrl);
return ResponseEntity.ok().contentType(contentType).eTag(createUniqueId(content)).varyBy("Accept")
.cacheControl(determineCacheControlFor(metadata)).body(content);
return ResponseEntity.ok()
.contentType(contentType)
.eTag(createUniqueId(content))
.varyBy("Accept")
.cacheControl(determineCacheControlFor(metadata))
.body(content);
}
private static InitializrMetadataJsonMapper getJsonMapper(InitializrMetadataVersion version) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -41,12 +41,21 @@ public class DependencyMetadataV21JsonMapper implements DependencyMetadataJsonMa
public String write(DependencyMetadata metadata) {
ObjectNode json = nodeFactory.objectNode();
json.put("bootVersion", metadata.getBootVersion().toString());
json.set("dependencies", mapNode(metadata.getDependencies().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, (entry) -> mapDependency(entry.getValue())))));
json.set("repositories", mapNode(metadata.getRepositories().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, (entry) -> mapRepository(entry.getValue())))));
json.set("boms", mapNode(metadata.getBoms().entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, (entry) -> mapBom(entry.getValue())))));
json.set("dependencies",
mapNode(metadata.getDependencies()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, (entry) -> mapDependency(entry.getValue())))));
json.set("repositories",
mapNode(metadata.getRepositories()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, (entry) -> mapRepository(entry.getValue())))));
json.set("boms",
mapNode(metadata.getBoms()
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey, (entry) -> mapBom(entry.getValue())))));
return json.toString();
}
@@ -69,8 +78,9 @@ public class DependencyMetadataV21JsonMapper implements DependencyMetadataJsonMa
private static JsonNode mapRepository(Repository repo) {
ObjectNode node = nodeFactory.objectNode();
node.put("name", repo.getName()).put("url", (repo.getUrl() != null) ? repo.getUrl().toString() : null)
.put("snapshotEnabled", repo.isSnapshotsEnabled());
node.put("name", repo.getName())
.put("url", (repo.getUrl() != null) ? repo.getUrl().toString() : null)
.put("snapshotEnabled", repo.isSnapshotsEnabled());
return node;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -44,8 +44,8 @@ public class MetadataProjectDescriptionCustomizer implements ProjectDescriptionC
@Override
public void customize(MutableProjectDescription description) {
if (!StringUtils.hasText(description.getApplicationName())) {
description.setApplicationName(
this.metadata.getConfiguration().generateApplicationName(description.getName()));
description
.setApplicationName(this.metadata.getConfiguration().generateApplicationName(description.getName()));
}
String targetArtifactId = determineValue(description.getArtifactId(),
() -> this.metadata.getArtifactId().getContent());
@@ -64,8 +64,8 @@ public class MetadataProjectDescriptionCustomizer implements ProjectDescriptionC
else if (targetArtifactId.equals(description.getName())) {
description.setName(cleanMavenCoordinate(targetArtifactId, "-"));
}
description.setPackageName(this.metadata.getConfiguration().cleanPackageName(description.getPackageName(),
this.metadata.getPackageName().getContent()));
description.setPackageName(this.metadata.getConfiguration()
.cleanPackageName(description.getPackageName(), this.metadata.getPackageName().getContent()));
if (description.getPlatformVersion() == null) {
description.setPlatformVersion(Version.parse(this.metadata.getBootVersions().getDefault().getId()));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -173,8 +173,11 @@ public class CommandLineHelpGenerator {
String[][] dependencyTable = new String[metadata.getDependencies().getAll().size() + 1][];
dependencyTable[0] = new String[] { "Id", "Description", "Required version" };
int i = 1;
for (Dependency dep : metadata.getDependencies().getAll().stream()
.sorted(Comparator.comparing(MetadataElement::getId)).toList()) {
for (Dependency dep : metadata.getDependencies()
.getAll()
.stream()
.sorted(Comparator.comparing(MetadataElement::getId))
.toList()) {
String[] data = new String[3];
data[0] = dep.getId();
data[1] = (dep.getDescription() != null) ? dep.getDescription() : dep.getName();
@@ -193,8 +196,11 @@ public class CommandLineHelpGenerator {
typeTable[0] = new String[] { linkHeader, "Description" };
}
int i = 1;
for (Type type : metadata.getTypes().getContent().stream().sorted(Comparator.comparing(MetadataElement::getId))
.toList()) {
for (Type type : metadata.getTypes()
.getContent()
.stream()
.sorted(Comparator.comparing(MetadataElement::getId))
.toList()) {
String[] data = new String[typeTable[0].length];
data[0] = (type.isDefault() ? type.getId() + " *" : type.getId());
data[1] = (type.getDescription() != null) ? type.getDescription() : type.getName();
@@ -225,8 +231,12 @@ public class CommandLineHelpGenerator {
if (type.getTags().isEmpty()) {
return "";
}
return String.join(",", type.getTags().entrySet().stream()
.map((entry) -> entry.getKey() + ":" + entry.getValue()).toArray(String[]::new));
return String.join(",",
type.getTags()
.entrySet()
.stream()
.map((entry) -> entry.getKey() + ":" + entry.getValue())
.toArray(String[]::new));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -100,7 +100,8 @@ public abstract class AbstractInitializrIntegrationTests {
MediaType actual = response.getHeaders().getContentType();
assertThat(actual).isNotNull();
assertThat(actual.isCompatibleWith(expected))
.as("Non compatible media-type, expected " + expected + ", got " + actual).isTrue();
.as("Non compatible media-type, expected " + expected + ", got " + actual)
.isTrue();
}
protected JsonNode parseJson(String text) {
@@ -290,8 +291,10 @@ public abstract class AbstractInitializrIntegrationTests {
}
private Set<PosixFilePermission> getPosixFilePermissions(int unixMode) {
return Arrays.stream(BitMaskFilePermission.values()).filter((permission) -> permission.permitted(unixMode))
.map(BitMaskFilePermission::getFilePermission).collect(Collectors.toSet());
return Arrays.stream(BitMaskFilePermission.values())
.filter((permission) -> permission.permitted(unixMode))
.map(BitMaskFilePermission::getFilePermission)
.collect(Collectors.toSet());
}
private void applyPermissions(Path target, Set<PosixFilePermission> permissions) throws IOException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -58,10 +58,10 @@ import static org.mockito.Mockito.mock;
class InitializrAutoConfigurationTests {
private static final AutoConfigurations BASIC_AUTO_CONFIGURATIONS = AutoConfigurations
.of(RestTemplateAutoConfiguration.class, JacksonAutoConfiguration.class, InitializrAutoConfiguration.class);
.of(RestTemplateAutoConfiguration.class, JacksonAutoConfiguration.class, InitializrAutoConfiguration.class);
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(BASIC_AUTO_CONFIGURATIONS);
.withConfiguration(BASIC_AUTO_CONFIGURATIONS);
@Test
void autoConfigRegistersTemplateRenderer() {
@@ -84,12 +84,11 @@ class InitializrAutoConfigurationTests {
@Test
void metadataProviderWithCustomInitializrMetadataUpdateStrategyIsRegistered() {
this.contextRunner.withUserConfiguration(CustomInitializrMetadataUpdateStrategyConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(DefaultInitializrMetadataProvider.class);
assertThat(context.getBean(DefaultInitializrMetadataProvider.class)).hasFieldOrPropertyWithValue(
"initializrMetadataUpdateStrategy",
context.getBean("testInitializrMetadataUpdateStrategy"));
});
.run((context) -> {
assertThat(context).hasSingleBean(DefaultInitializrMetadataProvider.class);
assertThat(context.getBean(DefaultInitializrMetadataProvider.class)).hasFieldOrPropertyWithValue(
"initializrMetadataUpdateStrategy", context.getBean("testInitializrMetadataUpdateStrategy"));
});
}
@Test
@@ -116,7 +115,7 @@ class InitializrAutoConfigurationTests {
@Test
void webConfiguration() {
WebApplicationContextRunner webContextRunner = new WebApplicationContextRunner()
.withConfiguration(BASIC_AUTO_CONFIGURATIONS);
.withConfiguration(BASIC_AUTO_CONFIGURATIONS);
webContextRunner.run((context) -> {
assertThat(context).hasSingleBean(InitializrWebConfig.class);
assertThat(context).hasSingleBean(ProjectGenerationController.class);
@@ -129,11 +128,12 @@ class InitializrAutoConfigurationTests {
@Test
void autoConfigWithCustomProjectGenerationController() {
new WebApplicationContextRunner().withConfiguration(BASIC_AUTO_CONFIGURATIONS)
.withUserConfiguration(CustomProjectGenerationController.class).run((context) -> {
assertThat(context).hasSingleBean(ProjectGenerationController.class);
assertThat(context.getBean(ProjectGenerationController.class))
.isSameAs(context.getBean("testProjectGenerationController"));
});
.withUserConfiguration(CustomProjectGenerationController.class)
.run((context) -> {
assertThat(context).hasSingleBean(ProjectGenerationController.class);
assertThat(context.getBean(ProjectGenerationController.class))
.isSameAs(context.getBean("testProjectGenerationController"));
});
}
@@ -151,34 +151,35 @@ class InitializrAutoConfigurationTests {
@Test
void cacheConfigurationCreatesInitializrCachesIfNecessary() {
this.contextRunner.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class))
.withUserConfiguration(CacheTestConfiguration.class).run((context) -> {
assertThat(context).hasSingleBean(JCacheManagerCustomizer.class)
.hasSingleBean(JCacheCacheManager.class);
JCacheCacheManager cacheManager = context.getBean(JCacheCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("initializr.metadata",
"initializr.dependency-metadata", "initializr.project-resources", "initializr.templates");
assertThat(getConfiguration(cacheManager, "initializr.metadata").isStatisticsEnabled()).isTrue();
});
.withUserConfiguration(CacheTestConfiguration.class)
.run((context) -> {
assertThat(context).hasSingleBean(JCacheManagerCustomizer.class)
.hasSingleBean(JCacheCacheManager.class);
JCacheCacheManager cacheManager = context.getBean(JCacheCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("initializr.metadata",
"initializr.dependency-metadata", "initializr.project-resources", "initializr.templates");
assertThat(getConfiguration(cacheManager, "initializr.metadata").isStatisticsEnabled()).isTrue();
});
}
@Test
void cacheConfigurationDoesNotOverrideExistingCaches() {
this.contextRunner.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class))
.withUserConfiguration(CacheTestConfiguration.class, CustomJCacheManagerCustomizer.class)
.run((context) -> {
assertThat(context).getBeans(JCacheManagerCustomizer.class).hasSize(2);
JCacheCacheManager cacheManager = context.getBean(JCacheCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("initializr.metadata",
"initializr.dependency-metadata", "initializr.project-resources", "initializr.templates",
"custom.cache");
assertThat(getConfiguration(cacheManager, "initializr.metadata").isStatisticsEnabled()).isFalse();
});
.withUserConfiguration(CacheTestConfiguration.class, CustomJCacheManagerCustomizer.class)
.run((context) -> {
assertThat(context).getBeans(JCacheManagerCustomizer.class).hasSize(2);
JCacheCacheManager cacheManager = context.getBean(JCacheCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("initializr.metadata",
"initializr.dependency-metadata", "initializr.project-resources", "initializr.templates",
"custom.cache");
assertThat(getConfiguration(cacheManager, "initializr.metadata").isStatisticsEnabled()).isFalse();
});
}
@Test
void cacheConfigurationConditionalOnClass() {
this.contextRunner.withClassLoader(new FilteredClassLoader("javax.cache.CacheManager"))
.run((context) -> assertThat(context).doesNotHaveBean(JCacheManagerCustomizer.class));
.run((context) -> assertThat(context).doesNotHaveBean(JCacheManagerCustomizer.class));
}
@SuppressWarnings("unchecked")

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -43,9 +43,10 @@ class CommandLineExampleIntegrationTests extends AbstractInitializrControllerInt
ProjectStructure project = downloadZip("/starter.zip");
assertDefaultProject(project);
assertDoesNotHaveWebResources(project);
assertThat(project).mavenBuild().hasDependency(Dependency.createSpringBootStarter(""))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(2);
assertThat(project).mavenBuild()
.hasDependency(Dependency.createSpringBootStarter(""))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(2);
}
@Test
@@ -53,19 +54,22 @@ class CommandLineExampleIntegrationTests extends AbstractInitializrControllerInt
ProjectStructure project = downloadZip("/starter.zip?dependencies=web&javaVersion=1.8");
assertDefaultProject(project);
assertHasWebResources(project);
assertThat(project).mavenBuild().hasProperty("java.version", "1.8")
.hasDependency(Dependency.createSpringBootStarter("web"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(2);
assertThat(project).mavenBuild()
.hasProperty("java.version", "1.8")
.hasDependency(Dependency.createSpringBootStarter("web"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
.hasDependenciesSize(2);
}
@Test
void generateWebDataJpaGradleProject() {
ProjectStructure project = downloadTgz(
"/starter.tgz?dependencies=web,data-jpa&type=gradle-project&baseDir=my-dir").resolveModule("my-dir");
"/starter.tgz?dependencies=web,data-jpa&type=gradle-project&baseDir=my-dir")
.resolveModule("my-dir");
assertHasWebResources(project);
assertThat(project).groovyDslGradleBuild().contains("spring-boot-starter-web")
.contains("spring-boot-starter-data-jpa");
assertThat(project).groovyDslGradleBuild()
.contains("spring-boot-starter-web")
.contains("spring-boot-starter-data-jpa");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -123,7 +123,7 @@ public class CommandLineMetadataControllerIntegrationTests extends AbstractIniti
validateContentType(response, MediaType.TEXT_PLAIN);
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
assertThat(response.getBody()).contains("Service capabilities", "Supported dependencies")
.doesNotContain("Examples:", "curl");
.doesNotContain("Examples:", "curl");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -36,8 +36,12 @@ class ProjectGenerationControllerCustomDefaultsIntegrationTests extends Abstract
void generateDefaultPom() {
String content = getRestTemplate().getForObject(createUrl("/pom.xml?dependencies=web"), String.class);
MavenBuildAssert pomAssert = new MavenBuildAssert(content);
pomAssert.hasGroupId("org.foo").hasArtifactId("foo-bar").hasVersion("1.2.4-SNAPSHOT")
.doesNotHaveNode("/project/packaging").hasName("FooBar").hasDescription("FooBar Project");
pomAssert.hasGroupId("org.foo")
.hasArtifactId("foo-bar")
.hasVersion("1.2.4-SNAPSHOT")
.doesNotHaveNode("/project/packaging")
.hasName("FooBar")
.hasDescription("FooBar Project");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -43,9 +43,10 @@ class ProjectGenerationControllerCustomEnvIntegrationTests extends AbstractIniti
assertThat(project).doesNotContainFiles("src/main/java/com/example/demo/DemoApplication.java",
"src/test/java/com/example/demo/DemoApplicationTests.java");
assertDoesNotHaveWebResources(project);
assertThat(project).mavenBuild().hasDependenciesSize(2)
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
assertThat(project).mavenBuild()
.hasDependenciesSize(2)
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 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.
@@ -47,10 +47,12 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
ProjectStructure project = projectFromArchive(entity.getBody());
assertDefaultProject(project);
assertHasWebResources(project);
assertThat(project).mavenBuild().hasDependenciesSize(3).hasDependency(Dependency.createSpringBootStarter("web"))
// alias: jpa -> data-jpa
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
assertThat(project).mavenBuild()
.hasDependenciesSize(3)
.hasDependency(Dependency.createSpringBootStarter("web"))
// alias: jpa -> data-jpa
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
}
@@ -106,10 +108,11 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
ProjectStructure project = downloadZip("/starter.zip");
assertDefaultProject(project);
assertDoesNotHaveWebResources(project);
assertThat(project).mavenBuild().hasDependenciesSize(2)
// the root dep is added if none is specified
.hasDependency(Dependency.createSpringBootStarter(""))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
assertThat(project).mavenBuild()
.hasDependenciesSize(2)
// the root dep is added if none is specified
.hasDependency(Dependency.createSpringBootStarter(""))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
}
@Test
@@ -117,10 +120,12 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
ProjectStructure project = downloadZip("/starter.zip?dependencies=web&dependencies=jpa");
assertDefaultProject(project);
assertHasWebResources(project);
assertThat(project).mavenBuild().hasDependenciesSize(3).hasDependency(Dependency.createSpringBootStarter("web"))
// alias: jpa -> data-jpa
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
assertThat(project).mavenBuild()
.hasDependenciesSize(3)
.hasDependency(Dependency.createSpringBootStarter("web"))
// alias: jpa -> data-jpa
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
}
@Test
@@ -128,10 +133,12 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
ProjectStructure project = downloadZip("/starter.zip?dependencies=web,jpa");
assertDefaultProject(project);
assertHasWebResources(project);
assertThat(project).mavenBuild().hasDependenciesSize(3).hasDependency(Dependency.createSpringBootStarter("web"))
// alias: jpa -> data-jpa
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
assertThat(project).mavenBuild()
.hasDependenciesSize(3)
.hasDependency(Dependency.createSpringBootStarter("web"))
// alias: jpa -> data-jpa
.hasDependency(Dependency.createSpringBootStarter("data-jpa"))
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
}
@Test
@@ -158,21 +165,23 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
@Test
void missingDependencyProperException() {
assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> downloadArchive("/starter.zip?dependencies=foo:bar")).satisfies((ex) -> {
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Unknown dependency 'foo:bar' check project metadata");
});
.isThrownBy(() -> downloadArchive("/starter.zip?dependencies=foo:bar"))
.satisfies((ex) -> {
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Unknown dependency 'foo:bar' check project metadata");
});
}
@Test
void invalidDependencyProperException() {
assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> downloadArchive("/starter.zip?dependencies=foo")).satisfies((ex) -> {
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Unknown dependency 'foo' check project metadata");
});
.isThrownBy(() -> downloadArchive("/starter.zip?dependencies=foo"))
.satisfies((ex) -> {
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Unknown dependency 'foo' check project metadata");
});
}
@Test
@@ -197,11 +206,12 @@ class ProjectGenerationControllerIntegrationTests extends AbstractInitializrCont
private void assertUsingStyleIsFailingForUrl(String url) {
assertThatExceptionOfType(HttpClientErrorException.class)
.isThrownBy(() -> getRestTemplate().getForEntity(createUrl(url), byte[].class)).satisfies((ex) -> {
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Dependencies must be specified using 'dependencies'");
});
.isThrownBy(() -> getRestTemplate().getForEntity(createUrl(url), byte[].class))
.satisfies((ex) -> {
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
assertStandardErrorBody(ex.getResponseBodyAsString(),
"Dependencies must be specified using 'dependencies'");
});
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 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.
@@ -52,7 +52,8 @@ class ProjectMetadataControllerCustomDefaultsIntegrationTests extends AbstractFu
void initializeRemoteConfig() throws Exception {
InitializrMetadata localMetadata = this.metadataProvider.get();
InitializrMetadata metadata = InitializrMetadataBuilder.create()
.withInitializrMetadata(new UrlResource(createUrl("/metadata/config"))).build();
.withInitializrMetadata(new UrlResource(createUrl("/metadata/config")))
.build();
// Basic assertions
assertThat(metadata.getDependencies().getContent()).hasSameSizeAs(localMetadata.getDependencies().getContent());
assertThat(metadata.getTypes().getContent()).hasSameSizeAs(localMetadata.getTypes().getContent());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -53,12 +53,12 @@ class DependencyMetadataJsonMapperTests {
JSONObject content = new JSONObject(this.mapper.write(metadata));
assertThat(content.getJSONObject("dependencies").getJSONObject("foo").getString("bom")).isEqualTo("my-bom");
assertThat(content.getJSONObject("dependencies").getJSONObject("foo").getString("repository"))
.isEqualTo("my-repo");
.isEqualTo("my-repo");
assertThat(content.getJSONObject("repositories").getJSONObject("repo-id").getString("name"))
.isEqualTo("foo-repo");
.isEqualTo("foo-repo");
assertThat(content.getJSONObject("boms").getJSONObject("bom-id").getString("artifactId")).isEqualTo("foo-bom");
assertThat(content.getJSONObject("boms").getJSONObject("bom-id").getString("version"))
.isEqualTo("1.0.0.RELEASE");
.isEqualTo("1.0.0.RELEASE");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -44,23 +44,27 @@ class InitializrMetadataV21JsonMapperTests {
@Test
void withNoAppUrl() throws IOException {
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
.addType("foo", true, "/foo.zip", "none", null, "test").addDependencyGroup("foo", "one", "two").build();
.addType("foo", true, "/foo.zip", "none", null, "test")
.addDependencyGroup("foo", "one", "two")
.build();
String json = this.jsonMapper.write(metadata, null);
JsonNode result = objectMapper.readTree(json);
assertThat(get(result, "_links.foo.href"))
.isEqualTo("/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion,"
+ "groupId,artifactId,version,name,description,packageName}");
.isEqualTo("/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion,"
+ "groupId,artifactId,version,name,description,packageName}");
}
@Test
void withAppUrl() throws IOException {
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
.addType("foo", true, "/foo.zip", "none", null, "test").addDependencyGroup("foo", "one", "two").build();
.addType("foo", true, "/foo.zip", "none", null, "test")
.addDependencyGroup("foo", "one", "two")
.build();
String json = this.jsonMapper.write(metadata, "http://server:8080/my-app");
JsonNode result = objectMapper.readTree(json);
assertThat(get(result, "_links.foo.href"))
.isEqualTo("http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion,"
+ "language,bootVersion,groupId,artifactId,version,name,description,packageName}");
.isEqualTo("http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion,"
+ "language,bootVersion,groupId,artifactId,version,name,description,packageName}");
}
@Test
@@ -69,7 +73,8 @@ class InitializrMetadataV21JsonMapperTests {
dependency.getLinks().add(Link.create("guide", "https://example.com/how-to"));
dependency.getLinks().add(Link.create("reference", "https://example.com/doc"));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", dependency).build();
.addDependencyGroup("test", dependency)
.build();
String json = this.jsonMapper.write(metadata, null);
int first = json.indexOf("https://example.com/how-to");
int second = json.indexOf("https://example.com/doc");
@@ -99,7 +104,9 @@ class InitializrMetadataV21JsonMapperTests {
@Test
void platformVersionUsingSemVerUseBackwardCompatibleFormat() throws JsonProcessingException {
InitializrMetadata metadata = new InitializrMetadataTestBuilder().addBootVersion("2.5.0-SNAPSHOT", false)
.addBootVersion("2.5.0-M2", false).addBootVersion("2.4.2", true).build();
.addBootVersion("2.5.0-M2", false)
.addBootVersion("2.4.2", true)
.build();
String json = this.jsonMapper.write(metadata, null);
JsonNode result = objectMapper.readTree(json);
JsonNode platformVersions = result.get("bootVersion");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -59,7 +59,9 @@ class InitializrMetadataV22JsonMapperTests {
@Test
void platformVersionUsingSemVerUIsNotChanged() throws JsonProcessingException {
InitializrMetadata metadata = new InitializrMetadataTestBuilder().addBootVersion("2.5.0-SNAPSHOT", false)
.addBootVersion("2.5.0-M2", false).addBootVersion("2.4.2", true).build();
.addBootVersion("2.5.0-M2", false)
.addBootVersion("2.4.2", true)
.build();
String json = this.jsonMapper.write(metadata, null);
JsonNode result = objectMapper.readTree(json);
JsonNode platformVersions = result.get("bootVersion");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -35,14 +35,16 @@ class DefaultProjectRequestPlatformVersionTransformerTests {
@Test
void formatV1WhenV2IsExpected() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1").build();
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1")
.build();
assertThat(this.transformer.transform(Version.parse("2.4.0.RELEASE"), metadata)).hasToString("2.4.0");
}
@Test
void formatV1WhenV1IsExpected() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1").build();
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1")
.build();
Version version = Version.parse("2.2.0.RELEASE");
assertThat(this.transformer.transform(version, metadata)).isSameAs(version);
}
@@ -50,15 +52,17 @@ class DefaultProjectRequestPlatformVersionTransformerTests {
@Test
void formatV2WhenV1IsExpected() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1").build();
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1")
.build();
assertThat(this.transformer.transform(Version.parse("2.3.0-SNAPSHOT"), metadata))
.hasToString("2.3.0.BUILD-SNAPSHOT");
.hasToString("2.3.0.BUILD-SNAPSHOT");
}
@Test
void formatV2WhenV2IsExpected() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1").build();
.setPlatformVersionFormatCompatibilityRange("[2.0.0.RELEASE,2.4.0-M1)", "2.4.0-M1")
.build();
Version version = Version.parse("2.4.0");
assertThat(this.transformer.transform(version, metadata)).isSameAs(version);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -84,8 +84,8 @@ class DefaultProjectRequestToDescriptionConverterTests {
ProjectRequest request = createProjectRequest();
request.setType("foo-build");
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown type 'foo-build' check project metadata");
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown type 'foo-build' check project metadata");
}
@Test
@@ -96,29 +96,30 @@ class DefaultProjectRequestToDescriptionConverterTests {
ProjectRequest request = createProjectRequest();
request.setType("example-project");
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, testMetadata))
.withMessage("Invalid type 'example-project' (missing build tag) check project metadata");
.isThrownBy(() -> this.converter.convert(request, testMetadata))
.withMessage("Invalid type 'example-project' (missing build tag) check project metadata");
}
@Test
void convertWhenTypeDoesNotDefineDialectTagShouldUseDefaultDialect() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addType("foo", true, "/foo.zip", GradleBuildSystem.ID, null, "test").build();
.addType("foo", true, "/foo.zip", GradleBuildSystem.ID, null, "test")
.build();
ProjectRequest request = createProjectRequest();
request.setType("foo");
assertThat(this.converter.convert(request, metadata).getBuildSystem().dialect())
.isEqualTo(GradleBuildSystem.DIALECT_GROOVY);
.isEqualTo(GradleBuildSystem.DIALECT_GROOVY);
}
@Test
void convertWhenTypeDefinesDialectTagShouldUseDialect() {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addType("foo", true, "/foo.zip", GradleBuildSystem.ID, GradleBuildSystem.DIALECT_KOTLIN, "test")
.build();
.addType("foo", true, "/foo.zip", GradleBuildSystem.ID, GradleBuildSystem.DIALECT_KOTLIN, "test")
.build();
ProjectRequest request = createProjectRequest();
request.setType("foo");
assertThat(this.converter.convert(request, metadata).getBuildSystem().dialect())
.isEqualTo(GradleBuildSystem.DIALECT_KOTLIN);
.isEqualTo(GradleBuildSystem.DIALECT_KOTLIN);
}
@Test
@@ -127,7 +128,7 @@ class DefaultProjectRequestToDescriptionConverterTests {
ProjectRequest request = createProjectRequest();
request.setBootVersion("1.5.9.RELEASE");
assertThat(this.converter.convert(request, this.metadata).getPlatformVersion())
.isEqualTo(Version.parse("1.5.9.RELEASE"));
.isEqualTo(Version.parse("1.5.9.RELEASE"));
}
@Test
@@ -146,12 +147,14 @@ class DefaultProjectRequestToDescriptionConverterTests {
@Test
void convertWhenSpringBootVersionInvalidShouldThrowException() {
this.metadata = InitializrMetadataTestBuilder.withDefaults()
.setPlatformCompatibilityRange("[2.0.0.RELEASE,2.3.0.M1)").build();
.setPlatformCompatibilityRange("[2.0.0.RELEASE,2.3.0.M1)")
.build();
ProjectRequest request = createProjectRequest();
request.setBootVersion("1.5.9.RELEASE");
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, this.metadata)).withMessage(
"Invalid Spring Boot version '1.5.9.RELEASE', Spring Boot compatibility range is >=2.0.0.RELEASE and <2.3.0.M1");
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage(
"Invalid Spring Boot version '1.5.9.RELEASE', Spring Boot compatibility range is >=2.0.0.RELEASE and <2.3.0.M1");
}
@Test
@@ -159,8 +162,8 @@ class DefaultProjectRequestToDescriptionConverterTests {
ProjectRequest request = createProjectRequest();
request.setPackaging("star");
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown packaging 'star' check project metadata");
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown packaging 'star' check project metadata");
}
@Test
@@ -168,8 +171,8 @@ class DefaultProjectRequestToDescriptionConverterTests {
ProjectRequest request = createProjectRequest();
request.setLanguage("english");
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown language 'english' check project metadata");
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown language 'english' check project metadata");
}
@Test
@@ -177,21 +180,22 @@ class DefaultProjectRequestToDescriptionConverterTests {
ProjectRequest request = createProjectRequest();
request.setDependencies(Collections.singletonList("invalid"));
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown dependency 'invalid' check project metadata");
.isThrownBy(() -> this.converter.convert(request, this.metadata))
.withMessage("Unknown dependency 'invalid' check project metadata");
}
@Test
void convertWhenDependencyOutOfRangeShouldThrowException() {
Dependency dependency = Dependency.withId("foo");
dependency.setRange(new VersionRange(Version.parse("2.5.0.M1")));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency)
.build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("foo", dependency)
.build();
ProjectRequest request = createProjectRequest();
request.setDependencies(Collections.singletonList("foo"));
assertThatExceptionOfType(InvalidProjectRequestException.class)
.isThrownBy(() -> this.converter.convert(request, metadata))
.withMessage("Dependency 'foo' is not compatible " + "with Spring Boot 2.4.1");
.isThrownBy(() -> this.converter.convert(request, metadata))
.withMessage("Dependency 'foo' is not compatible " + "with Spring Boot 2.4.1");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -41,8 +41,8 @@ class ProjectGenerationDescriptionCustomizerTests extends AbstractInitializrCont
ProjectStructure project = downloadZip("/starter.zip?bootVersion=2.0.4.RELEASE&javaVersion=1.8");
assertDefaultJavaProject(project);
assertThat(project).mavenBuild()
.hasParent("org.springframework.boot", "spring-boot-starter-parent", "2.2.3.RELEASE")
.hasProperty("java.version", "1.7");
.hasParent("org.springframework.boot", "spring-boot-starter-parent", "2.2.3.RELEASE")
.hasProperty("java.version", "1.7");
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2023 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.
@@ -117,10 +117,14 @@ public class ProjectGenerationInvokerTests {
request.initialize(metadata);
byte[] bytes = this.invoker.invokeBuildGeneration(request);
String content = new String(bytes);
new MavenBuildAssert(content).hasGroupId(request.getGroupId()).hasArtifactId(request.getArtifactId())
.hasVersion(request.getVersion()).doesNotHaveNode("/project/packaging").hasName(request.getName())
.hasDescription(request.getDescription()).hasProperty("java.version", request.getJavaVersion())
.hasParent("org.springframework.boot", "spring-boot-starter-parent", request.getBootVersion());
new MavenBuildAssert(content).hasGroupId(request.getGroupId())
.hasArtifactId(request.getArtifactId())
.hasVersion(request.getVersion())
.doesNotHaveNode("/project/packaging")
.hasName(request.getName())
.hasDescription(request.getDescription())
.hasProperty("java.version", request.getJavaVersion())
.hasParent("org.springframework.boot", "spring-boot-starter-parent", request.getBootVersion());
verifyProjectSuccessfulEventFor(request);
}
@@ -132,8 +136,8 @@ public class ProjectGenerationInvokerTests {
byte[] bytes = this.invoker.invokeBuildGeneration(request);
String content = new String(bytes);
new GroovyDslGradleBuildAssert(content).hasVersion(request.getVersion())
.hasPlugin("org.springframework.boot", request.getBootVersion())
.hasSourceCompatibility(request.getJavaVersion());
.hasPlugin("org.springframework.boot", request.getBootVersion())
.hasSourceCompatibility(request.getJavaVersion());
verifyProjectSuccessfulEventFor(request);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 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.
@@ -42,8 +42,10 @@ class CommandLineHelpGeneratorTests {
@Test
void generateGenericCapabilities() throws IOException {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test",
createDependency("id-b", "depB"), createDependency("id-a", "depA", "and some description")).build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-b", "depB"),
createDependency("id-a", "depA", "and some description"))
.build();
String content = this.generator.generateGenericCapabilities(metadata, "https://fake-service");
assertCommandLineCapabilities(content);
assertThat(content).contains("id-a | and some description |");
@@ -71,7 +73,8 @@ class CommandLineHelpGeneratorTests {
Dependency dependency = createDependency("dep", "some description");
dependency.setAliases(Arrays.asList("legacy", "another"));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", dependency).build();
.addDependencyGroup("test", dependency)
.build();
String content = this.generator.generateGenericCapabilities(metadata, "https://fake-service");
assertCommandLineCapabilities(content);
assertThat(content).contains("dep | some description |");
@@ -80,8 +83,10 @@ class CommandLineHelpGeneratorTests {
@Test
void generateCurlCapabilities() throws IOException {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test",
createDependency("id-b", "depB"), createDependency("id-a", "depA", "and some description")).build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-b", "depB"),
createDependency("id-a", "depA", "and some description"))
.build();
String content = this.generator.generateCurlCapabilities(metadata, "https://fake-service");
assertCommandLineCapabilities(content);
assertThat(content).contains("id-a | and some description |");
@@ -95,9 +100,9 @@ class CommandLineHelpGeneratorTests {
void generateGeneralCapabilitiesWithDefaultLineWrap() throws IOException {
CommandLineHelpGenerator lineWrapTemplateGenerator = new CommandLineHelpGenerator(template);
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-a", "Short description"), createDependency("id-b",
"Version control for your database so you can migrate from any version (incl. an empty database) to the latest version of the schema."))
.build();
.addDependencyGroup("test", createDependency("id-a", "Short description"), createDependency("id-b",
"Version control for your database so you can migrate from any version (incl. an empty database) to the latest version of the schema."))
.build();
String content = lineWrapTemplateGenerator.generateGenericCapabilities(metadata, "https://fake-service");
assertCommandLineCapabilities(content);
assertThat(readAllLines(content)).containsSequence(
@@ -113,9 +118,9 @@ class CommandLineHelpGeneratorTests {
void generateGeneralCapabilitiesWithCustomLineWrap() throws IOException {
CommandLineHelpGenerator lineWrapTemplateGenerator = new CommandLineHelpGenerator(template, 100);
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-a", "Short description"), createDependency("id-b",
"Version control for your database so you can migrate from any version (incl. an empty database) to the latest version of the schema."))
.build();
.addDependencyGroup("test", createDependency("id-a", "Short description"), createDependency("id-b",
"Version control for your database so you can migrate from any version (incl. an empty database) to the latest version of the schema."))
.build();
String content = lineWrapTemplateGenerator.generateGenericCapabilities(metadata, "https://fake-service");
assertCommandLineCapabilities(content);
assertThat(readAllLines(content)).containsSequence(
@@ -128,8 +133,10 @@ class CommandLineHelpGeneratorTests {
@Test
void generateHttpCapabilities() throws IOException {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test",
createDependency("id-b", "depB"), createDependency("id-a", "depA", "and some description")).build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-b", "depB"),
createDependency("id-a", "depA", "and some description"))
.build();
String content = this.generator.generateHttpieCapabilities(metadata, "https://fake-service");
assertCommandLineCapabilities(content);
assertThat(content).contains("id-a | and some description |");
@@ -142,8 +149,10 @@ class CommandLineHelpGeneratorTests {
@Test
void generateSpringBootCliCapabilities() throws IOException {
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test",
createDependency("id-b", "depB"), createDependency("id-a", "depA", "and some description")).build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", createDependency("id-b", "depB"),
createDependency("id-a", "depA", "and some description"))
.build();
String content = this.generator.generateSpringBootCliCapabilities(metadata, "https://fake-service");
assertThat(content).contains("| Id");
assertThat(content).contains("| Tags");
@@ -167,7 +176,8 @@ class CommandLineHelpGeneratorTests {
second.setDescription("second desc");
second.setCompatibilityRange(" [1.2.0.RELEASE,1.3.0.M1) ");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", first, second).build();
.addDependencyGroup("test", first, second)
.build();
String content = this.generator.generateSpringBootCliCapabilities(metadata, "https://fake-service");
assertThat(content).contains("| first | first desc | >=1.2.0.RELEASE |");
assertThat(content).contains("| second | second desc | >=1.2.0.RELEASE and <1.3.0.M1 |");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2023 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.
@@ -42,7 +42,8 @@ class DefaultDependencyMetadataProviderTests {
Dependency third = Dependency.withId("third", "org.foo", "third");
third.setCompatibilityRange("2.1.8.RELEASE");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", first, second, third).build();
.addDependencyGroup("test", first, second, third)
.build();
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("2.1.5.RELEASE"));
assertThat(dependencyMetadata.getDependencies()).hasSize(2);
assertThat(dependencyMetadata.getRepositories()).isEmpty();
@@ -54,13 +55,15 @@ class DefaultDependencyMetadataProviderTests {
@Test
void resolveDependencies() {
Dependency first = Dependency.withId("first", "org.foo", "first");
first.getMappings().add(Dependency.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "org.bar", "second",
"0.1.0.RELEASE", null, null, null));
first.getMappings()
.add(Dependency.Mapping.create("1.1.0.RELEASE", "org.biz", "third", "0.2.0.RELEASE", null, null, null));
.add(Dependency.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "org.bar", "second", "0.1.0.RELEASE", null,
null, null));
first.getMappings()
.add(Dependency.Mapping.create("1.1.0.RELEASE", "org.biz", "third", "0.2.0.RELEASE", null, null, null));
Dependency second = Dependency.withId("second", "org.foo", "second");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addDependencyGroup("test", first, second).build();
.addDependencyGroup("test", first, second)
.build();
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.0.5.RELEASE"));
assertThat(dependencyMetadata.getDependencies()).hasSize(2);
@@ -83,14 +86,15 @@ class DefaultDependencyMetadataProviderTests {
Dependency third = Dependency.withId("third", "org.foo", "third");
third.setRepository("repo-foo");
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addReleasesRepository("repo-foo", "my-repo", "http://localhost")
.addDependencyGroup("test", first, second, third).build();
.addReleasesRepository("repo-foo", "my-repo", "http://localhost")
.addDependencyGroup("test", first, second, third)
.build();
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
assertThat(dependencyMetadata.getRepositories()).hasSize(1);
assertThat(dependencyMetadata.getBoms()).isEmpty();
assertThat(dependencyMetadata.getRepositories().get("repo-foo"))
.isSameAs(metadata.getConfiguration().getEnv().getRepositories().get("repo-foo"));
.isSameAs(metadata.getConfiguration().getEnv().getRepositories().get("repo-foo"));
}
@Test
@@ -104,8 +108,10 @@ class DefaultDependencyMetadataProviderTests {
BillOfMaterials bom = BillOfMaterials.create("org.foo", "bom");
bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.8.RELEASE)", "1.0.0.RELEASE"));
bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.8.RELEASE", "2.0.0.RELEASE"));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
.addDependencyGroup("test", first, second, third).build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addBom("bom-foo", bom)
.addDependencyGroup("test", first, second, third)
.build();
DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("1.1.5.RELEASE"));
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
assertThat(dependencyMetadata.getRepositories()).isEmpty();
@@ -151,14 +157,17 @@ class DefaultDependencyMetadataProviderTests {
third.setBom("bom-foo");
BillOfMaterials bom = BillOfMaterials.create("org.foo", "bom");
bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "2.0.0.RELEASE",
"repo-foo", "repo-bar"));
bom.getMappings()
.add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 1.1.0.RELEASE)", "2.0.0.RELEASE", "repo-foo",
"repo-bar"));
bom.getMappings().add(BillOfMaterials.Mapping.create("1.1.0.RELEASE", "3.0.0.RELEASE", "repo-biz"));
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addBom("bom-foo", bom)
.addReleasesRepository("repo-foo", "foo", "http://localhost")
.addReleasesRepository("repo-bar", "bar", "http://localhost")
.addReleasesRepository("repo-biz", "biz", "http://localhost")
.addDependencyGroup("test", first, second, third).build();
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
.addBom("bom-foo", bom)
.addReleasesRepository("repo-foo", "foo", "http://localhost")
.addReleasesRepository("repo-bar", "bar", "http://localhost")
.addReleasesRepository("repo-biz", "biz", "http://localhost")
.addDependencyGroup("test", first, second, third)
.build();
return this.provider.get(metadata, Version.parse(bootVersion));
}

View File

@@ -52,10 +52,12 @@ class SpringBootMetadataReaderTests {
@Test
void readAvailableVersions() throws IOException {
this.server.expect(requestTo("https://api.spring.io/projects/spring-boot/releases")).andRespond(
withSuccess(new ClassPathResource("metadata/springio/spring-boot.json"), MediaType.APPLICATION_JSON));
this.server.expect(requestTo("https://api.spring.io/projects/spring-boot/releases"))
.andRespond(withSuccess(new ClassPathResource("metadata/springio/spring-boot.json"),
MediaType.APPLICATION_JSON));
List<DefaultMetadataElement> versions = new SpringBootMetadataReader(this.objectMapper, this.restTemplate,
this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()).getBootVersions();
this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl())
.getBootVersions();
assertThat(versions).hasSize(7);
assertSpringBootVersion(versions.get(0), "3.0.2-SNAPSHOT", "3.0.2 (SNAPSHOT)", false);
assertSpringBootVersion(versions.get(1), "3.0.1", "3.0.1", true);
@@ -70,10 +72,11 @@ class SpringBootMetadataReaderTests {
@Test
void readAvailableVersionsWithInvalidVersion() throws IOException {
this.server.expect(requestTo("https://api.spring.io/projects/spring-boot/releases"))
.andRespond(withSuccess(new ClassPathResource("metadata/springio/spring-boot-invalid-version.json"),
MediaType.APPLICATION_JSON));
.andRespond(withSuccess(new ClassPathResource("metadata/springio/spring-boot-invalid-version.json"),
MediaType.APPLICATION_JSON));
List<DefaultMetadataElement> versions = new SpringBootMetadataReader(this.objectMapper, this.restTemplate,
this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()).getBootVersions();
this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl())
.getBootVersions();
assertThat(versions).hasSize(1);
assertSpringBootVersion(versions.get(0), "3.0.1", "3.0.1", true);
this.server.verify();

View File

@@ -60,7 +60,8 @@ class SpringIoInitializrMetadataUpdateStrategyTests {
@Test
void bootVersionsAreReplaced() {
InitializrMetadata metadata = new InitializrMetadataTestBuilder().addBootVersion("0.0.9.RELEASE", true)
.addBootVersion("0.0.8.RELEASE", false).build();
.addBootVersion("0.0.8.RELEASE", false)
.build();
assertThat(metadata.getBootVersions().getDefault().getId()).isEqualTo("0.0.9.RELEASE");
SpringIoInitializrMetadataUpdateStrategy provider = new SpringIoInitializrMetadataUpdateStrategy(
this.restTemplate, objectMapper);
@@ -83,7 +84,8 @@ class SpringIoInitializrMetadataUpdateStrategyTests {
@Test
void defaultBootVersionIsAlwaysSet() {
InitializrMetadata metadata = new InitializrMetadataTestBuilder().addBootVersion("0.0.9.RELEASE", true)
.addBootVersion("0.0.8.RELEASE", false).build();
.addBootVersion("0.0.8.RELEASE", false)
.build();
assertThat(metadata.getBootVersions().getDefault().getId()).isEqualTo("0.0.9.RELEASE");
SpringIoInitializrMetadataUpdateStrategy provider = new SpringIoInitializrMetadataUpdateStrategy(
this.restTemplate, objectMapper);
@@ -111,8 +113,9 @@ class SpringIoInitializrMetadataUpdateStrategyTests {
private void expectJson(String url, String bodyPath) {
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
this.mockServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK).body(new ClassPathResource(bodyPath)).headers(httpHeaders));
this.mockServer.expect(requestTo(url))
.andExpect(method(HttpMethod.GET))
.andRespond(withStatus(HttpStatus.OK).body(new ClassPathResource(bodyPath)).headers(httpHeaders));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
final class JsonFieldPath {
private static final Pattern BRACKETS_AND_ARRAY_PATTERN = Pattern
.compile("\\[\'(.+?)\'\\]|\\[([0-9]+|\\*){0,1}\\]");
.compile("\\[\'(.+?)\'\\]|\\[([0-9]+|\\*){0,1}\\]");
private static final Pattern ARRAY_INDEX_PATTERN = Pattern.compile("\\[([0-9]+|\\*){0,1}\\]");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@@ -74,8 +74,8 @@ public class MockMvcClientHttpRequestFactory implements ClientHttpRequestFactory
HttpStatus status = HttpStatus.valueOf(servletResponse.getStatus());
if (status.value() >= 400) {
requestBuilder = request(HttpMethod.GET, "/error")
.requestAttr(RequestDispatcher.ERROR_STATUS_CODE, status.value())
.requestAttr(RequestDispatcher.ERROR_REQUEST_URI, uri.toString());
.requestAttr(RequestDispatcher.ERROR_STATUS_CODE, status.value())
.requestAttr(RequestDispatcher.ERROR_REQUEST_URI, uri.toString());
if (servletResponse.getErrorMessage() != null) {
requestBuilder.requestAttr(RequestDispatcher.ERROR_MESSAGE,
servletResponse.getErrorMessage());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -31,7 +31,7 @@ public final class MockMvcClientHttpRequestFactoryTestExecutionListener extends
@Override
public void beforeTestClass(TestContext testContext) throws Exception {
ConfigurableBeanFactory beanFactory = (ConfigurableBeanFactory) testContext.getApplicationContext()
.getAutowireCapableBeanFactory();
.getAutowireCapableBeanFactory();
if (!beanFactory.containsBean("mockMvcClientHttpRequestFactory")) {
this.factory = new MockMvcClientHttpRequestFactory(beanFactory.getBean(MockMvc.class));
beanFactory.registerSingleton("mockMvcClientHttpRequestFactory", this.factory);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2023 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.
@@ -81,13 +81,13 @@ public class ResponseFieldSnippet extends TemplatedSnippet {
@Override
public void document(Operation operation) throws IOException {
RestDocumentationContext context = (RestDocumentationContext) operation.getAttributes()
.get(RestDocumentationContext.class.getName());
.get(RestDocumentationContext.class.getName());
WriterResolver writerResolver = (WriterResolver) operation.getAttributes().get(WriterResolver.class.getName());
try (Writer writer = writerResolver.resolve(operation.getName() + "/" + getSnippetName(), this.file, context)) {
Map<String, Object> model = createModel(operation);
model.putAll(getAttributes());
TemplateEngine templateEngine = (TemplateEngine) operation.getAttributes()
.get(TemplateEngine.class.getName());
.get(TemplateEngine.class.getName());
writer.append(templateEngine.compileTemplate(getSnippetName()).render(model));
}
}