().with(TestDemoApplication::class).run(*args)
+ import org.junit.jupiter.api.Test
+ import org.springframework.boot.test.context.SpringBootTest
+ import org.springframework.context.annotation.Import
+
+ @Import(TestcontainersConfiguration::class)
+ @SpringBootTest
+ class DemoApplicationTests {
+
+ @Test
+ fun contextLoads() {
}
- """);
+
+ }
+ """);
}
@Test
void shouldAddHelpSection() {
assertHelpDocument(SPRING_BOOT_VERSION_3_3, "testcontainers", "data-mongodb", "postgresql").contains(
- "https://docs.spring.io/spring-boot/docs/3.3.0/reference/html/features.html#features.testing.testcontainers")
+ "https://docs.spring.io/spring-boot/3.3.0/reference/testing/testcontainers.html#testing.testcontainers")
+ .contains(
+ "https://docs.spring.io/spring-boot/3.3.0/reference/features/dev-services.html#features.dev-services.testcontainers")
+ .contains("mongo:latest")
+ .contains("postgres:latest");
+ }
+
+ @Test
+ void shouldAddHelpSectionWithOldSpringBoot() {
+ assertHelpDocument(SPRING_BOOT_VERSION_3_2, "testcontainers", "data-mongodb", "postgresql").contains(
+ "https://docs.spring.io/spring-boot/docs/3.2.0/reference/html/features.html#features.testing.testcontainers")
.contains(
- "https://docs.spring.io/spring-boot/docs/3.3.0/reference/html/features.html#features.testing.testcontainers.at-development-time")
+ "https://docs.spring.io/spring-boot/docs/3.2.0/reference/html/features.html#features.testing.testcontainers.at-development-time")
.contains("mongo:latest")
.contains("postgres:latest");
}
diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/thymeleaf/ThymeleafBuildCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/thymeleaf/ThymeleafBuildCustomizerTests.java
index 97482ed6c07..9a4eda8b6c0 100644
--- a/start-site/src/test/java/io/spring/start/site/extension/dependency/thymeleaf/ThymeleafBuildCustomizerTests.java
+++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/thymeleaf/ThymeleafBuildCustomizerTests.java
@@ -27,6 +27,7 @@
* Tests for {@link ThymeleafBuildCustomizer}.
*
* @author Stephane Nicoll
+ * @author Moritz Halbritter
*/
class ThymeleafBuildCustomizerTests extends AbstractExtensionTests {
@@ -39,6 +40,15 @@ void thymeleafWithSpringSecurityAndSpringBootAddsExtrasDependency() {
"thymeleaf-extras-springsecurity6"));
}
+ @Test
+ void thymeleafWithOAuth2ClientAndSpringBootAddsExtrasDependency() {
+ ProjectRequest projectRequest = createProjectRequest("thymeleaf", "oauth2-client");
+ assertThat(mavenPom(projectRequest)).hasDependency(Dependency.createSpringBootStarter("thymeleaf"))
+ .hasDependency(Dependency.createSpringBootStarter("oauth2-client"))
+ .hasDependency(Dependency.withId("thymeleaf-extras-spring-security", "org.thymeleaf.extras",
+ "thymeleaf-extras-springsecurity6"));
+ }
+
@Test
void thymeleafWithoutSpringSecurityDoesNotAddExtrasDependency() {
assertThat(mavenPom(createProjectRequest("thymeleaf", "web")))
diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinMavenBuildCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinMavenBuildCustomizerTests.java
new file mode 100644
index 00000000000..f9ffe3ea943
--- /dev/null
+++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinMavenBuildCustomizerTests.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2012-2024 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
+ *
+ * https://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 io.spring.start.site.extension.dependency.vaadin;
+
+import io.spring.initializr.web.project.ProjectRequest;
+import io.spring.start.site.extension.AbstractExtensionTests;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for {@link VaadinMavenBuildCustomizer}.
+ *
+ * @author Moritz Halbritter
+ */
+class VaadinMavenBuildCustomizerTests extends AbstractExtensionTests {
+
+ @Test
+ void shouldAddProductionProfile() {
+ ProjectRequest projectRequest = createProjectRequest("vaadin", "web");
+ assertThat(mavenPom(projectRequest)).hasProfile("production").lines().containsSequence(
+ // @formatter:off
+ " ",
+ " production",
+ " ",
+ " ",
+ " com.vaadin",
+ " vaadin-core",
+ " ",
+ " ",
+ " com.vaadin",
+ " vaadin-dev",
+ " ",
+ " ",
+ " ",
+ "",
+ " ",
+ " ",
+ " ",
+ " ",
+ " com.vaadin",
+ " vaadin-maven-plugin",
+ " ${vaadin.version}",
+ " ",
+ " ",
+ " frontend",
+ " compile",
+ " ",
+ " prepare-frontend",
+ " build-frontend",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " "
+ );
+ // @formatter:on
+ }
+
+}
diff --git a/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinProjectGenerationConfigurationTests.java b/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinProjectGenerationConfigurationTests.java
index 4c6b9d31340..67da3174585 100644
--- a/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinProjectGenerationConfigurationTests.java
+++ b/start-site/src/test/java/io/spring/start/site/extension/dependency/vaadin/VaadinProjectGenerationConfigurationTests.java
@@ -27,30 +27,54 @@
* Tests for {@link VaadinProjectGenerationConfiguration}.
*
* @author Stephane Nicoll
+ * @author Moritz Halbritter
*/
class VaadinProjectGenerationConfigurationTests extends AbstractExtensionTests {
- private static final String SPRING_BOOT_VERSION = "3.2.0";
+ private static final String SPRING_BOOT_VERSION = "3.3.0";
@Test
void mavenBuildWithVaadinAddProductionProfileWithoutProductionModeFlag() {
ProjectRequest request = createProjectRequest("vaadin", "data-jpa");
request.setBootVersion(SPRING_BOOT_VERSION);
- assertThat(mavenPom(request)).hasProfile("production")
- .lines()
- .containsSequence(" ", " production", " ",
- " ", " ",
- " com.vaadin",
- " vaadin-maven-plugin",
- " ${vaadin.version}",
- " ", " ",
- " frontend",
- " compile", " ",
- " prepare-frontend",
- " build-frontend",
- " ", " ",
- " ", " ", " ",
- " ", " ");
+ assertThat(mavenPom(request)).hasProfile("production").lines().containsSequence(
+ // @formatter:off
+ " ",
+ " production",
+ " ",
+ " ",
+ " com.vaadin",
+ " vaadin-core",
+ " ",
+ " ",
+ " com.vaadin",
+ " vaadin-dev",
+ " ",
+ " ",
+ " ",
+ "",
+ " ",
+ " ",
+ " ",
+ " ",
+ " com.vaadin",
+ " vaadin-maven-plugin",
+ " ${vaadin.version}",
+ " ",
+ " ",
+ " frontend",
+ " compile",
+ " ",
+ " prepare-frontend",
+ " build-frontend",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " "
+ );
}
@Test
@@ -87,6 +111,18 @@ void gitIgnoreWithoutVaadinDoesNotIgnoreNodeModules() {
.doesNotContain("node_modules");
}
+ @Test
+ void shouldAddLaunchBrowserProperty() {
+ assertThat(generateProject(createProjectRequest("vaadin"))).textFile("src/main/resources/application.properties")
+ .contains("vaadin.launch-browser=true");
+ }
+
+ @Test
+ void shouldNotAddLaunchBrowserPropertyIfVaadinIsNotSelected() {
+ assertThat(generateProject(createProjectRequest("data-jpa"))).textFile("src/main/resources/application.properties")
+ .doesNotContain("vaadin.launch-browser=true");
+ }
+
@Override
protected ProjectRequest createProjectRequest(String... dependencies) {
ProjectRequest request = super.createProjectRequest(dependencies);
diff --git a/start-site/src/test/java/io/spring/start/site/project/JavaVersionProjectDescriptionCustomizerTests.java b/start-site/src/test/java/io/spring/start/site/project/JavaVersionProjectDescriptionCustomizerTests.java
index d94d38668b9..6d83d76ab4e 100755
--- a/start-site/src/test/java/io/spring/start/site/project/JavaVersionProjectDescriptionCustomizerTests.java
+++ b/start-site/src/test/java/io/spring/start/site/project/JavaVersionProjectDescriptionCustomizerTests.java
@@ -58,7 +58,7 @@ void mavenBuildWithSupportedOptionsDoesNotDowngradeJavaVersion(String language,
@MethodSource("supportedGradleGroovyParameters")
void gradleGroovyBuildWithSupportedOptionsDoesNotDowngradeJavaVersion(String language, String javaVersion,
String springBootVersion) {
- assertThat(gradleBuild(project(language, javaVersion, springBootVersion))).hasSourceCompatibility(javaVersion);
+ assertThat(gradleBuild(project(language, javaVersion, springBootVersion))).hasToolchainForJava(javaVersion);
}
@Test
diff --git a/start-site/src/test/java/io/spring/start/site/test/TestMavenVersionResolver.java b/start-site/src/test/java/io/spring/start/site/test/TestMavenVersionResolver.java
index 3c6fedb07fd..49cac911690 100644
--- a/start-site/src/test/java/io/spring/start/site/test/TestMavenVersionResolver.java
+++ b/start-site/src/test/java/io/spring/start/site/test/TestMavenVersionResolver.java
@@ -19,6 +19,7 @@
import java.util.Map;
import io.spring.initializr.versionresolver.MavenVersionResolver;
+import io.spring.start.testsupport.TemporaryFiles;
/**
* A {@link MavenVersionResolver} for tests, which uses a fixed directory for the cache.
diff --git a/start-site/src/test/resources/dependency/hilla/hilla-maven-profile.xml b/start-site/src/test/resources/dependency/hilla/hilla-maven-profile.xml
deleted file mode 100644
index 6cc09429e49..00000000000
--- a/start-site/src/test/resources/dependency/hilla/hilla-maven-profile.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-
-
- production
-
-
-
- dev.hilla
- hilla-maven-plugin
- ${hilla.version}
-
-
- frontend
- compile
-
- build-frontend
-
-
- true
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/start-site/src/test/resources/junit-platform.properties b/start-site/src/test/resources/junit-platform.properties
index 308777dedba..5c068dfbba1 100644
--- a/start-site/src/test/resources/junit-platform.properties
+++ b/start-site/src/test/resources/junit-platform.properties
@@ -16,4 +16,4 @@
junit.jupiter.execution.parallel.enabled=true
junit.jupiter.execution.parallel.config.strategy=custom
-junit.jupiter.execution.parallel.config.custom.class=io.spring.start.site.test.JunitMaxParallelismStrategy
+junit.jupiter.execution.parallel.config.custom.class=io.spring.start.testsupport.JunitMaxParallelismStrategy
diff --git a/test-support/pom.xml b/test-support/pom.xml
new file mode 100644
index 00000000000..29137b934e6
--- /dev/null
+++ b/test-support/pom.xml
@@ -0,0 +1,51 @@
+
+
+ 4.0.0
+
+ io.spring.start
+ start-parent
+ ${revision}
+
+ test-support
+ Support utilities for tests
+
+
+
+ org.springframework
+ spring-core
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ false
+
+
+
+
+
+
diff --git a/test-support/src/main/java/io/spring/start/testsupport/Homes.java b/test-support/src/main/java/io/spring/start/testsupport/Homes.java
new file mode 100644
index 00000000000..a13f24dabb8
--- /dev/null
+++ b/test-support/src/main/java/io/spring/start/testsupport/Homes.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2012-2024 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
+ *
+ * https://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 io.spring.start.testsupport;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.springframework.util.Assert;
+
+/**
+ * Manages Maven and Gradle home directories.
+ *
+ * The directories are reused, if possible. If no home is available for reuse, a new one
+ * will be created.
+ *
+ * @author Moritz Halbritter
+ */
+public class Homes {
+
+ /**
+ * Maven homes.
+ */
+ public static final Homes MAVEN = new Homes("maven-home");
+
+ /**
+ * Gradle homes.
+ */
+ public static final Homes GRADLE = new Homes("gradle-home");
+
+ private final Set homes = ConcurrentHashMap.newKeySet();
+
+ private final Queue freeHomes = new ConcurrentLinkedQueue<>();
+
+ private final AtomicInteger counter = new AtomicInteger();
+
+ private final String prefix;
+
+ public Homes(String prefix) {
+ this.prefix = prefix;
+ }
+
+ /**
+ * Acquires a path to the home. Callers are responsible to call {@link #release(Path)}
+ * when done.
+ * @return the path to the home
+ */
+ public Path acquire() {
+ Path home = this.freeHomes.poll();
+ if (home == null) {
+ home = createTempDirectory();
+ this.homes.add(home);
+ }
+ return home;
+ }
+
+ /**
+ * Releases a path to the home.
+ * @param home the path to the home
+ */
+ public void release(Path home) {
+ Assert.state(this.homes.contains(home), "Invalid home '%s'".formatted(home));
+ this.freeHomes.add(home);
+ }
+
+ private Path createTempDirectory() {
+ try {
+ Path path = TemporaryFiles.getTempDir()
+ .resolve("homes")
+ .resolve(this.prefix + "-" + this.counter.getAndIncrement());
+ Files.createDirectories(path);
+ return path;
+ }
+ catch (IOException ex) {
+ throw new UncheckedIOException("Failed to create temp directory", ex);
+ }
+ }
+
+}
diff --git a/start-site/src/test/java/io/spring/start/site/test/JunitMaxParallelismStrategy.java b/test-support/src/main/java/io/spring/start/testsupport/JunitMaxParallelismStrategy.java
similarity index 98%
rename from start-site/src/test/java/io/spring/start/site/test/JunitMaxParallelismStrategy.java
rename to test-support/src/main/java/io/spring/start/testsupport/JunitMaxParallelismStrategy.java
index 97d3c63bbf4..9b0e22f19fb 100644
--- a/start-site/src/test/java/io/spring/start/site/test/JunitMaxParallelismStrategy.java
+++ b/test-support/src/main/java/io/spring/start/testsupport/JunitMaxParallelismStrategy.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package io.spring.start.site.test;
+package io.spring.start.testsupport;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Predicate;
diff --git a/start-site/src/test/java/io/spring/start/site/test/TemporaryFiles.java b/test-support/src/main/java/io/spring/start/testsupport/TemporaryFiles.java
similarity index 98%
rename from start-site/src/test/java/io/spring/start/site/test/TemporaryFiles.java
rename to test-support/src/main/java/io/spring/start/testsupport/TemporaryFiles.java
index 70151d6053c..92fab023fe3 100644
--- a/start-site/src/test/java/io/spring/start/site/test/TemporaryFiles.java
+++ b/test-support/src/main/java/io/spring/start/testsupport/TemporaryFiles.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package io.spring.start.site.test;
+package io.spring.start.testsupport;
import java.io.IOException;
import java.nio.file.Files;
diff --git a/test-support/src/main/java/io/spring/start/testsupport/package-info.java b/test-support/src/main/java/io/spring/start/testsupport/package-info.java
new file mode 100644
index 00000000000..1399b403a46
--- /dev/null
+++ b/test-support/src/main/java/io/spring/start/testsupport/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2012-2024 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
+ *
+ * https://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.
+ */
+
+/**
+ * Test support classes.
+ */
+package io.spring.start.testsupport;
diff --git a/test-support/src/test/java/io/spring/start/testsupport/HomesTests.java b/test-support/src/test/java/io/spring/start/testsupport/HomesTests.java
new file mode 100644
index 00000000000..3411d61ad40
--- /dev/null
+++ b/test-support/src/test/java/io/spring/start/testsupport/HomesTests.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2012-2024 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
+ *
+ * https://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 io.spring.start.testsupport;
+
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests for {@link Homes}.
+ *
+ * @author Moritz Halbritter
+ */
+class HomesTests {
+
+ @Test
+ void shouldAcquireNewHome() {
+ Homes homes = new Homes("test");
+ Path home1 = homes.acquire();
+ Path home2 = homes.acquire();
+ assertThat(home1).isNotEqualTo(home2);
+ homes.release(home1);
+ Path home3 = homes.acquire();
+ assertThat(home3).isEqualTo(home1);
+ }
+
+}