mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-17 09:35:53 +08:00
Move assert to AssertJ
This commit moves project-based assertions to regular AssertJ Assert classes. `ProjectStructure` is now an assert provider so that it can be used with the standard `assertThat` method. Specialized assertions are provided for the supported build systems as well as text-based content. Closes gh-764
This commit is contained in:
@@ -59,11 +59,6 @@
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
|
||||
@@ -28,7 +28,6 @@ import io.spring.initializr.generator.project.ProjectDescription;
|
||||
import io.spring.initializr.generator.project.ProjectGenerationContext;
|
||||
import io.spring.initializr.generator.project.ResolvedProjectDescription;
|
||||
import io.spring.initializr.generator.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectGeneratorTester;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
@@ -55,26 +54,26 @@ public abstract class AbstractComplianceTests {
|
||||
this.tempDir = dir;
|
||||
}
|
||||
|
||||
protected ProjectAssert generateProject(Language language, BuildSystem buildSystem, String version) {
|
||||
protected ProjectStructure generateProject(Language language, BuildSystem buildSystem, String version) {
|
||||
return generateProject(language, buildSystem, version, (description) -> {
|
||||
});
|
||||
}
|
||||
|
||||
protected ProjectAssert generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
protected ProjectStructure generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
Consumer<ProjectDescription> descriptionCustomizer) {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("web", WEB)
|
||||
.build();
|
||||
return generateProject(language, buildSystem, version, descriptionCustomizer, metadata);
|
||||
}
|
||||
|
||||
protected ProjectAssert generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
protected ProjectStructure generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
Consumer<ProjectDescription> descriptionCustomizer, Consumer<ProjectGenerationContext> contextCustomizer) {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("web", WEB)
|
||||
.build();
|
||||
return generateProject(language, buildSystem, version, descriptionCustomizer, metadata, contextCustomizer);
|
||||
}
|
||||
|
||||
protected ProjectAssert generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
protected ProjectStructure generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
Consumer<ProjectDescription> descriptionCustomizer, InitializrMetadata metadata) {
|
||||
return generateProject(language, buildSystem, version, descriptionCustomizer, metadata,
|
||||
(projectGenerationContext) -> {
|
||||
@@ -82,7 +81,7 @@ public abstract class AbstractComplianceTests {
|
||||
|
||||
}
|
||||
|
||||
private ProjectAssert generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
private ProjectStructure generateProject(Language language, BuildSystem buildSystem, String version,
|
||||
Consumer<ProjectDescription> descriptionCustomizer, InitializrMetadata metadata,
|
||||
Consumer<ProjectGenerationContext> contextCustomizer) {
|
||||
ProjectGeneratorTester projectTester = new ProjectGeneratorTester().withDirectory(this.tempDir)
|
||||
@@ -91,9 +90,7 @@ public abstract class AbstractComplianceTests {
|
||||
.withDescriptionCustomizer(descriptionCustomizer)
|
||||
.withContextInitializer((context) -> setupProjectGenerationContext(metadata, context))
|
||||
.withContextInitializer(contextCustomizer);
|
||||
ProjectStructure projectStructure = projectTester.generate(new ProjectDescription());
|
||||
Path resolve = projectStructure.resolve("");
|
||||
return new ProjectAssert(resolve);
|
||||
return projectTester.generate(new ProjectDescription());
|
||||
}
|
||||
|
||||
private void setupProjectGenerationContext(InitializrMetadata metadata, ProjectGenerationContext context) {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package io.spring.initializr.generator.spring;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
@@ -26,6 +25,7 @@ import io.spring.initializr.generator.project.ProjectGenerationConfiguration;
|
||||
import io.spring.initializr.generator.project.ProjectGenerator;
|
||||
import io.spring.initializr.generator.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.test.project.ProjectGeneratorTester;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -58,8 +58,8 @@ class ProjectGeneratorIntegrationTests {
|
||||
description.setLanguage(new JavaLanguage());
|
||||
description.setGroupId("com.example");
|
||||
description.setBaseDirectory("test/demo-app");
|
||||
List<String> relativePaths = this.projectTester.generate(description).getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).containsOnly("test/demo-app/.gitignore", "test/demo-app/pom.xml",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).filePaths().containsOnly("test/demo-app/.gitignore", "test/demo-app/pom.xml",
|
||||
"test/demo-app/mvnw", "test/demo-app/mvnw.cmd",
|
||||
"test/demo-app/.mvn/wrapper/MavenWrapperDownloader.java",
|
||||
"test/demo-app/.mvn/wrapper/maven-wrapper.properties", "test/demo-app/.mvn/wrapper/maven-wrapper.jar",
|
||||
|
||||
@@ -28,7 +28,7 @@ import io.spring.initializr.generator.language.kotlin.KotlinLanguage;
|
||||
import io.spring.initializr.generator.packaging.Packaging;
|
||||
import io.spring.initializr.generator.spring.AbstractComplianceTests;
|
||||
import io.spring.initializr.generator.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
import io.spring.initializr.generator.version.VersionProperty;
|
||||
import io.spring.initializr.metadata.BillOfMaterials;
|
||||
@@ -41,6 +41,8 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Build compliance tests.
|
||||
*
|
||||
@@ -86,9 +88,8 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
}
|
||||
|
||||
private void testCurrentGenerationJar(Language language, BuildSystem build, String fileName) {
|
||||
ProjectAssert project = generateProject(language, build, "2.1.1.RELEASE");
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/standard/" + getAssertFileName(fileName)));
|
||||
assertThat(generateProject(language, build, "2.1.1.RELEASE")).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + language + "/standard/" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -110,11 +111,11 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
}
|
||||
|
||||
private void testCurrentGenerationWar(Language language, BuildSystem build, String fileName) {
|
||||
ProjectAssert project = generateProject(language, build, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(language, build, "2.1.1.RELEASE", (description) -> {
|
||||
description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB));
|
||||
description.setPackaging(Packaging.forId("war"));
|
||||
});
|
||||
project.sourceCodeAssert(fileName).equalsTo(
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + language + "/standard/war-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@@ -137,9 +138,9 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
}
|
||||
|
||||
private void testNextGenerationJar(Language language, BuildSystem build, String fileName) {
|
||||
ProjectAssert project = generateProject(language, build, "2.2.0.RELEASE");
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/next/" + getAssertFileName(fileName)));
|
||||
ProjectStructure project = generateProject(language, build, "2.2.0.RELEASE");
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + language + "/next/" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -161,24 +162,24 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
}
|
||||
|
||||
private void testPreviousGenerationJar(Language language, BuildSystem build, String fileName) {
|
||||
ProjectAssert project = generateProject(language, build, "1.5.18.RELEASE");
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/previous/" + getAssertFileName(fileName)));
|
||||
ProjectStructure project = generateProject(language, build, "1.5.18.RELEASE");
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + language + "/previous/" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void kotlinJava11(BuildSystem build, String fileName) {
|
||||
ProjectAssert project = generateProject(kotlin, build, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(kotlin, build, "2.1.1.RELEASE",
|
||||
(description) -> description.setLanguage(Language.forId(kotlin.id(), "11")));
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + build + "/kotlin-java11-" + getAssertFileName(fileName)));
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/kotlin-java11-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void versionOverride(BuildSystem build, String fileName) {
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
(description) -> description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB)),
|
||||
(projectGenerationContext) -> projectGenerationContext.registerBean(BuildCustomizer.class,
|
||||
() -> (projectBuild) -> {
|
||||
@@ -186,7 +187,7 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
"0.1.0.RELEASE");
|
||||
projectBuild.addVersionProperty(VersionProperty.of("spring-bar.version"), "0.2.0.RELEASE");
|
||||
}));
|
||||
project.sourceCodeAssert(fileName).equalsTo(
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/version-override-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@@ -199,10 +200,10 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
bom.setVersionProperty("foo.version");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", foo)
|
||||
.addBom("the-bom", bom).build();
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
(description) -> description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo)), metadata);
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + build + "/bom-property-" + getAssertFileName(fileName)));
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/bom-property-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -213,12 +214,12 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
foo.setScope(Dependency.SCOPE_COMPILE_ONLY);
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("core", "web", "data-jpa").addDependencyGroup("foo", foo).build();
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo));
|
||||
description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB));
|
||||
description.addDependency("data-jpa", MetadataBuildItemMapper.toDependency(dataJpa));
|
||||
}, metadata);
|
||||
project.sourceCodeAssert(fileName).equalsTo(
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/compile-only-dependency-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@@ -232,13 +233,13 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("core", "web", "data-jpa")
|
||||
.addDependencyGroup("configuration-processor", annotationProcessor).build();
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
description.addDependency("configuration-processor",
|
||||
MetadataBuildItemMapper.toDependency(annotationProcessor));
|
||||
description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB));
|
||||
description.addDependency("data-jpa", MetadataBuildItemMapper.toDependency(dataJpa));
|
||||
}, metadata);
|
||||
project.sourceCodeAssert(fileName).equalsTo(new ClassPathResource(
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(new ClassPathResource(
|
||||
"project/" + build + "/annotation-processor-dependency-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@@ -258,10 +259,10 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
fooBom.getAdditionalBoms().add("biz-bom");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", foo)
|
||||
.addBom("foo-bom", fooBom).addBom("bar-bom", barBom).addBom("biz-bom", bizBom).build();
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE",
|
||||
(description) -> description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo)), metadata);
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + build + "/bom-ordering-" + getAssertFileName(fileName)));
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/bom-ordering-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -274,12 +275,12 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test", foo, bar)
|
||||
.addRepository("foo-repository", "foo-repo", "https://example.com/foo", false)
|
||||
.addRepository("bar-repository", "bar-repo", "https://example.com/bar", true).build();
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo));
|
||||
description.addDependency("bar", MetadataBuildItemMapper.toDependency(bar));
|
||||
}, metadata);
|
||||
project.sourceCodeAssert(fileName)
|
||||
.equalsTo(new ClassPathResource("project/" + build + "/repositories-" + getAssertFileName(fileName)));
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/repositories-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -288,11 +289,11 @@ class BuildComplianceTests extends AbstractComplianceTests {
|
||||
Dependency foo = Dependency.withId("foo", "org.acme", "foo");
|
||||
InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("test", foo)
|
||||
.build();
|
||||
ProjectAssert project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(java, build, "2.1.1.RELEASE", (description) -> {
|
||||
description.setPlatformVersion(Version.parse("2.2.0.M1"));
|
||||
description.addDependency("foo", MetadataBuildItemMapper.toDependency(foo));
|
||||
}, metadata);
|
||||
project.sourceCodeAssert(fileName).equalsTo(
|
||||
assertThat(project).textFile(fileName).hasSameContentAs(
|
||||
new ClassPathResource("project/" + build + "/repositories-milestone-" + getAssertFileName(fileName)));
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.build.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.BuildWriter;
|
||||
@@ -92,19 +89,16 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
|
||||
@ParameterizedTest(name = "Spring Boot {0}")
|
||||
@MethodSource("gradleWrapperParameters")
|
||||
void gradleWrapperIsContributedWhenGeneratingGradleKtsProject(String platformVersion, String expectedGradleVersion)
|
||||
throws IOException {
|
||||
void gradleWrapperIsContributedWhenGeneratingGradleKtsProject(String platformVersion,
|
||||
String expectedGradleVersion) {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse(platformVersion));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).containsFiles("gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
"gradle/wrapper/gradle-wrapper.jar");
|
||||
try (Stream<String> lines = Files.lines(projectStructure.resolve("gradle/wrapper/gradle-wrapper.properties"))) {
|
||||
assertThat(lines.filter((line) -> line.contains(String.format("gradle-%s-bin.zip", expectedGradleVersion))))
|
||||
.hasSize(1);
|
||||
}
|
||||
assertThat(project).textFile("gradle/wrapper/gradle-wrapper.properties")
|
||||
.containsOnlyOnce(String.format("gradle-%s-bin.zip", expectedGradleVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,10 +108,9 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
description.setLanguage(new JavaLanguage("11"));
|
||||
description.addDependency("acme",
|
||||
Dependency.withCoordinates("com.example", "acme").scope(DependencyScope.COMPILE).build());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle.kts");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle.kts");
|
||||
assertThat(lines).containsExactly("plugins {", " id(\"org.springframework.boot\") version \"2.1.0.RELEASE\"",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle.kts").containsExactly("plugins {",
|
||||
" id(\"org.springframework.boot\") version \"2.1.0.RELEASE\"",
|
||||
" id(\"io.spring.dependency-management\") version \"1.0.6.RELEASE\"", " java", "}", "",
|
||||
"group = \"com.example\"", "version = \"0.0.1-SNAPSHOT\"",
|
||||
"java.sourceCompatibility = JavaVersion.VERSION_11", "", "repositories {", " mavenCentral()", "}",
|
||||
@@ -131,8 +124,9 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage("11"));
|
||||
List<String> lines = this.projectTester.generate(description).readAllLines("build.gradle.kts");
|
||||
assertThat(lines).contains(" id(\"io.spring.dependency-management\") version \"1.0.6.RELEASE\"");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle.kts").lines()
|
||||
.contains(" id(\"io.spring.dependency-management\") version \"1.0.6.RELEASE\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,10 +134,11 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage("11"));
|
||||
List<String> lines = this.projectTester
|
||||
ProjectStructure project = this.projectTester
|
||||
.withBean(DependencyManagementPluginVersionResolver.class, () -> (d) -> "1.5.1.RC1")
|
||||
.generate(description).readAllLines("build.gradle.kts");
|
||||
assertThat(lines).contains(" id(\"io.spring.dependency-management\") version \"1.5.1.RC1\"");
|
||||
.generate(description);
|
||||
assertThat(project).textFile("build.gradle.kts").lines()
|
||||
.contains(" id(\"io.spring.dependency-management\") version \"1.5.1.RC1\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,9 +147,8 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
description.setPackaging(new WarPackaging());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle.kts");
|
||||
assertThat(projectStructure.readAllLines("build.gradle.kts")).containsOnlyOnce(" war");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle.kts").lines().containsOnlyOnce(" war");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -162,10 +156,9 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle.kts");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle.kts");
|
||||
assertThat(lines).containsSequence("tasks.withType<Test> {", " useJUnitPlatform()", "}");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle.kts").lines().containsSequence("tasks.withType<Test> {",
|
||||
" useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,10 +166,9 @@ class GradleKtsProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle.kts");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle.kts");
|
||||
assertThat(lines).doesNotContainSequence("tasks.withType<Test> {", " useJUnitPlatform()", "}");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle.kts").lines().doesNotContainSequence("tasks.withType<Test> {",
|
||||
" useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,7 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.build.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -93,19 +90,15 @@ class GradleProjectGenerationConfigurationTests {
|
||||
|
||||
@ParameterizedTest(name = "Spring Boot {0}")
|
||||
@MethodSource("gradleWrapperParameters")
|
||||
void gradleWrapperIsContributedWhenGeneratingGradleProject(String platformVersion, String expectedGradleVersion)
|
||||
throws IOException {
|
||||
void gradleWrapperIsContributedWhenGeneratingGradleProject(String platformVersion, String expectedGradleVersion) {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse(platformVersion));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).containsFiles("gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
"gradle/wrapper/gradle-wrapper.jar");
|
||||
try (Stream<String> lines = Files.lines(projectStructure.resolve("gradle/wrapper/gradle-wrapper.properties"))) {
|
||||
assertThat(lines.filter((line) -> line.contains(String.format("gradle-%s-bin.zip", expectedGradleVersion))))
|
||||
.hasSize(1);
|
||||
}
|
||||
assertThat(project).textFile("gradle/wrapper/gradle-wrapper.properties")
|
||||
.containsOnlyOnce(String.format("gradle-%s-bin.zip", expectedGradleVersion));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,11 +108,9 @@ class GradleProjectGenerationConfigurationTests {
|
||||
description.setLanguage(new JavaLanguage("11"));
|
||||
description.addDependency("acme",
|
||||
Dependency.withCoordinates("com.example", "acme").scope(DependencyScope.COMPILE).build());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).containsExactly("plugins {", " id 'org.springframework.boot' version '2.1.0.RELEASE'",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").containsExactly("plugins {",
|
||||
" id 'org.springframework.boot' version '2.1.0.RELEASE'",
|
||||
" id 'io.spring.dependency-management' version '1.0.6.RELEASE'", " id 'java'", "}", "",
|
||||
"group = 'com.example'", "version = '0.0.1-SNAPSHOT'", "sourceCompatibility = '11'", "",
|
||||
"repositories {", " mavenCentral()", "}", "", "dependencies {",
|
||||
@@ -129,17 +120,13 @@ class GradleProjectGenerationConfigurationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void warPluginIsAppliedWhenBuildingProjectThatUsesWarPackaging() throws IOException {
|
||||
void warPluginIsAppliedWhenBuildingProjectThatUsesWarPackaging() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
description.setPackaging(new WarPackaging());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> relativePaths = projectStructure.getRelativePathsOfProjectFiles();
|
||||
assertThat(relativePaths).contains("build.gradle");
|
||||
try (Stream<String> lines = Files.lines(projectStructure.resolve("build.gradle"))) {
|
||||
assertThat(lines.filter((line) -> line.contains(" id 'war'"))).hasSize(1);
|
||||
}
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").lines().containsOnlyOnce(" id 'war'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,10 +134,8 @@ class GradleProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).containsSequence("test {", " useJUnitPlatform()", "}");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").lines().containsSequence("test {", " useJUnitPlatform()", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,10 +143,9 @@ class GradleProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).doesNotContainSequence("test {", " useJUnitPlatform()", "}");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").lines().doesNotContainSequence("test {", " useJUnitPlatform()",
|
||||
"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -170,10 +154,8 @@ class GradleProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.M4"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).containsSequence(
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").lines().containsSequence(
|
||||
" testImplementation('org.springframework.boot:spring-boot-starter-test') {",
|
||||
" exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'",
|
||||
" exclude group: 'junit', module: 'junit'", " }");
|
||||
@@ -184,10 +166,8 @@ class GradleProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.M5"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).containsSequence(
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").lines().containsSequence(
|
||||
" testImplementation('org.springframework.boot:spring-boot-starter-test') {",
|
||||
" exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'", " }");
|
||||
}
|
||||
@@ -197,10 +177,8 @@ class GradleProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.6.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("build.gradle");
|
||||
List<String> lines = projectStructure.readAllLines("build.gradle");
|
||||
assertThat(lines).doesNotContain("exclude group");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("build.gradle").doesNotContain("exclude group");
|
||||
}
|
||||
|
||||
static Stream<Arguments> annotationProcessorScopeBuildParameters() {
|
||||
|
||||
@@ -19,19 +19,16 @@ package io.spring.initializr.generator.spring.build.gradle;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.gradle.GradleBuild;
|
||||
import io.spring.initializr.generator.buildsystem.gradle.GroovyDslGradleSettingsWriter;
|
||||
import io.spring.initializr.generator.buildsystem.gradle.KotlinDslGradleSettingsWriter;
|
||||
import io.spring.initializr.generator.io.IndentingWriterFactory;
|
||||
import io.spring.initializr.generator.io.SimpleIndentStrategy;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.test.io.TextAssert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SettingsGradleProjectContributorTests}.
|
||||
*
|
||||
@@ -47,10 +44,9 @@ class SettingsGradleProjectContributorTests {
|
||||
void groovyDslGradleSettingsIsContributedToProject() throws IOException {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add("maven-central");
|
||||
List<String> lines = generateSettings(
|
||||
groovyDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()));
|
||||
assertThat(lines).containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
assertSettings(groovyDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()))
|
||||
.lines().containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,28 +55,26 @@ class SettingsGradleProjectContributorTests {
|
||||
(factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" ")));
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add("maven-central");
|
||||
List<String> lines = generateSettings(groovyDslSettingsGradleProjectContributor(build, indentingWriterFactory));
|
||||
assertThat(lines).containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
assertSettings(groovyDslSettingsGradleProjectContributor(build, indentingWriterFactory)).lines()
|
||||
.containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void groovyDslGradleSettingsDoesNotUseRepositories() throws IOException {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add("maven-central");
|
||||
List<String> lines = generateSettings(
|
||||
groovyDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()));
|
||||
assertThat(lines).doesNotContain("pluginManagement");
|
||||
assertSettings(groovyDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()))
|
||||
.doesNotContain("pluginManagement");
|
||||
}
|
||||
|
||||
@Test
|
||||
void kotlinDslGradleSettingsIsContributedToProject() throws IOException {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add("maven-central");
|
||||
List<String> lines = generateSettings(
|
||||
kotlinDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()));
|
||||
assertThat(lines).containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
assertSettings(kotlinDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()))
|
||||
.lines().containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,24 +83,23 @@ class SettingsGradleProjectContributorTests {
|
||||
(factory) -> factory.indentingStrategy("gradle", new SimpleIndentStrategy(" ")));
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.pluginRepositories().add("maven-central");
|
||||
List<String> lines = generateSettings(kotlinDslSettingsGradleProjectContributor(build, indentingWriterFactory));
|
||||
assertThat(lines).containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
assertSettings(kotlinDslSettingsGradleProjectContributor(build, indentingWriterFactory)).lines()
|
||||
.containsSequence("pluginManagement {", " repositories {", " mavenCentral()",
|
||||
" gradlePluginPortal()", " }", "}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void kotlinDslGradleSettingsDoesNotUseRepositories() throws IOException {
|
||||
GradleBuild build = new GradleBuild();
|
||||
build.repositories().add("maven-central");
|
||||
List<String> lines = generateSettings(
|
||||
kotlinDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()));
|
||||
assertThat(lines).doesNotContain("pluginManagement");
|
||||
assertSettings(kotlinDslSettingsGradleProjectContributor(build, IndentingWriterFactory.withDefaultSettings()))
|
||||
.doesNotContain("pluginManagement");
|
||||
}
|
||||
|
||||
private List<String> generateSettings(SettingsGradleProjectContributor contributor) throws IOException {
|
||||
private TextAssert assertSettings(SettingsGradleProjectContributor contributor) throws IOException {
|
||||
Path projectDir = Files.createTempDirectory(this.directory, "project-");
|
||||
contributor.contribute(projectDir);
|
||||
return new ProjectStructure(projectDir).readAllLines("test.gradle");
|
||||
return new TextAssert(projectDir.resolve("test.gradle"));
|
||||
}
|
||||
|
||||
private SettingsGradleProjectContributor groovyDslSettingsGradleProjectContributor(GradleBuild build,
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package io.spring.initializr.generator.spring.build.maven;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.BuildWriter;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
@@ -70,29 +68,26 @@ class MavenProjectGenerationConfigurationTests {
|
||||
void mavenWrapperIsContributedWhenGeneratingMavenProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("mvnw", "mvnw.cmd",
|
||||
".mvn/wrapper/MavenWrapperDownloader.java", ".mvn/wrapper/maven-wrapper.properties",
|
||||
".mvn/wrapper/maven-wrapper.jar");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).filePaths().contains("mvnw", "mvnw.cmd", ".mvn/wrapper/MavenWrapperDownloader.java",
|
||||
".mvn/wrapper/maven-wrapper.properties", ".mvn/wrapper/maven-wrapper.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mavenPomIsContributedWhenGeneratingMavenProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).filePaths().contains("pom.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
void warPackagingIsUsedWhenBuildingProjectThatUsesWarPackaging() throws IOException {
|
||||
void warPackagingIsUsedWhenBuildingProjectThatUsesWarPackaging() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
|
||||
description.setPackaging(new WarPackaging());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
List<String> lines = projectStructure.readAllLines("pom.xml");
|
||||
assertThat(lines).containsOnlyOnce(" <packaging>war</packaging>");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("pom.xml").containsOnlyOnce(" <packaging>war</packaging>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,11 +96,9 @@ class MavenProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.M4"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
List<String> lines = projectStructure.readAllLines("pom.xml");
|
||||
assertThat(lines).containsSequence(" <exclusions>", " <exclusion>",
|
||||
" <groupId>org.junit.vintage</groupId>",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("pom.xml").lines().containsSequence(" <exclusions>",
|
||||
" <exclusion>", " <groupId>org.junit.vintage</groupId>",
|
||||
" <artifactId>junit-vintage-engine</artifactId>", " </exclusion>",
|
||||
" <exclusion>", " <groupId>junit</groupId>",
|
||||
" <artifactId>junit</artifactId>", " </exclusion>",
|
||||
@@ -117,11 +110,9 @@ class MavenProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.M5"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
List<String> lines = projectStructure.readAllLines("pom.xml");
|
||||
assertThat(lines).containsSequence(" <exclusions>", " <exclusion>",
|
||||
" <groupId>org.junit.vintage</groupId>",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("pom.xml").lines().containsSequence(" <exclusions>",
|
||||
" <exclusion>", " <groupId>org.junit.vintage</groupId>",
|
||||
" <artifactId>junit-vintage-engine</artifactId>", " </exclusion>",
|
||||
" </exclusions>");
|
||||
}
|
||||
@@ -131,10 +122,8 @@ class MavenProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.6.RELEASE"));
|
||||
description.setLanguage(new JavaLanguage());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains("pom.xml");
|
||||
List<String> lines = projectStructure.readAllLines("pom.xml");
|
||||
assertThat(lines).doesNotContain(" <exclusions>");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("pom.xml").doesNotContain(" <exclusions>");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
import io.spring.initializr.generator.language.kotlin.KotlinLanguage;
|
||||
import io.spring.initializr.generator.packaging.Packaging;
|
||||
import io.spring.initializr.generator.spring.AbstractComplianceTests;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
import io.spring.initializr.metadata.support.MetadataBuildItemMapper;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -35,6 +35,8 @@ import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Code compliance tests.
|
||||
*
|
||||
@@ -52,113 +54,115 @@ class CodeComplianceTests extends AbstractComplianceTests {
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationJar(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
project.isGenericProject(ProjectAssert.DEFAULT_PACKAGE_NAME, ProjectAssert.DEFAULT_APPLICATION_NAME,
|
||||
language.id(), extension);
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
assertThat(project).filePaths().contains(
|
||||
String.format("src/main/%s/com/example/demo/DemoApplication.%s", language.id(), extension),
|
||||
String.format("src/test/%s/com/example/demo/DemoApplicationTests.%s", language.id(), extension),
|
||||
"src/main/resources/application.properties");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationWar(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.setPackaging(Packaging.forId("war")));
|
||||
project.isGenericProject(ProjectAssert.DEFAULT_PACKAGE_NAME, ProjectAssert.DEFAULT_APPLICATION_NAME,
|
||||
language.id(), extension);
|
||||
assertThat(project).filePaths().contains(
|
||||
String.format("src/main/%s/com/example/demo/DemoApplication.%s", language.id(), extension),
|
||||
String.format("src/test/%s/com/example/demo/DemoApplicationTests.%s", language.id(), extension),
|
||||
"src/main/resources/application.properties");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationMainClass(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
project.sourceCodeAssert("src/main/" + language + "/com/example/demo/DemoApplication." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "DemoApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplication." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void previousGenerationMainClass(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.setPlatformVersion(Version.parse("1.5.18.RELEASE")));
|
||||
project.sourceCodeAssert("src/main/" + language + "/com/example/demo/DemoApplication." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "DemoApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/previous/" + "/DemoApplication." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationTestClass(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
project.sourceCodeAssert("src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE");
|
||||
assertThat(project).asJvmModule(language, extension).testSource("com.example.demo", "DemoApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/DemoApplicationTests." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationTestClassWeb(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.addDependency("web", MetadataBuildItemMapper.toDependency(WEB)));
|
||||
project.sourceCodeAssert("src/test/" + language + "/com/example/demo/DemoApplicationTests." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/standard/DemoApplicationTestsWeb."
|
||||
assertThat(project).asJvmModule(language, extension).testSource("com.example.demo", "DemoApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/standard/DemoApplicationTestsWeb."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationServletInitializer(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE",
|
||||
(description) -> description.setPackaging(Packaging.forId("war")));
|
||||
project.sourceCodeAssert("src/main/" + language + "/com/example/demo/ServletInitializer." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/standard/" + "ServletInitializer."
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "ServletInitializer")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/standard/" + "ServletInitializer."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void previousGenerationServletInitializer(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE", (description) -> {
|
||||
description.setPackaging(Packaging.forId("war"));
|
||||
description.setPlatformVersion(Version.parse("1.5.18.RELEASE"));
|
||||
});
|
||||
project.sourceCodeAssert("src/main/" + language + "/com/example/demo/ServletInitializer." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/previous/" + "ServletInitializer."
|
||||
assertThat(project).asJvmModule(language, extension).mainSource("com.example.demo", "ServletInitializer")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/previous/" + "ServletInitializer."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void currentGenerationCustomCoordinates(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "2.1.1.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(language, maven, "2.1.1.RELEASE", (description) -> {
|
||||
description.setGroupId("com.example.acme");
|
||||
description.setArtifactId("my-project");
|
||||
description.setPackageName("com.example.acme.myproject");
|
||||
description.setApplicationName("MyProjectApplication");
|
||||
});
|
||||
project.isGenericProject("com.example.acme.myproject", "MyProjectApplication", language.id(), extension);
|
||||
project.sourceCodeAssert(
|
||||
"src/main/" + language + "/com/example/acme/myproject/MyProjectApplication." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
assertThat(project).asJvmModule(language, extension)
|
||||
.mainSource("com.example.acme.myproject", "MyProjectApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/standard/MyProjectApplication." + getExpectedExtension(extension)));
|
||||
project.sourceCodeAssert(
|
||||
"src/test/" + language + "/com/example/acme/myproject/MyProjectApplicationTests." + extension)
|
||||
.equalsTo(new ClassPathResource("project/" + language + "/standard/MyProjectApplicationTests."
|
||||
assertThat(project).asJvmModule(language, extension)
|
||||
.testSource("com.example.acme.myproject", "MyProjectApplicationTests")
|
||||
.hasSameContentAs(new ClassPathResource("project/" + language + "/standard/MyProjectApplicationTests."
|
||||
+ getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parameters")
|
||||
void previousGenerationCustomCoordinates(Language language, String extension) {
|
||||
ProjectAssert project = generateProject(language, maven, "1.5.18.RELEASE", (description) -> {
|
||||
ProjectStructure project = generateProject(language, maven, "1.5.18.RELEASE", (description) -> {
|
||||
description.setGroupId("com.example.acme");
|
||||
description.setArtifactId("my-project");
|
||||
description.setPackageName("com.example.acme.myproject");
|
||||
description.setApplicationName("MyProjectApplication");
|
||||
});
|
||||
project.isGenericProject("com.example.acme.myproject", "MyProjectApplication", language.id(), extension);
|
||||
project.sourceCodeAssert(
|
||||
"src/main/" + language + "/com/example/acme/myproject/MyProjectApplication." + extension)
|
||||
.equalsTo(new ClassPathResource(
|
||||
assertThat(project).asJvmModule(language, extension)
|
||||
.mainSource("com.example.acme.myproject", "MyProjectApplication")
|
||||
.hasSameContentAs(new ClassPathResource(
|
||||
"project/" + language + "/previous/MyProjectApplication." + getExpectedExtension(extension)));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package io.spring.initializr.generator.spring.code.groovy;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
import io.spring.initializr.generator.language.groovy.GroovyLanguage;
|
||||
@@ -58,22 +57,18 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
|
||||
@Test
|
||||
void mainClassIsContributed() {
|
||||
ProjectStructure projectStructure = this.projectTester.generate(new ProjectDescription());
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/groovy/com/example/demo/DemoApplication.groovy");
|
||||
ProjectStructure project = this.projectTester.generate(new ProjectDescription());
|
||||
assertThat(project).containsFiles("src/main/groovy/com/example/demo/DemoApplication.groovy");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassIsContributedWithJUnit4() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
assertThat(lines).containsExactly("package com.example.demo", "", "import org.junit.Test",
|
||||
"import org.junit.runner.RunWith", "import org.springframework.boot.test.context.SpringBootTest",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/test/groovy/com/example/demo/DemoApplicationTests.groovy").containsExactly(
|
||||
"package com.example.demo", "", "import org.junit.Test", "import org.junit.runner.RunWith",
|
||||
"import org.springframework.boot.test.context.SpringBootTest",
|
||||
"import org.springframework.test.context.junit4.SpringRunner", "", "@RunWith(SpringRunner)",
|
||||
"@SpringBootTest", "class DemoApplicationTests {", "", " @Test", " void contextLoads() {",
|
||||
" }", "", "}");
|
||||
@@ -83,12 +78,9 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
void testClassIsContributedWithJUnit5() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/test/groovy/com/example/demo/DemoApplicationTests.groovy");
|
||||
assertThat(lines).containsExactly("package com.example.demo", "", "import org.junit.jupiter.api.Test",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/test/groovy/com/example/demo/DemoApplicationTests.groovy").containsExactly(
|
||||
"package com.example.demo", "", "import org.junit.jupiter.api.Test",
|
||||
"import org.springframework.boot.test.context.SpringBootTest", "", "@SpringBootTest",
|
||||
"class DemoApplicationTests {", "", " @Test", " void contextLoads() {", " }", "", "}");
|
||||
}
|
||||
@@ -98,13 +90,9 @@ class GroovyProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPackaging(new WarPackaging());
|
||||
description.setApplicationName("Demo2Application");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/groovy/com/example/demo/ServletInitializer.groovy");
|
||||
List<String> lines = projectStructure
|
||||
.readAllLines("src/main/groovy/com/example/demo/ServletInitializer.groovy");
|
||||
assertThat(lines).containsExactly("package com.example.demo", "",
|
||||
"import org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/main/groovy/com/example/demo/ServletInitializer.groovy").containsExactly(
|
||||
"package com.example.demo", "", "import org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
"import org.springframework.boot.web.servlet.support.SpringBootServletInitializer", "",
|
||||
"class ServletInitializer extends SpringBootServletInitializer {", "", " @Override",
|
||||
" protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {",
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package io.spring.initializr.generator.spring.code.java;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
@@ -59,21 +58,18 @@ class JavaProjectGenerationConfigurationTests {
|
||||
@Test
|
||||
void mainClassIsContributed() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/java/com/example/demo/DemoApplication.java");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).containsFiles("src/main/java/com/example/demo/DemoApplication.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassIsContributedWithJUnit4() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
List<String> lines = projectStructure.readAllLines("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
assertThat(lines).containsExactly("package com.example.demo;", "", "import org.junit.Test;",
|
||||
"import org.junit.runner.RunWith;", "import org.springframework.boot.test.context.SpringBootTest;",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/test/java/com/example/demo/DemoApplicationTests.java").containsExactly(
|
||||
"package com.example.demo;", "", "import org.junit.Test;", "import org.junit.runner.RunWith;",
|
||||
"import org.springframework.boot.test.context.SpringBootTest;",
|
||||
"import org.springframework.test.context.junit4.SpringRunner;", "", "@RunWith(SpringRunner.class)",
|
||||
"@SpringBootTest", "public class DemoApplicationTests {", "", " @Test",
|
||||
" public void contextLoads() {", " }", "", "}");
|
||||
@@ -83,11 +79,9 @@ class JavaProjectGenerationConfigurationTests {
|
||||
void testClassIsContributedWithJUnit5() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
List<String> lines = projectStructure.readAllLines("src/test/java/com/example/demo/DemoApplicationTests.java");
|
||||
assertThat(lines).containsExactly("package com.example.demo;", "", "import org.junit.jupiter.api.Test;",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/test/java/com/example/demo/DemoApplicationTests.java").containsExactly(
|
||||
"package com.example.demo;", "", "import org.junit.jupiter.api.Test;",
|
||||
"import org.springframework.boot.test.context.SpringBootTest;", "", "@SpringBootTest",
|
||||
"class DemoApplicationTests {", "", " @Test", " void contextLoads() {", " }", "", "}");
|
||||
}
|
||||
@@ -97,12 +91,9 @@ class JavaProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPackaging(new WarPackaging());
|
||||
description.setApplicationName("MyDemoApplication");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/java/com/example/demo/ServletInitializer.java");
|
||||
List<String> lines = projectStructure.readAllLines("src/main/java/com/example/demo/ServletInitializer.java");
|
||||
assertThat(lines).containsExactly("package com.example.demo;", "",
|
||||
"import org.springframework.boot.builder.SpringApplicationBuilder;",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/main/java/com/example/demo/ServletInitializer.java").containsExactly(
|
||||
"package com.example.demo;", "", "import org.springframework.boot.builder.SpringApplicationBuilder;",
|
||||
"import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;", "",
|
||||
"public class ServletInitializer extends SpringBootServletInitializer {", "", " @Override",
|
||||
" protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {",
|
||||
@@ -113,9 +104,8 @@ class JavaProjectGenerationConfigurationTests {
|
||||
void customPackageNameIsUsedWhenGeneratingProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPackageName("com.example.foo");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains(
|
||||
"src/main/java/com/example/foo/DemoApplication.java",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).containsFiles("src/main/java/com/example/foo/DemoApplication.java",
|
||||
"src/test/java/com/example/foo/DemoApplicationTests.java");
|
||||
}
|
||||
|
||||
@@ -123,9 +113,8 @@ class JavaProjectGenerationConfigurationTests {
|
||||
void customApplicationNameIsUsedWhenGeneratingProject() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setApplicationName("MyApplication");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).contains(
|
||||
"src/main/java/com/example/demo/MyApplication.java",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).containsFiles("src/main/java/com/example/demo/MyApplication.java",
|
||||
"src/test/java/com/example/demo/MyApplicationTests.java");
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package io.spring.initializr.generator.spring.code.kotlin;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.buildsystem.Dependency;
|
||||
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
|
||||
@@ -85,21 +84,18 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
|
||||
@Test
|
||||
void mainClassIsContributedWhenGeneratingProject() {
|
||||
ProjectStructure projectStructure = this.projectTester.generate(new ProjectDescription());
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/kotlin/com/example/demo/DemoApplication.kt");
|
||||
ProjectStructure project = this.projectTester.generate(new ProjectDescription());
|
||||
assertThat(project).containsFiles("src/main/kotlin/com/example/demo/DemoApplication.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassIsContributedWithJunit4() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.1.4.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
List<String> lines = projectStructure.readAllLines("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
assertThat(lines).containsExactly("package com.example.demo", "", "import org.junit.Test",
|
||||
"import org.junit.runner.RunWith", "import org.springframework.boot.test.context.SpringBootTest",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/test/kotlin/com/example/demo/DemoApplicationTests.kt").containsExactly(
|
||||
"package com.example.demo", "", "import org.junit.Test", "import org.junit.runner.RunWith",
|
||||
"import org.springframework.boot.test.context.SpringBootTest",
|
||||
"import org.springframework.test.context.junit4.SpringRunner", "", "@RunWith(SpringRunner::class)",
|
||||
"@SpringBootTest", "class DemoApplicationTests {", "", " @Test", " fun contextLoads() {", " }",
|
||||
"", "}");
|
||||
@@ -109,11 +105,9 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
void testClassIsContributedWithJunit5() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPlatformVersion(Version.parse("2.2.0.RELEASE"));
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
List<String> lines = projectStructure.readAllLines("src/test/kotlin/com/example/demo/DemoApplicationTests.kt");
|
||||
assertThat(lines).containsExactly("package com.example.demo", "", "import org.junit.jupiter.api.Test",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/test/kotlin/com/example/demo/DemoApplicationTests.kt").containsExactly(
|
||||
"package com.example.demo", "", "import org.junit.jupiter.api.Test",
|
||||
"import org.springframework.boot.test.context.SpringBootTest", "", "@SpringBootTest",
|
||||
"class DemoApplicationTests {", "", " @Test", " fun contextLoads() {", " }", "", "}");
|
||||
}
|
||||
@@ -123,12 +117,9 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.setPackaging(new WarPackaging());
|
||||
description.setApplicationName("KotlinDemoApplication");
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles())
|
||||
.contains("src/main/kotlin/com/example/demo/ServletInitializer.kt");
|
||||
List<String> lines = projectStructure.readAllLines("src/main/kotlin/com/example/demo/ServletInitializer.kt");
|
||||
assertThat(lines).containsExactly("package com.example.demo", "",
|
||||
"import org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("src/main/kotlin/com/example/demo/ServletInitializer.kt").containsExactly(
|
||||
"package com.example.demo", "", "import org.springframework.boot.builder.SpringApplicationBuilder",
|
||||
"import org.springframework.boot.web.servlet.support.SpringBootServletInitializer", "",
|
||||
"class ServletInitializer : SpringBootServletInitializer() {", "",
|
||||
" override fun configure(application: SpringApplicationBuilder): SpringApplicationBuilder {",
|
||||
@@ -139,9 +130,8 @@ class KotlinProjectGenerationConfigurationTests {
|
||||
void jacksonKotlinModuleShouldBeAddedWhenJsonFacetPresent() {
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.addDependency("foo", Dependency.withCoordinates("com.example", "foo").build());
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
List<String> lines = projectStructure.readAllLines("pom.xml");
|
||||
assertThat(lines).contains(" <dependency>",
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).textFile("pom.xml").contains(" <dependency>",
|
||||
" <groupId>com.fasterxml.jackson.module</groupId>",
|
||||
" <artifactId>jackson-module-kotlin</artifactId>", " </dependency>");
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package io.spring.initializr.generator.spring.configuration;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -41,8 +40,8 @@ class ApplicationPropertiesContributorTests {
|
||||
void applicationConfigurationWithDefaultSettings() throws IOException {
|
||||
Path projectDir = Files.createTempDirectory(this.directory, "project-");
|
||||
new ApplicationPropertiesContributor().contribute(projectDir);
|
||||
List<String> lines = new ProjectStructure(projectDir).readAllLines("src/main/resources/application.properties");
|
||||
assertThat(lines).isEmpty();
|
||||
assertThat(new ProjectStructure(projectDir)).textFile("src/main/resources/application.properties").lines()
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@ package io.spring.initializr.generator.spring.documentation;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.test.io.TextAssert;
|
||||
import org.assertj.core.api.ListAssert;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@@ -61,8 +61,7 @@ class HelpDocumentProjectContributorTests {
|
||||
HelpDocument document = new HelpDocument(this.templateRenderer);
|
||||
document.gettingStarted().addGuideLink("https://test.example.com", "test")
|
||||
.addGuideLink("https://test2.example.com", "test2");
|
||||
List<String> lines = generateDocument(document);
|
||||
assertThat(lines).containsExactly("# Getting Started", "", "### Guides",
|
||||
assertHelpDocument(document).containsExactly("# Getting Started", "", "### Guides",
|
||||
"The following guides illustrate how to use some features concretely:", "",
|
||||
"* [test](https://test.example.com)", "* [test2](https://test2.example.com)");
|
||||
}
|
||||
@@ -72,8 +71,7 @@ class HelpDocumentProjectContributorTests {
|
||||
HelpDocument document = new HelpDocument(this.templateRenderer);
|
||||
document.gettingStarted().addReferenceDocLink("https://test.example.com", "doc")
|
||||
.addReferenceDocLink("https://test2.example.com", "doc2");
|
||||
List<String> lines = generateDocument(document);
|
||||
assertThat(lines).containsExactly("# Getting Started", "", "### Reference Documentation",
|
||||
assertHelpDocument(document).containsExactly("# Getting Started", "", "### Reference Documentation",
|
||||
"For further reference, please consider the following sections:", "",
|
||||
"* [doc](https://test.example.com)", "* [doc2](https://test2.example.com)");
|
||||
}
|
||||
@@ -82,8 +80,7 @@ class HelpDocumentProjectContributorTests {
|
||||
void helpDocumentWithLinksToOtherLinks() throws IOException {
|
||||
HelpDocument document = new HelpDocument(this.templateRenderer);
|
||||
document.gettingStarted().addAdditionalLink("https://test.example.com", "Something");
|
||||
List<String> lines = generateDocument(document);
|
||||
assertThat(lines).containsExactly("# Getting Started", "", "### Additional Links",
|
||||
assertHelpDocument(document).containsExactly("# Getting Started", "", "### Additional Links",
|
||||
"These additional references should also help you:", "", "* [Something](https://test.example.com)");
|
||||
}
|
||||
|
||||
@@ -91,8 +88,7 @@ class HelpDocumentProjectContributorTests {
|
||||
void helpDocumentWithSimpleSection() throws IOException {
|
||||
HelpDocument document = new HelpDocument(this.templateRenderer);
|
||||
document.addSection((writer) -> writer.println(String.format("# My test section%n%n * Test")));
|
||||
List<String> lines = generateDocument(document);
|
||||
assertThat(lines).containsExactly("# My test section", "", " * Test");
|
||||
assertHelpDocument(document).containsExactly("# My test section", "", " * Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,16 +96,15 @@ class HelpDocumentProjectContributorTests {
|
||||
HelpDocument document = new HelpDocument(this.templateRenderer);
|
||||
document.gettingStarted().addGuideLink("https://test.example.com", "test")
|
||||
.addSection((writer) -> writer.println(String.format("# My test section%n%n * Test")));
|
||||
List<String> lines = generateDocument(document);
|
||||
assertThat(lines).containsExactly("# Getting Started", "", "### Guides",
|
||||
assertHelpDocument(document).containsExactly("# Getting Started", "", "### Guides",
|
||||
"The following guides illustrate how to use some features concretely:", "",
|
||||
"* [test](https://test.example.com)", "", "# My test section", "", " * Test");
|
||||
}
|
||||
|
||||
private List<String> generateDocument(HelpDocument document) throws IOException {
|
||||
private ListAssert<String> assertHelpDocument(HelpDocument document) throws IOException {
|
||||
Path projectDir = Files.createTempDirectory(this.directory, "project-");
|
||||
new HelpDocumentProjectContributor(document).contribute(projectDir);
|
||||
return new ProjectStructure(projectDir).readAllLines("HELP.md");
|
||||
return new TextAssert(projectDir.resolve("HELP.md")).lines();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ class HelpDocumentProjectGenerationConfigurationTests {
|
||||
|
||||
@Test
|
||||
void helpDocumentIsNotContributedWithoutLinks() {
|
||||
assertThat(this.projectTester.generate(new ProjectDescription()).getRelativePathsOfProjectFiles()).isEmpty();
|
||||
ProjectStructure project = this.projectTester.generate(new ProjectDescription());
|
||||
assertThat(project).filePaths().isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -65,8 +66,8 @@ class HelpDocumentProjectGenerationConfigurationTests {
|
||||
this.metadataBuilder.addDependencyGroup("test", dependency);
|
||||
ProjectDescription description = new ProjectDescription();
|
||||
description.addDependency("example", null);
|
||||
ProjectStructure projectStructure = this.projectTester.generate(description);
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).containsOnly("HELP.md");
|
||||
ProjectStructure project = this.projectTester.generate(description);
|
||||
assertThat(project).filePaths().containsOnly("HELP.md");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -24,18 +24,18 @@
|
||||
<groupId>io.spring.initializr</groupId>
|
||||
<artifactId>initializr-metadata</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.samskivert</groupId>
|
||||
<artifactId>jmustache</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.buildsystem.gradle;
|
||||
|
||||
import org.assertj.core.api.AbstractStringAssert;
|
||||
|
||||
/**
|
||||
* Very simple assertions for the gradle build.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class GradleBuildAssert extends AbstractStringAssert<GradleBuildAssert> {
|
||||
|
||||
public GradleBuildAssert(String content) {
|
||||
super(content, GradleBuildAssert.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} uses the specified {@code version}.
|
||||
* @param version the version of the build
|
||||
* @return this
|
||||
*/
|
||||
public GradleBuildAssert hasVersion(String version) {
|
||||
return contains("version = '" + version + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} uses an ext build script block declaring the Spring
|
||||
* Boot plugin with the specified version.
|
||||
* @param springBootVersion the spring boot version
|
||||
* @return this
|
||||
*/
|
||||
public GradleBuildAssert hasSpringBootBuildScriptPlugin(String springBootVersion) {
|
||||
return contains("ext {").contains("org.springframework.boot:spring-boot-gradle-plugin:" + springBootVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} declares the Spring Boot plugin with the specified
|
||||
* version.
|
||||
* @param springBootVersion the spring boot version
|
||||
* @return this
|
||||
*/
|
||||
public GradleBuildAssert hasSpringBootPlugin(String springBootVersion) {
|
||||
return contains("id 'org.springframework.boot' version '" + springBootVersion + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} declares a source compatibility for the specified java
|
||||
* version.
|
||||
* @param javaVersion the java version
|
||||
* @return this
|
||||
*/
|
||||
public GradleBuildAssert hasJavaVersion(String javaVersion) {
|
||||
return contains("sourceCompatibility = '" + javaVersion + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} declares the {@code repo.spring.io/snapshot}
|
||||
* repository.
|
||||
* @return this
|
||||
*/
|
||||
public GradleBuildAssert hasSnapshotRepository() {
|
||||
return contains("https://repo.spring.io/snapshot");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} declares a repository with the specified url.
|
||||
* @param url the url of the repository
|
||||
* @return this
|
||||
*/
|
||||
public GradleBuildAssert hasRepository(String url) {
|
||||
return contains("maven { url '" + url + "' }");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} contains only the specified properties.
|
||||
* @param values the property value pairs
|
||||
* @return this for method chaining.
|
||||
*/
|
||||
public GradleBuildAssert hasProperties(String... values) {
|
||||
StringBuilder builder = new StringBuilder(String.format("ext {%n"));
|
||||
if (values.length % 2 == 1) {
|
||||
throw new IllegalArgumentException("Size must be even, it is a set of property=value pairs");
|
||||
}
|
||||
for (int i = 0; i < values.length; i += 2) {
|
||||
builder.append(String.format("\tset('%s', \"%s\")%n", values[i], values[i + 1]));
|
||||
}
|
||||
builder.append("}");
|
||||
return contains(builder.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.buildsystem.gradle;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.test.io.AbstractTextAssert;
|
||||
import io.spring.initializr.generator.test.io.TextTestUtils;
|
||||
|
||||
/**
|
||||
* Simple assertions for a gradle build using the Groovy DSL.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class GroovyDslGradleBuildAssert extends AbstractTextAssert<GroovyDslGradleBuildAssert> {
|
||||
|
||||
public GroovyDslGradleBuildAssert(String content) {
|
||||
super(content, GroovyDslGradleBuildAssert.class);
|
||||
}
|
||||
|
||||
public GroovyDslGradleBuildAssert(Path buildGradleFile) {
|
||||
this(TextTestUtils.readContent(buildGradleFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} defines a plugin with the specified id and version.
|
||||
* @param id the id of the plugin
|
||||
* @param version the version of the plugin
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert hasPlugin(String id, String version) {
|
||||
return contains(String.format("id '%s' version '%s'", id, version));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} defines a plugin with the specified id.
|
||||
* @param id the id of the plugin
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert hasPlugin(String id) {
|
||||
return contains(String.format("id '%s'", id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} uses the specified {@code version}.
|
||||
* @param version the version of the build
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert hasVersion(String version) {
|
||||
return hasProperty("version", version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} uses a source compatibility for the specified java
|
||||
* version.
|
||||
* @param javaVersion the java version
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert hasSourceCompatibility(String javaVersion) {
|
||||
return hasProperty("sourceCompatibility", javaVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} defines a top-level property with the specified name
|
||||
* and value.
|
||||
* @param name the name of the property
|
||||
* @param value the value
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert hasProperty(String name, String value) {
|
||||
return contains(String.format("%s = '%s", name, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code build.gradle} contains only the specified properties.
|
||||
* @param values the property value pairs
|
||||
* @return this for method chaining.
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert containsOnlyExtProperties(String... values) {
|
||||
StringBuilder builder = new StringBuilder(String.format("ext {%n"));
|
||||
if (values.length % 2 == 1) {
|
||||
throw new IllegalArgumentException("Size must be even, it is a set of property=value pairs");
|
||||
}
|
||||
for (int i = 0; i < values.length; i += 2) {
|
||||
builder.append(String.format("\tset('%s', \"%s\")%n", values[i], values[i + 1]));
|
||||
}
|
||||
builder.append("}");
|
||||
return contains(builder.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,38 +16,37 @@
|
||||
|
||||
package io.spring.initializr.generator.test.buildsystem.gradle;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import io.spring.initializr.generator.test.io.AbstractTextAssert;
|
||||
|
||||
/**
|
||||
* Very simple assertions for the gradle settings.
|
||||
* Simple assertions for a gradle settings using the Groovy DSL.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class GradleSettingsAssert {
|
||||
public class GroovyDslGradleSettingsAssert extends AbstractTextAssert<GroovyDslGradleSettingsAssert> {
|
||||
|
||||
private final String content;
|
||||
|
||||
public GradleSettingsAssert(String content) {
|
||||
this.content = content;
|
||||
public GroovyDslGradleSettingsAssert(String content) {
|
||||
super(content, GroovyDslGradleSettingsAssert.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code settings.gradle} defines the specified project name.
|
||||
* @param name the name of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GradleSettingsAssert hasProjectName(String name) {
|
||||
return contains(String.format("rootProject.name = '%s'", name));
|
||||
public GroovyDslGradleSettingsAssert hasProjectName(String name) {
|
||||
return hasProperty("rootProject.name", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code settings.gradle} contains the specified expression.
|
||||
* @param expression an expected expression
|
||||
* @return this
|
||||
* Assert {@code settings.gradle} defines a property with the specified name and
|
||||
* value.
|
||||
* @param name the name of the property
|
||||
* @param value the value
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public GradleSettingsAssert contains(String expression) {
|
||||
assertThat(this.content).contains(expression);
|
||||
return this;
|
||||
public GroovyDslGradleSettingsAssert hasProperty(String name, String value) {
|
||||
return contains(String.format("%s = '%s", name, value));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,107 +18,104 @@ package io.spring.initializr.generator.test.buildsystem.maven;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.test.io.AbstractTextAssert;
|
||||
import io.spring.initializr.generator.test.io.NodeAssert;
|
||||
import io.spring.initializr.generator.test.io.TextTestUtils;
|
||||
import io.spring.initializr.metadata.BillOfMaterials;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.metadata.Repository;
|
||||
import org.assertj.core.api.BooleanAssert;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.assertj.core.api.StringAssert;
|
||||
import org.assertj.core.api.UrlAssert;
|
||||
import org.w3c.dom.DOMException;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* {@link Node} assertions that are specific to a standard Maven POM.
|
||||
* Assertions for a Maven build.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class PomAssert {
|
||||
|
||||
private final String content;
|
||||
public class MavenBuildAssert extends AbstractTextAssert<MavenBuildAssert> {
|
||||
|
||||
private final NodeAssert pom;
|
||||
|
||||
public PomAssert(String content) {
|
||||
this.content = content;
|
||||
public MavenBuildAssert(String content) {
|
||||
super(content, MavenBuildAssert.class);
|
||||
this.pom = new NodeAssert(content);
|
||||
}
|
||||
|
||||
public MavenBuildAssert(Path pomFile) {
|
||||
this(TextTestUtils.readContent(pomFile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified parent.
|
||||
* @param groupId the groupId of the parent
|
||||
* @param artifactId the artifactId of the parent
|
||||
* @param version the version of the parent
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasParent(String groupId, String artifactId, String version) {
|
||||
public MavenBuildAssert hasParent(String groupId, String artifactId, String version) {
|
||||
return hasText("/project/parent/groupId", groupId).hasText("/project/parent/artifactId", artifactId)
|
||||
.hasText("/project/parent/version", version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the standard {@code spring-boot-starter-parent}.
|
||||
* @param version the spring boot version
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasSpringBootParent(String version) {
|
||||
return hasParent("org.springframework.boot", "spring-boot-starter-parent", version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} uses the specified {@code groupId}.
|
||||
* @param groupId the groupId of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasGroupId(String groupId) {
|
||||
public MavenBuildAssert hasGroupId(String groupId) {
|
||||
return hasText("/project/groupId", groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} uses the specified {@code artifactId}.
|
||||
* @param artifactId the artifactId of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasArtifactId(String artifactId) {
|
||||
public MavenBuildAssert hasArtifactId(String artifactId) {
|
||||
return hasText("/project/artifactId", artifactId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} uses the specified {@code version}.
|
||||
* @param version the version of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasVersion(String version) {
|
||||
public MavenBuildAssert hasVersion(String version) {
|
||||
return hasText("/project/version", version);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} uses the specified {@code packaging}.
|
||||
* @param packaging the packaging of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasPackaging(String packaging) {
|
||||
public MavenBuildAssert hasPackaging(String packaging) {
|
||||
return hasText("/project/packaging", packaging);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} uses the specified {@code name}.
|
||||
* @param name the name of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasName(String name) {
|
||||
public MavenBuildAssert hasName(String name) {
|
||||
return hasText("/project/name", name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} uses the specified {@code description}.
|
||||
* @param description the description of the project
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasDescription(String description) {
|
||||
public MavenBuildAssert hasDescription(String description) {
|
||||
return hasText("/project/description", description);
|
||||
}
|
||||
|
||||
@@ -126,85 +123,39 @@ public class PomAssert {
|
||||
* Assert {@code pom.xml} defines the specified property.
|
||||
* @param name the name of the property
|
||||
* @param value the value of the property
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasProperty(String name, String value) {
|
||||
public MavenBuildAssert hasProperty(String name, String value) {
|
||||
return hasText("/project/properties/" + name, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} does not defined the specified property.
|
||||
* Assert {@code pom.xml} does not define the specified property.
|
||||
* @param name the name of the property
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert doesNotHaveProperty(String name) {
|
||||
public MavenBuildAssert doesNotHaveProperty(String name) {
|
||||
return doesNotHaveNode("/project/properties/" + name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified Java version.
|
||||
* @param javaVersion the java version of the project
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasJavaVersion(String javaVersion) {
|
||||
return hasProperty("java.version", javaVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified number of dependencies.
|
||||
* @param count the number of dependencies
|
||||
* @return this
|
||||
* @param size the number of dependencies
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasDependenciesCount(int count) {
|
||||
assertThat(this.pom).nodesAtPath("project/dependencies/dependency").hasSize(count);
|
||||
public MavenBuildAssert hasDependenciesSize(int size) {
|
||||
this.pom.nodesAtPath("project/dependencies/dependency").hasSize(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified starter.
|
||||
* @param starterId the id of the starter (e.g. {@code web} for
|
||||
* {@code spring-boot-starter-web}.
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasSpringBootStarterDependency(String starterId) {
|
||||
return hasDependency("org.springframework.boot", "spring-boot-starter-" + starterId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified starter in the specified scope.
|
||||
* @param starterId the id of the starter (e.g. {@code web} for
|
||||
* {@code spring-boot-starter-web}.
|
||||
* @param scope the scope of the starter
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasSpringBootStarterDependency(String starterId, String scope) {
|
||||
return hasDependency("org.springframework.boot", "spring-boot-starter-" + starterId, null, scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the root {@code spring-boot-starter} starter.
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasSpringBootStarterRootDependency() {
|
||||
return hasDependency("org.springframework.boot", "spring-boot-starter");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the {@code spring-boot-starter-test} starter.
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasSpringBootStarterTest() {
|
||||
return hasSpringBootStarterDependency("test", "test");
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified dependency with no version and compile
|
||||
* scope.
|
||||
* @param groupId the groupId of the dependency
|
||||
* @param artifactId the artifactId of the dependency
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasDependency(String groupId, String artifactId) {
|
||||
public MavenBuildAssert hasDependency(String groupId, String artifactId) {
|
||||
return hasDependency(groupId, artifactId, null);
|
||||
}
|
||||
|
||||
@@ -213,9 +164,9 @@ public class PomAssert {
|
||||
* @param groupId the groupId of the dependency
|
||||
* @param artifactId the artifactId of the dependency
|
||||
* @param version the version of the dependency
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasDependency(String groupId, String artifactId, String version) {
|
||||
public MavenBuildAssert hasDependency(String groupId, String artifactId, String version) {
|
||||
return hasDependency(Dependency.create(groupId, artifactId, version, "compile"));
|
||||
}
|
||||
|
||||
@@ -225,36 +176,35 @@ public class PomAssert {
|
||||
* @param artifactId the artifactId of the dependency
|
||||
* @param version the version of the dependency
|
||||
* @param scope the scope of the dependency
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasDependency(String groupId, String artifactId, String version, String scope) {
|
||||
public MavenBuildAssert hasDependency(String groupId, String artifactId, String version, String scope) {
|
||||
return hasDependency(Dependency.create(groupId, artifactId, version, scope));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified dependency.
|
||||
* @param dependency the dependency
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasDependency(Dependency dependency) {
|
||||
assertThat(this.pom).nodesAtPath("/project/dependencies/dependency").areExactly(1,
|
||||
new Condition<>((candidate) -> {
|
||||
Dependency actual = toDependency(candidate);
|
||||
if (dependency.getGroupId().equals(actual.getGroupId())
|
||||
&& dependency.getArtifactId().equals(actual.getArtifactId())) {
|
||||
if (dependency.getVersion() != null) {
|
||||
assertThat(actual.getVersion()).isEqualTo(dependency.getVersion());
|
||||
}
|
||||
if (dependency.getScope() != null) {
|
||||
assertThat(actual.getScope()).isEqualTo(dependency.getScope());
|
||||
}
|
||||
if (dependency.getType() != null) {
|
||||
assertThat(actual.getType()).isEqualTo(dependency.getType());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, "matching dependency"));
|
||||
public MavenBuildAssert hasDependency(Dependency dependency) {
|
||||
this.pom.nodesAtPath("/project/dependencies/dependency").areExactly(1, new Condition<>((candidate) -> {
|
||||
Dependency actual = toDependency(candidate);
|
||||
if (dependency.getGroupId().equals(actual.getGroupId())
|
||||
&& dependency.getArtifactId().equals(actual.getArtifactId())) {
|
||||
if (dependency.getVersion() != null) {
|
||||
new StringAssert(actual.getVersion()).isEqualTo(dependency.getVersion());
|
||||
}
|
||||
if (dependency.getScope() != null) {
|
||||
new StringAssert(actual.getScope()).isEqualTo(dependency.getScope());
|
||||
}
|
||||
if (dependency.getType() != null) {
|
||||
new StringAssert(actual.getType()).isEqualTo(dependency.getType());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, "matching dependency"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -263,10 +213,10 @@ public class PomAssert {
|
||||
* {@code groupId} and {@code artifactId}.
|
||||
* @param groupId the dependency's groupId
|
||||
* @param artifactId the dependency's artifactId
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert doesNotHaveDependency(String groupId, String artifactId) {
|
||||
assertThat(this.pom).nodesAtPath("/project/dependencies/dependency").noneMatch((candidate) -> {
|
||||
public MavenBuildAssert doesNotHaveDependency(String groupId, String artifactId) {
|
||||
this.pom.nodesAtPath("/project/dependencies/dependency").noneMatch((candidate) -> {
|
||||
Dependency actual = toDependency(candidate);
|
||||
return groupId.equals(actual.getGroupId()) && artifactId.equals(actual.getArtifactId());
|
||||
});
|
||||
@@ -275,11 +225,11 @@ public class PomAssert {
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified number of boms.
|
||||
* @param count the number of boms
|
||||
* @return this
|
||||
* @param size the number of boms
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasBomsCount(int count) {
|
||||
assertThat(this.pom).nodesAtPath("/project/dependencyManagement/dependencies/dependency").hasSize(count);
|
||||
public MavenBuildAssert hasBomsSize(int size) {
|
||||
this.pom.nodesAtPath("/project/dependencyManagement/dependencies/dependency").hasSize(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -288,10 +238,10 @@ public class PomAssert {
|
||||
* @param groupId the groupId of the bom
|
||||
* @param artifactId the artifactId of the bom
|
||||
* @param version the version of the bom
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasBom(String groupId, String artifactId, String version) {
|
||||
assertThat(this.pom).nodesAtPath("/project/dependencyManagement/dependencies/dependency").areExactly(1,
|
||||
public MavenBuildAssert hasBom(String groupId, String artifactId, String version) {
|
||||
this.pom.nodesAtPath("/project/dependencyManagement/dependencies/dependency").areExactly(1,
|
||||
new Condition<>((candidate) -> {
|
||||
BillOfMaterials actual = toBom(candidate);
|
||||
return (actual != null && actual.getGroupId().equals(groupId)
|
||||
@@ -302,11 +252,11 @@ public class PomAssert {
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} defines the specified number of repositories.
|
||||
* @param count the number of repositories
|
||||
* @return this
|
||||
* @param size the number of repositories
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasRepositoriesCount(int count) {
|
||||
assertThat(this.pom).nodesAtPath("/project/repositories/repository").hasSize(count);
|
||||
public MavenBuildAssert hasRepositoriesSize(int size) {
|
||||
this.pom.nodesAtPath("/project/repositories/repository").hasSize(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -316,32 +266,31 @@ public class PomAssert {
|
||||
* @param name the name of the repository
|
||||
* @param url the url of the repository
|
||||
* @param snapshotsEnabled whether snapshot is enabled for the repository
|
||||
* @return this
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public PomAssert hasRepository(String id, String name, String url, Boolean snapshotsEnabled) {
|
||||
assertThat(this.pom).nodesAtPath("/project/repositories/repository").areExactly(1,
|
||||
new Condition<>((candidate) -> {
|
||||
String actualId = ((Element) candidate).getElementsByTagName("id").item(0).getTextContent();
|
||||
if (actualId.equals(id)) {
|
||||
Repository repository = toRepository(candidate);
|
||||
if (name != null) {
|
||||
assertThat(repository.getName()).isEqualTo(name);
|
||||
}
|
||||
if (url != null) {
|
||||
try {
|
||||
assertThat(repository.getUrl()).isEqualTo(new URL(url));
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new IllegalArgumentException("Cannot parse URL", ex);
|
||||
}
|
||||
}
|
||||
if (snapshotsEnabled) {
|
||||
assertThat(repository.isSnapshotsEnabled()).isEqualTo(snapshotsEnabled);
|
||||
}
|
||||
return true;
|
||||
public MavenBuildAssert hasRepository(String id, String name, String url, Boolean snapshotsEnabled) {
|
||||
this.pom.nodesAtPath("/project/repositories/repository").areExactly(1, new Condition<>((candidate) -> {
|
||||
String actualId = ((Element) candidate).getElementsByTagName("id").item(0).getTextContent();
|
||||
if (actualId.equals(id)) {
|
||||
Repository repository = toRepository(candidate);
|
||||
if (name != null) {
|
||||
new StringAssert(repository.getName()).isEqualTo(name);
|
||||
}
|
||||
if (url != null) {
|
||||
try {
|
||||
new UrlAssert(repository.getUrl()).isEqualTo(new URL(url));
|
||||
}
|
||||
return false;
|
||||
}, "matching repository"));
|
||||
catch (MalformedURLException ex) {
|
||||
throw new IllegalArgumentException("Cannot parse URL", ex);
|
||||
}
|
||||
}
|
||||
if (snapshotsEnabled) {
|
||||
new BooleanAssert(repository.isSnapshotsEnabled()).isEqualTo(snapshotsEnabled);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, "matching repository"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -350,28 +299,8 @@ public class PomAssert {
|
||||
* @param path the path of the node
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert doesNotHaveNode(String path) {
|
||||
assertThat(this.pom.nodeAtPath(path)).isNull();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} contains the specified expression.
|
||||
* @param expression an expected expression
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert contains(String expression) {
|
||||
assertThat(this.content).contains(expression);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert {@code pom.xml} does not contain the specified expression.
|
||||
* @param expression an unexpected expression
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert doesNotContain(String expression) {
|
||||
assertThat(this.content).doesNotContain(expression);
|
||||
public MavenBuildAssert doesNotHaveNode(String path) {
|
||||
this.pom.nodeAtPath(path).isNull();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -381,8 +310,8 @@ public class PomAssert {
|
||||
* @param value the expected value of the element
|
||||
* @return this
|
||||
*/
|
||||
public PomAssert hasText(String path, String value) {
|
||||
assertThat(this.pom).textAtPath(path).isEqualTo(value);
|
||||
public MavenBuildAssert hasText(String path, String value) {
|
||||
this.pom.textAtPath(path).isEqualTo(value);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.assertj.core.api.AbstractStringAssert;
|
||||
import org.assertj.core.api.ListAssert;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
/**
|
||||
* Base class for text assertions.
|
||||
*
|
||||
* @param <SELF> the type of the concrete assert implementations
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractTextAssert<SELF extends AbstractStringAssert<SELF>> extends AbstractStringAssert<SELF> {
|
||||
|
||||
protected AbstractTextAssert(String actual, Class<?> selfType) {
|
||||
super(actual, selfType);
|
||||
}
|
||||
|
||||
protected AbstractTextAssert(Path textFile, Class<?> selfType) {
|
||||
this(TextTestUtils.readContent(textFile), selfType);
|
||||
this.info.description("Content at " + textFile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert this text has the same content as the content defined by the specified
|
||||
* {@link Resource}. Differences in newlines are ignored
|
||||
* @param expected a resource with the expected content
|
||||
* @return {@code this} assertion object
|
||||
* @see #isEqualToIgnoringNewLines(CharSequence)
|
||||
*/
|
||||
public SELF hasSameContentAs(Resource expected) {
|
||||
if (!expected.isReadable()) {
|
||||
failWithMessage("Expected resource does not exist: " + expected);
|
||||
}
|
||||
try (InputStream in = expected.getInputStream()) {
|
||||
String expectedContent = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
isEqualToIgnoringNewLines(expectedContent);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
failWithMessage("Cannot read expected content " + expected);
|
||||
}
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert this text contains exactly the specified lines.
|
||||
* @param lines the lines that constitute the content of this text
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF containsExactly(String... lines) {
|
||||
lines().containsExactly(lines);
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an {@link ListAssert assert} for the lines that constitute this text, to
|
||||
* allow chaining of lines-specific assertions from this call.
|
||||
* @return a {@link ListAssert} for the lines that constitutes this text
|
||||
*/
|
||||
public ListAssert<String> lines() {
|
||||
return new ListAssert<>(TextTestUtils.readAllLines(this.actual));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.io;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Assertions for text content.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class TextAssert extends AbstractTextAssert<TextAssert> {
|
||||
|
||||
public TextAssert(String actual) {
|
||||
super(actual, TextAssert.class);
|
||||
}
|
||||
|
||||
public TextAssert(Path textFile) {
|
||||
super(textFile, TextAssert.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,18 +43,6 @@ public final class TextTestUtils {
|
||||
return Arrays.asList(lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all lines from the specified {@link Path source}. Check the given
|
||||
* {@code source} is a regular file that ends with a new line.
|
||||
* @param source a text file
|
||||
* @return all lines from the file
|
||||
*/
|
||||
public static List<String> readAllLines(Path source) {
|
||||
String content = readContent(source);
|
||||
assertThat(content).endsWith(System.lineSeparator());
|
||||
return readAllLines(content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the content from the specified {@link Path source}. Check the given
|
||||
* {@code source} is a regular file.
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.language;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Source code assertions.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class SourceCodeAssert {
|
||||
|
||||
private final String name;
|
||||
|
||||
private final String content;
|
||||
|
||||
public SourceCodeAssert(String name, String content) {
|
||||
this.name = name;
|
||||
this.content = content.replaceAll("\r\n", "\n");
|
||||
}
|
||||
|
||||
public SourceCodeAssert equalsTo(Resource expected) {
|
||||
try (InputStream in = expected.getInputStream()) {
|
||||
String expectedContent = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
assertThat(this.content).describedAs("Content for %s", this.name)
|
||||
.isEqualTo(expectedContent.replaceAll("\r\n", "\n"));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("Cannot read file", ex);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourceCodeAssert hasImports(String... classNames) {
|
||||
for (String className : classNames) {
|
||||
contains("import " + className);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourceCodeAssert doesNotHaveImports(String... classNames) {
|
||||
for (String className : classNames) {
|
||||
doesNotContain("import " + className);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourceCodeAssert contains(String... expressions) {
|
||||
assertThat(this.content).describedAs("Content for %s", this.name).contains(expressions);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SourceCodeAssert doesNotContain(String... expressions) {
|
||||
assertThat(this.content).describedAs("Content for %s", this.name).doesNotContain(expressions);
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.language.Language;
|
||||
import io.spring.initializr.generator.language.SourceStructure;
|
||||
import io.spring.initializr.generator.test.io.TextAssert;
|
||||
import org.assertj.core.api.PathAssert;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Base class for JVM module assertions.
|
||||
*
|
||||
* @param <SELF> the type of the concrete assert implementations
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractJvmModuleAssert<SELF extends AbstractJvmModuleAssert<SELF>>
|
||||
extends AbstractProjectAssert<SELF> {
|
||||
|
||||
private final SourceStructure mainDirectory;
|
||||
|
||||
private final SourceStructure testDirectory;
|
||||
|
||||
private final String sourceFileExtension;
|
||||
|
||||
protected AbstractJvmModuleAssert(Path projectDirectory, Language language, String sourceFileExtension,
|
||||
Class<?> selfType) {
|
||||
super(projectDirectory, selfType);
|
||||
this.mainDirectory = new SourceStructure(projectDirectory.resolve("src/main/"), language.id());
|
||||
this.testDirectory = new SourceStructure(projectDirectory.resolve("src/test/"), language.id());
|
||||
this.sourceFileExtension = sourceFileExtension;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the main source defines the specified package.
|
||||
* @param packageName the name of the package
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasMainPackage(String packageName) {
|
||||
return hasPackage(this.mainDirectory.getSourcesDirectory(), packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the main source defines the specified type.
|
||||
* @param packageName the name of a package
|
||||
* @param name the name of the type
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasMainSource(String packageName, String name) {
|
||||
validateAndGetAsset(this.mainDirectory.getSourcesDirectory(), packageName, name);
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the main source defines the specified type and return an
|
||||
* {@link TextAssert assert} for it, to allow chaining of text-specific assertions
|
||||
* from this call.
|
||||
* @param packageName the name of a package
|
||||
* @param name the name of the type
|
||||
* @return a {@link TextAssert} for the specified source
|
||||
*/
|
||||
public TextAssert mainSource(String packageName, String name) {
|
||||
return new TextAssert(validateAndGetAsset(this.mainDirectory.getSourcesDirectory(), packageName, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the main resources defines the specified resource.
|
||||
* @param resourcePath the path of a resource relative to the {@code resources}
|
||||
* directory
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasMainResource(String resourcePath) {
|
||||
return hasResource(this.mainDirectory.getRootDirectory().resolve("resources"), resourcePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the test source defines the specified package.
|
||||
* @param packageName the name of the package
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasTestPackage(String packageName) {
|
||||
return hasPackage(this.testDirectory.getSourcesDirectory(), packageName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the test source defines the specified type.
|
||||
* @param packageName the name of a package
|
||||
* @param name the name of the type
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasTestSource(String packageName, String name) {
|
||||
validateAndGetAsset(this.testDirectory.getSourcesDirectory(), packageName, name);
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the test source defines the specified type and return an
|
||||
* {@link TextAssert assert} for it, to allow chaining of text-specific assertions
|
||||
* from this call.
|
||||
* @param packageName the name of a package
|
||||
* @param name the name of the type
|
||||
* @return a {@link TextAssert} for the specified source
|
||||
*/
|
||||
public TextAssert testSource(String packageName, String name) {
|
||||
return new TextAssert(validateAndGetAsset(this.testDirectory.getSourcesDirectory(), packageName, name));
|
||||
}
|
||||
|
||||
private SELF hasPackage(Path baseDir, String packageName) {
|
||||
Path expected = baseDir.resolve(packageToPath(packageName));
|
||||
new PathAssert(expected).exists().isDirectory();
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
private Path validateAndGetAsset(Path baseDir, String packageName, String name) {
|
||||
Path source = resolveSource(baseDir, packageName, name);
|
||||
new PathAssert(source)
|
||||
.as("Source '%s.%s' not found in package '%s'", name, this.sourceFileExtension, packageName).exists()
|
||||
.isRegularFile();
|
||||
return source;
|
||||
}
|
||||
|
||||
private SELF hasResource(Path baseDir, String relativePath) {
|
||||
Path path = baseDir.resolve(relativePath);
|
||||
new PathAssert(path).as("Resource '%s' not found", relativePath).exists().isRegularFile();
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
private Path resolveSource(Path baseDir, String packageName, String name) {
|
||||
return baseDir.resolve(createSourceRelativePath(packageName, name));
|
||||
}
|
||||
|
||||
private String createSourceRelativePath(String packageName, String name) {
|
||||
return packageToPath(packageName) + "/" + name + "." + this.sourceFileExtension;
|
||||
}
|
||||
|
||||
private static String packageToPath(String packageName) {
|
||||
String packagePath = packageName.replace(".", "/");
|
||||
return StringUtils.trimTrailingCharacter(packagePath, '/');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.language.Language;
|
||||
import io.spring.initializr.generator.test.buildsystem.gradle.GroovyDslGradleBuildAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.MavenBuildAssert;
|
||||
|
||||
/**
|
||||
* Base class for module assertions.
|
||||
*
|
||||
* @param <SELF> the type of the concrete assert implementations
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractModuleAssert<SELF extends AbstractModuleAssert<SELF>>
|
||||
extends AbstractProjectAssert<SELF> {
|
||||
|
||||
protected AbstractModuleAssert(Path projectDirectory, Class<?> selfType) {
|
||||
super(projectDirectory, selfType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link JvmModuleAssert JVM module} assertion for the specified
|
||||
* {@link Language} and file source extension, to allow chaining of jvm
|
||||
* module-specific assertions from this call.
|
||||
* <p>
|
||||
* Does not validate that the module has source code for the specified language.
|
||||
* @param language the language of the module
|
||||
* @param sourceFileExtension the source file extension
|
||||
* @return a {@link JvmModuleAssert} for the specified language
|
||||
*/
|
||||
public JvmModuleAssert asJvmModule(Language language, String sourceFileExtension) {
|
||||
return new JvmModuleAssert(this.actual, language, sourceFileExtension);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the module defines a {@code pom.xml}.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasMavenBuild() {
|
||||
filePaths().contains("pom.xml");
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the module defines the Maven wrapper.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasMavenWrapper() {
|
||||
filePaths().contains("mvnw", "mvnw.cmd", ".mvn/wrapper/maven-wrapper.properties",
|
||||
".mvn/wrapper/maven-wrapper.jar");
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert this module has a {@code pom.xml} and return an {@link MavenBuildAssert
|
||||
* assert} for the {@code pom.xml} file of this module, to allow chaining of
|
||||
* maven-specific assertions from this call.
|
||||
* @return a {@link MavenBuildAssert}
|
||||
*/
|
||||
public MavenBuildAssert mavenBuild() {
|
||||
hasMavenBuild();
|
||||
return new MavenBuildAssert(this.actual.resolve("pom.xml"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the module defines a {@code build.gradle}.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasGroovyDslGradleBuild() {
|
||||
filePaths().contains("build.gradle");
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the module defines the Gradle wrapper.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF hasGradleWrapper() {
|
||||
filePaths().contains("gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
"gradle/wrapper/gradle-wrapper.jar");
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert this module has a {@code build.gradle} and return an
|
||||
* {@link GroovyDslGradleBuildAssert assert} for the {@code build.gradle} file of this
|
||||
* module, to allow chaining of gradle-specific assertions from this call.
|
||||
* @return a {@link GroovyDslGradleBuildAssert}
|
||||
*/
|
||||
public GroovyDslGradleBuildAssert groovyDslGradleBuild() {
|
||||
hasGroovyDslGradleBuild();
|
||||
return new GroovyDslGradleBuildAssert(this.actual.resolve("build.gradle"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.test.io.TextAssert;
|
||||
import org.assertj.core.api.AbstractPathAssert;
|
||||
import org.assertj.core.api.ListAssert;
|
||||
import org.assertj.core.api.PathAssert;
|
||||
|
||||
/**
|
||||
* Base class for project assertions.
|
||||
*
|
||||
* @param <SELF> the type of the concrete assert implementations
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractProjectAssert<SELF extends AbstractProjectAssert<SELF>> extends AbstractPathAssert<SELF> {
|
||||
|
||||
private ListAssert<String> filesAssert;
|
||||
|
||||
protected AbstractProjectAssert(Path projcetDirectory, Class<?> selfType) {
|
||||
super(projcetDirectory, selfType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the project has the specified directories.
|
||||
* @param directoryPaths the directories relative to the project directory.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF containsDirectories(String... directoryPaths) {
|
||||
for (String directory : directoryPaths) {
|
||||
new PathAssert(this.actual.resolve(directory)).exists().isDirectory();
|
||||
}
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the project does not have the specified directories.
|
||||
* @param directoryPaths the directory paths relative to the project directory.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF doesNotContainDirectories(String... directoryPaths) {
|
||||
for (String directory : directoryPaths) {
|
||||
new PathAssert(this.actual.resolve(directory)).doesNotExist();
|
||||
}
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the project has the specified files.
|
||||
* @param filePaths the file paths relative to the project directory.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF containsFiles(String... filePaths) {
|
||||
filePaths().contains(filePaths);
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the project does not have the specified files.
|
||||
* @param filePaths the file paths relative to the project directory.
|
||||
* @return {@code this} assertion object
|
||||
*/
|
||||
public SELF doesNotContainFiles(String... filePaths) {
|
||||
filePaths().doesNotContain(filePaths);
|
||||
return this.myself;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an {@link ListAssert assert} for the local file paths of this project, to
|
||||
* allow chaining of list-specific assertions from this call.
|
||||
* @return a {@link ListAssert} with the files of this project
|
||||
*/
|
||||
public ListAssert<String> filePaths() {
|
||||
if (this.filesAssert == null) {
|
||||
this.filesAssert = new ListAssert<>(getRelativePathsOfProjectFiles());
|
||||
}
|
||||
return this.filesAssert;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the project defines the specified file and return a {@link PathAssert}
|
||||
* for it, to allow chaining of Path-specific assertions from this call.
|
||||
* @param path the path of the file
|
||||
* @return a {@link PathAssert} for the specified file
|
||||
*/
|
||||
public PathAssert file(String path) {
|
||||
Path file = this.actual.resolve(path);
|
||||
return new PathAssert(file).exists().isRegularFile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the project defines the specified file and return a {@link TextAssert}
|
||||
* for it, to allow chaining of text file-specific assertions from this call.
|
||||
* @param path the path of a text file
|
||||
* @return a {@link TextAssert} for the specified text file
|
||||
*/
|
||||
public TextAssert textFile(String path) {
|
||||
Path file = this.actual.resolve(path);
|
||||
new PathAssert(file).exists().isRegularFile();
|
||||
return new TextAssert(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relative paths of all files. For consistency, always use {@code /} as
|
||||
* path separator.
|
||||
* @return the relative path of all files
|
||||
*/
|
||||
private List<String> getRelativePathsOfProjectFiles() {
|
||||
List<String> relativePaths = new ArrayList<>();
|
||||
try {
|
||||
Files.walkFileTree(this.actual, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||
relativePaths.add(createRelativePath(file));
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return relativePaths;
|
||||
}
|
||||
|
||||
private String createRelativePath(Path file) {
|
||||
String relativePath = this.actual.relativize(file).toString();
|
||||
if (FileSystems.getDefault().getSeparator().equals("\\")) {
|
||||
return relativePath.replace('\\', '/');
|
||||
}
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import io.spring.initializr.generator.language.Language;
|
||||
|
||||
/**
|
||||
* Assertions for a module with code for a particular {@link Language}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class JvmModuleAssert extends AbstractJvmModuleAssert<JvmModuleAssert> {
|
||||
|
||||
public JvmModuleAssert(Path projectDirectory, Language language, String sourceFileExtension) {
|
||||
super(projectDirectory, language, sourceFileExtension, JvmModuleAssert.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.spring.initializr.generator.test.project;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* Support for testing source code.
|
||||
* Assertions for a module.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
package io.spring.initializr.generator.test.language;
|
||||
public class ModuleAssert extends AbstractModuleAssert<ModuleAssert> {
|
||||
|
||||
public ModuleAssert(Path projectDirectory) {
|
||||
super(projectDirectory, ModuleAssert.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,248 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Properties;
|
||||
|
||||
import io.spring.initializr.generator.test.buildsystem.gradle.GradleBuildAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.gradle.GradleSettingsAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.PomAssert;
|
||||
import io.spring.initializr.generator.test.io.TextTestUtils;
|
||||
import io.spring.initializr.generator.test.language.SourceCodeAssert;
|
||||
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.support.PropertiesLoaderUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Various project based assertions.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ProjectAssert {
|
||||
|
||||
/**
|
||||
* Default package name.
|
||||
*/
|
||||
public static final String DEFAULT_PACKAGE_NAME = "com.example.demo";
|
||||
|
||||
/**
|
||||
* Default application name.
|
||||
*/
|
||||
public static final String DEFAULT_APPLICATION_NAME = "DemoApplication";
|
||||
|
||||
private final ProjectStructure projectStructure;
|
||||
|
||||
/**
|
||||
* Create a new instance with the directory holding the generated project.
|
||||
* @param dir the directory of the project
|
||||
*/
|
||||
public ProjectAssert(Path dir) {
|
||||
this.projectStructure = new ProjectStructure(dir);
|
||||
}
|
||||
|
||||
public ProjectStructure getProjectStructure() {
|
||||
return this.projectStructure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the project contains a base directory with the specified name.
|
||||
* <p>
|
||||
* When extracting such archive, a directory with the specified {@code name} will be
|
||||
* created with the content of the project instead of extracting it in the directory
|
||||
* itself.
|
||||
* @param name the expected name of the base directory
|
||||
* @return an updated project assert on that base directory
|
||||
*/
|
||||
public ProjectAssert hasBaseDir(String name) {
|
||||
Path projectDir = this.projectStructure.resolve(name);
|
||||
assertThat(projectDir)
|
||||
.describedAs("No directory %s found in %s", name, this.projectStructure.getProjectDirectory()).exists();
|
||||
assertThat(projectDir).isDirectory();
|
||||
// Replacing the root dir so that other assertions match the root
|
||||
return new ProjectAssert(projectDir);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link PomAssert} for this project.
|
||||
* @return a POM assert
|
||||
*/
|
||||
public PomAssert pomAssert() {
|
||||
return new PomAssert(TextTestUtils.readContent(this.projectStructure.resolve("pom.xml")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link GradleBuildAssert} for this project.
|
||||
* @return a gradle assert
|
||||
*/
|
||||
public GradleBuildAssert gradleBuildAssert() {
|
||||
return new GradleBuildAssert(TextTestUtils.readContent(this.projectStructure.resolve("build.gradle")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link GradleSettingsAssert} for this project.
|
||||
* @return a Gradle Settings assertion utility
|
||||
*/
|
||||
public GradleSettingsAssert gradleSettingsAssert() {
|
||||
return new GradleSettingsAssert(TextTestUtils.readContent(this.projectStructure.resolve("settings.gradle")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link SourceCodeAssert} for the specified source code.
|
||||
* @param sourceCodePath the source code path
|
||||
* @return a source code assertion utility
|
||||
*/
|
||||
public SourceCodeAssert sourceCodeAssert(String sourceCodePath) {
|
||||
hasFile(sourceCodePath);
|
||||
return new SourceCodeAssert(sourceCodePath,
|
||||
TextTestUtils.readContent(this.projectStructure.resolve(sourceCodePath)));
|
||||
}
|
||||
|
||||
public ProjectAssert isMavenProject() {
|
||||
hasFile("pom.xml").hasNoFile("build.gradle");
|
||||
hasFile("mvnw", "mvnw.cmd", ".mvn/wrapper/maven-wrapper.properties", ".mvn/wrapper/maven-wrapper.jar");
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectAssert isGradleProject(String version) {
|
||||
hasFile("build.gradle").hasNoFile("pom.xml");
|
||||
hasFile("gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
"gradle/wrapper/gradle-wrapper.jar");
|
||||
if (StringUtils.hasText(version)) {
|
||||
Properties properties = properties("gradle/wrapper/gradle-wrapper.properties");
|
||||
String distributionUrl = properties.getProperty("distributionUrl");
|
||||
assertThat(distributionUrl).contains(version);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectAssert isGradleProject() {
|
||||
return isGradleProject(null);
|
||||
}
|
||||
|
||||
public ProjectAssert isJavaProject(String expectedPackageName, String expectedApplicationName) {
|
||||
return isGenericProject(expectedPackageName, expectedApplicationName, "java", "java");
|
||||
}
|
||||
|
||||
public ProjectAssert isJavaProject() {
|
||||
return isJavaProject(DEFAULT_PACKAGE_NAME, DEFAULT_APPLICATION_NAME);
|
||||
}
|
||||
|
||||
public ProjectAssert isGroovyProject(String expectedPackageName, String expectedApplicationName) {
|
||||
return isGenericProject(expectedPackageName, expectedApplicationName, "groovy", "groovy");
|
||||
}
|
||||
|
||||
public ProjectAssert isKotlinProject(String expectedPackageName, String expectedApplicationName) {
|
||||
return isGenericProject(expectedPackageName, expectedApplicationName, "kotlin", "kt");
|
||||
}
|
||||
|
||||
public ProjectAssert isGroovyProject() {
|
||||
return isGroovyProject(DEFAULT_PACKAGE_NAME, DEFAULT_APPLICATION_NAME);
|
||||
}
|
||||
|
||||
public ProjectAssert isKotlinProject() {
|
||||
return isKotlinProject(DEFAULT_PACKAGE_NAME, DEFAULT_APPLICATION_NAME);
|
||||
}
|
||||
|
||||
public ProjectAssert isGenericProject(String expectedPackageName, String expectedApplicationName,
|
||||
String codeLocation, String extension) {
|
||||
String packageName = expectedPackageName.replace(".", "/");
|
||||
return hasFile("src/main/" + codeLocation + "/" + packageName + "/" + expectedApplicationName + "." + extension,
|
||||
"src/test/" + codeLocation + "/" + packageName + "/" + expectedApplicationName + "Tests." + extension,
|
||||
"src/main/resources/application.properties");
|
||||
}
|
||||
|
||||
public ProjectAssert isJavaWarProject(String expectedApplicationName) {
|
||||
return isGenericWarProject(DEFAULT_PACKAGE_NAME, expectedApplicationName, "java", "java");
|
||||
}
|
||||
|
||||
public ProjectAssert isJavaWarProject() {
|
||||
return isJavaWarProject(DEFAULT_APPLICATION_NAME);
|
||||
}
|
||||
|
||||
public ProjectAssert isGenericWarProject(String expectedPackageName, String expectedApplicationName,
|
||||
String codeLocation, String extension) {
|
||||
String packageName = expectedPackageName.replace(".", "/");
|
||||
return isGenericProject(expectedPackageName, expectedApplicationName, codeLocation, extension)
|
||||
.hasStaticAndTemplatesResources(true)
|
||||
.hasFile("src/main/" + codeLocation + "/" + packageName + "/ServletInitializer." + extension);
|
||||
}
|
||||
|
||||
public ProjectAssert hasStaticAndTemplatesResources(boolean web) {
|
||||
assertFile("src/main/resources/templates", web);
|
||||
return assertFile("src/main/resources/static", web);
|
||||
}
|
||||
|
||||
public ProjectAssert hasFile(String... localPaths) {
|
||||
assertThat(this.projectStructure.getRelativePathsOfProjectFiles()).contains(localPaths);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectAssert hasExecutableFile(String... localPaths) {
|
||||
if (runningOnWindows()) {
|
||||
for (String localPath : localPaths) {
|
||||
assertFile(localPath, true);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
for (String localPath : localPaths) {
|
||||
assertExecutable(localPath, true);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectAssert hasNoFile(String... localPaths) {
|
||||
assertThat(this.projectStructure.getRelativePathsOfProjectFiles()).doesNotContain(localPaths);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectAssert assertFile(String localPath, boolean exist) {
|
||||
Path candidate = this.projectStructure.resolve(localPath);
|
||||
assertThat(Files.exists(candidate)).describedAs("Invalid presence (%s) exist for %s", exist, localPath)
|
||||
.isEqualTo(exist);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ProjectAssert assertExecutable(String localPath, boolean exist) {
|
||||
Path candidate = this.projectStructure.resolve(localPath);
|
||||
assertThat(Files.exists(candidate)).describedAs("Invalid presence (%s) exist for %s", exist, localPath)
|
||||
.isEqualTo(exist);
|
||||
assertThat(Files.isExecutable(candidate)).describedAs("File (%s) is not an executable", localPath)
|
||||
.isEqualTo(exist);
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean runningOnWindows() {
|
||||
return File.separatorChar == '\\';
|
||||
}
|
||||
|
||||
private Properties properties(String localPath) {
|
||||
Path file = this.projectStructure.resolve(localPath);
|
||||
try {
|
||||
return PropertiesLoaderUtils.loadProperties(new FileSystemResource(file));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Cannot load Properties", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,24 +16,18 @@
|
||||
|
||||
package io.spring.initializr.generator.test.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.SimpleFileVisitor;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.spring.initializr.generator.test.io.TextTestUtils;
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
|
||||
/**
|
||||
* Test helper to assert content of a generated project structure.
|
||||
* Represent a generated project structure and act as an entry point for AssertJ
|
||||
* assertions.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ProjectStructure {
|
||||
public final class ProjectStructure implements AssertProvider<ModuleAssert> {
|
||||
|
||||
private final Path projectDirectory;
|
||||
|
||||
@@ -45,6 +39,11 @@ public class ProjectStructure {
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleAssert assertThat() {
|
||||
return new ModuleAssert(this.getProjectDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the project directory.
|
||||
* @return the project directory
|
||||
@@ -54,55 +53,17 @@ public class ProjectStructure {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a {@link Path} relative to the project directory.
|
||||
* @param other the path string to resolve against the root of the project structure
|
||||
* @return the resulting path
|
||||
* @see Path#resolve(String)
|
||||
* Resolve a {@link ProjectStructure} based on the specified module name.
|
||||
* @param name the name of a sub-directory of the current project
|
||||
* @return a new {@link ProjectStructure} for the sub-directory
|
||||
*/
|
||||
public Path resolve(String other) {
|
||||
return this.projectDirectory.resolve(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a {@link Path} relative to the project directory and return all lines.
|
||||
* Check that the resolved {@link Path} is a regular text file that ends with a
|
||||
* newline.
|
||||
* @param other the path string to resolve against the root of the project structure
|
||||
* @return all lines from the resolve file
|
||||
* @see TextTestUtils#readAllLines(Path)
|
||||
*/
|
||||
public List<String> readAllLines(String other) {
|
||||
return TextTestUtils.readAllLines(resolve(other));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the relative paths of all files. For consistency, always use {@code /} as
|
||||
* path separator.
|
||||
* @return the relative path of all files
|
||||
*/
|
||||
public List<String> getRelativePathsOfProjectFiles() {
|
||||
List<String> relativePaths = new ArrayList<>();
|
||||
try {
|
||||
Files.walkFileTree(this.projectDirectory, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||
relativePaths.add(createRelativePath(file));
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
public ProjectStructure resolveModule(String name) {
|
||||
Path projectDir = this.projectDirectory.resolve(name);
|
||||
if (!Files.isDirectory(projectDir)) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("No directory '%s' found in '%s'", name, this.projectDirectory));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
return relativePaths;
|
||||
}
|
||||
|
||||
private String createRelativePath(Path file) {
|
||||
String relativePath = this.projectDirectory.relativize(file).toString();
|
||||
if (FileSystems.getDefault().getSeparator().equals("\\")) {
|
||||
return relativePath.replace('\\', '/');
|
||||
}
|
||||
return relativePath;
|
||||
return new ProjectStructure(projectDir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link GroovyDslGradleBuildAssert}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class GroovyDslGradleBuildAssertTests {
|
||||
|
||||
@Test
|
||||
void hasPluginWithId() {
|
||||
assertThat(forSampleGradleBuild()).hasPlugin("java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasPluginWithIdAndVersion() {
|
||||
assertThat(forSampleGradleBuild()).hasPlugin("com.example", "1.0.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasPluginWrongId() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasPlugin("com.another", "1.0.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasPluginWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasPlugin("com.example", "2.0.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasVersion() {
|
||||
assertThat(forSampleGradleBuild()).hasVersion("0.0.1-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasVersionWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasVersion("0.0.3-SNAPSHOT"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasSourceCompatibility() {
|
||||
assertThat(forSampleGradleBuild()).hasSourceCompatibility("1.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasSourceCompatibilityWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleGradleBuild()).hasSourceCompatibility("11"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsOnlyExtProperties() {
|
||||
assertThat(forSampleGradleBuild()).containsOnlyExtProperties("acmeVersion", "Brussels.SR2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsOnlyExtPropertiesWithExtraValue() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forSampleGradleBuild())
|
||||
.containsOnlyExtProperties("acmeVersion", "Brussels.SR2", "wrong", "1.0.0"));
|
||||
}
|
||||
|
||||
private AssertProvider<GroovyDslGradleBuildAssert> forSampleGradleBuild() {
|
||||
String path = "project/build/gradle/sample-build.gradle";
|
||||
try (InputStream in = new ClassPathResource(path).getInputStream()) {
|
||||
String content = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
return () -> new GroovyDslGradleBuildAssert(content);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("No content found at " + path, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.buildsystem.gradle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Test for {@link GroovyDslGradleSettingsAssert}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class GroovyDslGradleSettingsAssertTests {
|
||||
|
||||
@Test
|
||||
void hasProjectName() {
|
||||
assertThat(forSampleGradleSettings()).hasProjectName("demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasProjectNameWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleGradleSettings()).hasProjectName("another-project"));
|
||||
}
|
||||
|
||||
private AssertProvider<GroovyDslGradleSettingsAssert> forSampleGradleSettings() {
|
||||
String path = "project/build/gradle/sample-settings.gradle";
|
||||
try (InputStream in = new ClassPathResource(path).getInputStream()) {
|
||||
String content = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
return () -> new GroovyDslGradleSettingsAssert(content);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("No content found at " + path, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.buildsystem.maven;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link MavenBuildAssert}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class MavenBuildAssertTests {
|
||||
|
||||
@Test
|
||||
void hasParent() {
|
||||
assertThat(forSampleMavenBuild()).hasParent("com.example.infrastructure", "infrastructure-parent",
|
||||
"1.0.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasParentWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forSampleMavenBuild())
|
||||
.hasParent("com.example.wrong", "infrastructure-parent", "1.0.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGroupId() {
|
||||
assertThat(forSampleMavenBuild()).hasGroupId("com.example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGroupIdWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasGroupId("com.wrong"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasArtifactId() {
|
||||
assertThat(forSampleMavenBuild()).hasArtifactId("demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasArtifactIdWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasArtifactId("wrong"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasVersion() {
|
||||
assertThat(forSampleMavenBuild()).hasVersion("0.0.1-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasVersionWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasVersion("1.0.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasPackaging() {
|
||||
assertThat(forMavenBuild("sample-packaging-pom.xml")).hasPackaging("zip");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasPackagingWithNoValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasPackaging("jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasName() {
|
||||
assertThat(forSampleMavenBuild()).hasName("demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasNameWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasName("wrong"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDescription() {
|
||||
assertThat(forSampleMavenBuild()).hasDescription("Demo project");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDescriptionWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDescription("Wrong description"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasProperty() {
|
||||
assertThat(forSampleMavenBuild()).hasProperty("acme.version", "Brussels.SR2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasPropertyWithWrongValue() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasProperty("acme.version", "Wrong.SR2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotHaveProperty() {
|
||||
assertThat(forSampleMavenBuild()).doesNotHaveProperty("unknown.version");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotHavePropertyWithExistingProperty() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).doesNotHaveProperty("acme.version"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependenciesSize() {
|
||||
assertThat(forSampleMavenBuild()).hasDependenciesSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependenciesSizeWithWrongSize() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDependenciesSize(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependency() {
|
||||
assertThat(forSampleMavenBuild()).hasDependency("com.example.acme", "library");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependencyWithWrongScope() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasDependency("com.example.acme", "library-test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependencyWithVersion() {
|
||||
assertThat(forMavenBuild("sample-dependency-version-pom.xml")).hasDependency("com.example.acme", "library",
|
||||
"1.2.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependencyWithVersionWithWrongVersion() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forMavenBuild("sample-dependency-version-pom.xml"))
|
||||
.hasDependency("com.example.acme", "library", "1.3.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependencyWithVersionAndScope() {
|
||||
assertThat(forMavenBuild("sample-dependency-version-pom.xml")).hasDependency("com.example.acme", "library-test",
|
||||
"1.3.0", "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasDependencyWithVersionAndScopeWithWrongScope() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forMavenBuild("sample-dependency-version-pom.xml"))
|
||||
.hasDependency("com.example.acme", "library-test", "1.3.0", "runtime"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotHaveDependencyArtifactId() {
|
||||
assertThat(forSampleMavenBuild()).doesNotHaveDependency("com.example.acme", "wrong");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotHaveDependencyGroupId() {
|
||||
assertThat(forSampleMavenBuild()).doesNotHaveDependency("com.example.wrong", "library");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotHaveDependencyWithMatchingDependency() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forSampleMavenBuild()).doesNotHaveDependency("com.example.acme", "library"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasBomsSize() {
|
||||
assertThat(forSampleMavenBuild()).hasBomsSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasBomsSizeWithWrongSize() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forSampleMavenBuild()).hasBomsSize(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasBom() {
|
||||
assertThat(forSampleMavenBuild()).hasBom("com.example.acme", "library-bom", "${acme.version}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasBomWithWrongGroupId() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forSampleMavenBuild()).hasBom("com.example.wrong", "library-bom", "${acme.version}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasBomWithWrongArtifactId() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forSampleMavenBuild()).hasBom("com.example.acme", "library-wrong", "${acme.version}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasBomWithWrongVersion() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forSampleMavenBuild()).hasBom("com.example.acme", "library-bom", "${wrong.version}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoriesSize() {
|
||||
assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepositoriesSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoriesSizeWithNoRepository() {
|
||||
assertThat(forSampleMavenBuild()).hasRepositoriesSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoriesSizeWrongSize() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepositoriesSize(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepository() {
|
||||
assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones", "Acme Milestones",
|
||||
"https://repo.example.com/milestone", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoryWithSnapshots() {
|
||||
assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-snapshots", "Acme Snapshots",
|
||||
"https://repo.example.com/snapshot", true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoryWithWrongId() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-wrong",
|
||||
"Acme Milestones", "https://repo.example.com/milestone", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoryWithWrongName() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forMavenBuild("sample-repositories-pom.xml"))
|
||||
.hasRepository("acme-milestones", "Acme Wrong", "https://repo.example.com/milestone", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoryWithWrongUrl() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
|
||||
"Acme Milestones", "https://repo.wrong.com/milestone", false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasRepositoryWithWrongSnapshotFlag() {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(
|
||||
() -> assertThat(forMavenBuild("sample-repositories-pom.xml")).hasRepository("acme-milestones",
|
||||
"Acme Milestones", "https://repo.example.com/milestone", true));
|
||||
}
|
||||
|
||||
private AssertProvider<MavenBuildAssert> forSampleMavenBuild() {
|
||||
return forMavenBuild("sample-pom.xml");
|
||||
}
|
||||
|
||||
private AssertProvider<MavenBuildAssert> forMavenBuild(String name) {
|
||||
try (InputStream in = new ClassPathResource("project/build/maven/" + name).getInputStream()) {
|
||||
String content = StreamUtils.copyToString(in, StandardCharsets.UTF_8);
|
||||
return () -> new MavenBuildAssert(content);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException("No content found at " + name, ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.io;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Tests for {@link TextAssert}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class TextAssertTests {
|
||||
|
||||
@Test
|
||||
void sameContentAsWithNonReadableResource() {
|
||||
Resource resource = mock(Resource.class);
|
||||
given(resource.isReadable()).willReturn(false);
|
||||
given(resource.toString()).willReturn("project/does-not-exist");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forContent("Hello")).hasSameContentAs(resource))
|
||||
.withMessageContaining("project/does-not-exist");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithNonReliableResource() throws IOException {
|
||||
Resource resource = mock(Resource.class);
|
||||
given(resource.isReadable()).willReturn(true);
|
||||
given(resource.getInputStream()).willThrow(new IOException("Test exception"));
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forContent("Hello")).hasSameContentAs(resource))
|
||||
.withMessageContaining("Cannot read expected content");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithMatchingResource() throws IOException {
|
||||
assertThat(forContent("Hello")).hasSameContentAs(createResource("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithMatchingResourceAndDifferentNewLinesInTarget() throws IOException {
|
||||
assertThat(forContent("Hello\nWorld")).hasSameContentAs(createResource("Hello\r\nWorld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithMatchingResourceAndDifferentNewLinesInSource() throws IOException {
|
||||
assertThat(forContent("Hello\r\nWorld")).hasSameContentAs(createResource("Hello\nWorld"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithNonMatchingResource() {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forContent("Test")).hasSameContentAs(createResource("Hello")))
|
||||
.withMessageContaining("Test").withMessageContaining("Hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithFile(@TempDir Path dir) throws IOException {
|
||||
Path file = Files.createFile(dir.resolve("hello.txt"));
|
||||
try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file))) {
|
||||
writer.println("Test");
|
||||
}
|
||||
assertThat(forContent(file)).hasSameContentAs(createResource("Test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sameContentAsWithFileAndNonMatchingResource(@TempDir Path dir) throws IOException {
|
||||
Path file = Files.createFile(dir.resolve("hello.txt"));
|
||||
try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file))) {
|
||||
writer.println("Test");
|
||||
}
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forContent(file)).hasSameContentAs(createResource("Hello")))
|
||||
.withMessageContaining("Test").withMessageContaining("Hello").withMessageContaining(file.toString());
|
||||
}
|
||||
|
||||
private AssertProvider<TextAssert> forContent(String content) {
|
||||
return () -> new TextAssert(content);
|
||||
}
|
||||
|
||||
private AssertProvider<TextAssert> forContent(Path file) {
|
||||
return () -> new TextAssert(file);
|
||||
}
|
||||
|
||||
private Resource createResource(String content) throws IOException {
|
||||
Resource resource = mock(Resource.class);
|
||||
given(resource.isReadable()).willReturn(true);
|
||||
given(resource.getInputStream()).willReturn(new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)));
|
||||
return resource;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link JvmModuleAssert}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class JvmModuleAssertTests {
|
||||
|
||||
private static final JavaLanguage JAVA_LANGUAGE = new JavaLanguage();
|
||||
|
||||
@Test
|
||||
void hasMainPackage(@TempDir Path root) throws IOException {
|
||||
Files.createDirectories(root.resolve("src/main/java/com/example"));
|
||||
assertThat(forJavaProject(root)).hasMainPackage("com.example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMainSource(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/main/java/com/example/Test.java");
|
||||
assertThat(forJavaProject(root)).hasMainSource("com.example", "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMainSourceWithNonMatchingExtension(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/main/java/com/example/Test.other");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainSource("com.example", "Test"))
|
||||
.withMessageContaining("Test").withMessageContaining("com.example").withMessageContaining("Test.java")
|
||||
.withMessageContaining("com.example").withMessageContaining("src/main/java/com/example/Test.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMainSourceWithNonMatchingSourceDir(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/main/groovy/com/example/Test.java");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainSource("com.example", "Test"))
|
||||
.withMessageContaining("Test.java").withMessageContaining("com.example")
|
||||
.withMessageContaining("src/main/java/com/example/Test.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mainSource(@TempDir Path root) throws IOException {
|
||||
createFileFrom("import com.example.Test;", root.resolve("src/main/java/com/acme/Test.java"));
|
||||
assertThat(forJavaProject(root)).mainSource("com.acme", "Test").containsOnlyOnce("import");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mainSourceWithMissingSource(@TempDir Path root) {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).mainSource("com.acme", "Test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMainResource(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/main/resources/project/sample.xml");
|
||||
assertThat(forJavaProject(root)).hasMainResource("project/sample.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMainResourceWithMissingResource(@TempDir Path root) {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).hasMainResource("project/sample.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTestPackage(@TempDir Path root) throws IOException {
|
||||
Files.createDirectories(root.resolve("src/test/java/com/example"));
|
||||
assertThat(forJavaProject(root)).hasTestPackage("com.example");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTestSource(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/test/java/com/example/Test.java");
|
||||
assertThat(forJavaProject(root)).hasTestSource("com.example", "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTestSourceWithNonMatchingExtension(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/test/java/com/example/Test.other");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).hasTestSource("com.example", "Test"))
|
||||
.withMessageContaining("Test").withMessageContaining("com.example").withMessageContaining("Test.java")
|
||||
.withMessageContaining("com.example").withMessageContaining("src/test/java/com/example/Test.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTestSourceWithNonMatchingSourceDir(@TempDir Path root) throws IOException {
|
||||
createFile(root, "src/test/groovy/com/example/Test.java");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).hasTestSource("com.example", "Test"))
|
||||
.withMessageContaining("Test.java").withMessageContaining("com.example")
|
||||
.withMessageContaining("src/test/java/com/example/Test.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSource(@TempDir Path root) throws IOException {
|
||||
createFileFrom("@Test", root.resolve("src/test/java/com/acme/DemoTests.java"));
|
||||
assertThat(forJavaProject(root)).testSource("com.acme", "DemoTests").containsOnlyOnce("@Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSourceWithMissingSource(@TempDir Path root) {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forJavaProject(root)).testSource("com.acme", "DemoTests"));
|
||||
}
|
||||
|
||||
private AssertProvider<AbstractJvmModuleAssert> forJavaProject(Path root) {
|
||||
return () -> new JvmModuleAssert(root, JAVA_LANGUAGE, "java");
|
||||
}
|
||||
|
||||
private void createFile(Path root, String path) throws IOException {
|
||||
Path target = root.resolve(path);
|
||||
Files.createDirectories(target.getParent());
|
||||
Files.createFile(target);
|
||||
}
|
||||
|
||||
private void createFileFrom(String content, Path target) throws IOException {
|
||||
Files.createDirectories(target.getParent());
|
||||
FileCopyUtils.copy(content, Files.newBufferedWriter(target, StandardOpenOption.CREATE));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link ModuleAssert}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class ModuleAssertTests {
|
||||
|
||||
@Test
|
||||
void containDirectories(@TempDir Path dir) throws IOException {
|
||||
createDirectories(dir, "test", "test/another", "another");
|
||||
assertThat(forDirectory(dir)).containsDirectories("test", "test/another");
|
||||
}
|
||||
|
||||
@Test
|
||||
void containDirectoriesWithMissingDirectory(@TempDir Path dir) throws IOException {
|
||||
createDirectories(dir, "test", "test/another", "another");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).containsDirectories("test", "wrong"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotContainDirectories(@TempDir Path dir) throws IOException {
|
||||
createDirectories(dir, "test", "test/another");
|
||||
assertThat(forDirectory(dir)).doesNotContainDirectories("another", "test/something");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotContainDirectoriesWithExistingDirectory(@TempDir Path dir) throws IOException {
|
||||
createDirectories(dir, "test", "test/another");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).doesNotContainDirectories("another", "test/another"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containFiles(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "test.xml", "src/Test.java", "another");
|
||||
assertThat(forDirectory(dir)).containsFiles("src/Test.java", "another");
|
||||
}
|
||||
|
||||
@Test
|
||||
void containFilesWithMissingFile(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "test.xml", "src/Test.java", "another");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).containsFiles("test.xml", "wrong"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotContainFiles(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "test.xml", "src/Test.java");
|
||||
assertThat(forDirectory(dir)).doesNotContainFiles("another", "test/Another.java");
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotContainFilesWithExistingFile(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "test.xml", "src/Test.java");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).doesNotContainFiles("another", "src/Test.java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void filePaths(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "src/One.java", "src/com/example/Two.java", "pom.xml", ".gitignore");
|
||||
createDirectories(dir, "test/unrelated");
|
||||
assertThat(forDirectory(dir)).filePaths().containsOnly("src/One.java", "src/com/example/Two.java", "pom.xml",
|
||||
".gitignore");
|
||||
}
|
||||
|
||||
@Test
|
||||
void file(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "some/file/here.txt");
|
||||
assertThat(forDirectory(dir)).file("some/file/here.txt").isEqualTo(dir.resolve("some/file/here.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileWithMissingFile(@TempDir Path dir) {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).file("som/file/does-not-exist.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void textFile(@TempDir Path dir) throws IOException {
|
||||
createFileFrom(new ClassPathResource("project/build/maven/sample-pom.xml"), dir.resolve("test.xml"));
|
||||
assertThat(forDirectory(dir)).textFile("test.xml").contains("<dependencies>", "<version>");
|
||||
}
|
||||
|
||||
@Test
|
||||
void textFileWithMissingFile(@TempDir Path dir) {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).textFile("som/file/does-not-exist.txt"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void asJavaProject(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "src/main/java/com/example/Test.java");
|
||||
assertThat(forDirectory(dir)).asJvmModule(new JavaLanguage(), "java").hasMainPackage("com.example")
|
||||
.hasMainSource("com.example", "Test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMavenBuild(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "pom.xml");
|
||||
assertThat(forDirectory(dir)).hasMavenBuild();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMavenBuildWithMissingPomFile(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "pom.wrong");
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenBuild());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMavenWrapper(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "mvnw", "mvnw.cmd", ".mvn/wrapper/maven-wrapper.properties", ".mvn/wrapper/maven-wrapper.jar");
|
||||
assertThat(forDirectory(dir)).hasMavenWrapper();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMavenWrapperWithMissingScript(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, ".mvn/wrapper/maven-wrapper.properties", ".mvn/wrapper/maven-wrapper.jar");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenWrapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasMavenWrapperWithMissingDotMvnDir(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "mvnw", "mvnw.cmd");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).hasMavenWrapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void mavenBuild(@TempDir Path dir) throws IOException {
|
||||
createFileFrom(new ClassPathResource("project/build/maven/sample-pom.xml"), dir.resolve("pom.xml"));
|
||||
assertThat(forDirectory(dir)).mavenBuild().hasGroupId("com.example").hasArtifactId("demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mavenBuildWithMissingPomFile(@TempDir Path dir) {
|
||||
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> assertThat(forDirectory(dir)).mavenBuild());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGroovyDslGradleBuild(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "build.gradle");
|
||||
assertThat(forDirectory(dir)).hasGroovyDslGradleBuild();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGroovyDslGradleBuildWithMissingBuildFile(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "build.wrong");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGroovyDslGradleBuild());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGradleWrapper(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "gradlew", "gradlew.bat", "gradle/wrapper/gradle-wrapper.properties",
|
||||
"gradle/wrapper/gradle-wrapper.jar");
|
||||
assertThat(forDirectory(dir)).hasGradleWrapper();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGradleWrapperWithMissingScript(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "gradle/wrapper/gradle-wrapper.properties", "gradle/wrapper/gradle-wrapper.jar");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGradleWrapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasGradleWrapperWithMissingGradleDir(@TempDir Path dir) throws IOException {
|
||||
createFiles(dir, "gradlew", "gradlew.bat");
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).hasGradleWrapper());
|
||||
}
|
||||
|
||||
@Test
|
||||
void groovyDslGradleBuild(@TempDir Path dir) throws IOException {
|
||||
createFileFrom(new ClassPathResource("project/build/gradle/sample-build.gradle"), dir.resolve("build.gradle"));
|
||||
assertThat(forDirectory(dir)).groovyDslGradleBuild().hasVersion("0.0.1-SNAPSHOT").hasSourceCompatibility("1.8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void groovyDslGradleBuildWithMissingBuildFile(@TempDir Path dir) {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(forDirectory(dir)).groovyDslGradleBuild());
|
||||
}
|
||||
|
||||
private AssertProvider<ModuleAssert> forDirectory(Path projectDirectory) {
|
||||
return () -> new ModuleAssert(projectDirectory);
|
||||
}
|
||||
|
||||
private void createDirectories(Path dir, String... directories) throws IOException {
|
||||
for (String directory : directories) {
|
||||
Files.createDirectories(dir.resolve(directory));
|
||||
}
|
||||
}
|
||||
|
||||
private void createFiles(Path dir, String... files) throws IOException {
|
||||
for (String file : files) {
|
||||
Path path = dir.resolve(file);
|
||||
Files.createDirectories(path.getParent());
|
||||
Files.createFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
private void createFileFrom(Resource from, Path target) throws IOException {
|
||||
Files.createDirectories(target.getParent());
|
||||
FileCopyUtils.copy(from.getInputStream(), Files.newOutputStream(target, StandardOpenOption.CREATE));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -91,9 +91,8 @@ class ProjectGeneratorTests {
|
||||
Files.createFile(subDir.resolve("Test.src"));
|
||||
});
|
||||
});
|
||||
ProjectStructure projectStructure = tester.generate(new ProjectDescription());
|
||||
assertThat(projectStructure.getRelativePathsOfProjectFiles()).containsOnly("test.text",
|
||||
"src/main/test/Test.src");
|
||||
ProjectStructure project = tester.generate(new ProjectDescription());
|
||||
assertThat(project).filePaths().containsOnly("test.text", "src/main/test/Test.src");
|
||||
}
|
||||
|
||||
private static class TestProjectDescriptionCustomizer implements ProjectDescriptionCustomizer {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2012-2019 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.initializr.generator.test.project;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link ProjectStructure}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class ProjectStructureTests {
|
||||
|
||||
@Test
|
||||
void resolveModule(@TempDir Path dir) throws IOException {
|
||||
Path moduleDir = dir.resolve("test");
|
||||
Files.createDirectories(moduleDir);
|
||||
ProjectStructure module = new ProjectStructure(dir).resolveModule("test");
|
||||
assertThat(module).isNotNull();
|
||||
assertThat(module.getProjectDirectory()).isEqualTo(moduleDir);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveModuleWithFile(@TempDir Path dir) throws IOException {
|
||||
Files.createFile(dir.resolve("test"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ProjectStructure(dir).resolveModule("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveModuleWithNonExistingPath(@TempDir Path dir) {
|
||||
Path test = dir.resolve("test");
|
||||
assertThat(test).doesNotExist();
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new ProjectStructure(dir).resolveModule("test"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
plugins {
|
||||
id 'com.example' version '1.0.0.RELEASE'
|
||||
id 'java'
|
||||
}
|
||||
|
||||
group = 'com.example'
|
||||
version = '0.0.1-SNAPSHOT'
|
||||
sourceCompatibility = '1.8'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
ext {
|
||||
set('acmeVersion', "Brussels.SR2")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.example.acme:library'
|
||||
testImplementation 'com.example.acme:library-test'
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "com.example.acme:library-bom:${acmeVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
rootProject.name = 'demo'
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.example.acme</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.example.acme</groupId>
|
||||
<artifactId>library-test</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>zip</packaging>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,57 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.example.infrastructure</groupId>
|
||||
<artifactId>infrastructure-parent</artifactId>
|
||||
<version>1.0.0.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>demo</name>
|
||||
<description>Demo project</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<acme.version>Brussels.SR2</acme.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.example.acme</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.example.acme</groupId>
|
||||
<artifactId>library-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.example.acme</groupId>
|
||||
<artifactId>library-bom</artifactId>
|
||||
<version>${acme.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>acme-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>acme-milestones</id>
|
||||
<name>Acme Milestones</name>
|
||||
<url>https://repo.example.com/milestone</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>acme-snapshots</id>
|
||||
<name>Acme Snapshots</name>
|
||||
<url>https://repo.example.com/snapshot</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
@@ -34,7 +34,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.web.AbstractInitializrIntegrationTests.Config;
|
||||
import io.spring.initializr.web.mapper.InitializrMetadataVersion;
|
||||
import io.spring.initializr.web.support.InitializrMetadataUpdateStrategy;
|
||||
@@ -145,29 +145,54 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link ProjectAssert} for the following archive content.
|
||||
* @param content the source content
|
||||
* @return a project assert
|
||||
* Assert that the specified {@link ProjectStructure} has a structure with default
|
||||
* settings, i.e. a Java-based project with the default package and maven build.
|
||||
* @param project the project structure to assert
|
||||
*/
|
||||
protected ProjectAssert zipProjectAssert(byte[] content) {
|
||||
return projectAssert(content, ArchiveType.ZIP);
|
||||
protected void assertDefaultProject(ProjectStructure project) {
|
||||
assertDefaultJavaProject(project);
|
||||
assertThat(project).containsFiles(".gitignore");
|
||||
assertThat(project).hasMavenBuild().hasMavenWrapper().file("mvnw").isExecutable();
|
||||
}
|
||||
|
||||
protected void assertDefaultJavaProject(ProjectStructure project) {
|
||||
assertThat(project).containsFiles("src/main/java/com/example/demo/DemoApplication.java",
|
||||
"src/test/java/com/example/demo/DemoApplicationTests.java",
|
||||
"src/main/resources/application.properties");
|
||||
}
|
||||
|
||||
protected void assertHasWebResources(ProjectStructure project) {
|
||||
assertThat(project).containsDirectories("src/main/resources/templates", "src/main/resources/static");
|
||||
}
|
||||
|
||||
protected void assertDoesNotHaveWebResources(ProjectStructure project) {
|
||||
assertThat(project).doesNotContainDirectories("src/main/resources/templates", "src/main/resources/static");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a {@link ProjectAssert} for the following TGZ archive.
|
||||
* Return a {@link ProjectStructure} for the following archive content.
|
||||
* @param content the source content
|
||||
* @return a project assert
|
||||
*/
|
||||
protected ProjectAssert tgzProjectAssert(byte[] content) {
|
||||
return projectAssert(content, ArchiveType.TGZ);
|
||||
protected ProjectStructure projectFromArchive(byte[] content) {
|
||||
return getProjectStructure(content, ArchiveType.ZIP);
|
||||
}
|
||||
|
||||
protected ProjectAssert downloadZip(String context) {
|
||||
/**
|
||||
* Return a {@link ProjectStructure} for the following TGZ archive.
|
||||
* @param content the source content
|
||||
* @return a project assert
|
||||
*/
|
||||
protected ProjectStructure tgzProjectAssert(byte[] content) {
|
||||
return getProjectStructure(content, ArchiveType.TGZ);
|
||||
}
|
||||
|
||||
protected ProjectStructure downloadZip(String context) {
|
||||
byte[] body = downloadArchive(context).getBody();
|
||||
return zipProjectAssert(body);
|
||||
return projectFromArchive(body);
|
||||
}
|
||||
|
||||
protected ProjectAssert downloadTgz(String context) {
|
||||
protected ProjectStructure downloadTgz(String context) {
|
||||
byte[] body = downloadArchive(context).getBody();
|
||||
return tgzProjectAssert(body);
|
||||
}
|
||||
@@ -200,7 +225,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
responseType);
|
||||
}
|
||||
|
||||
protected ProjectAssert projectAssert(byte[] content, ArchiveType archiveType) {
|
||||
protected ProjectStructure getProjectStructure(byte[] content, ArchiveType archiveType) {
|
||||
try {
|
||||
Path archiveFile = writeArchive(content);
|
||||
Path project = this.folder.resolve("project");
|
||||
@@ -212,7 +237,7 @@ public abstract class AbstractInitializrIntegrationTests {
|
||||
untar(archiveFile, project);
|
||||
break;
|
||||
}
|
||||
return new ProjectAssert(project);
|
||||
return new ProjectStructure(project);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Cannot unpack archive", ex);
|
||||
|
||||
@@ -16,13 +16,17 @@
|
||||
|
||||
package io.spring.initializr.web.project;
|
||||
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.PomAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.MavenBuildAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Validate that the "raw" HTTP commands that are described in the command-line help
|
||||
* works. If anything needs to be updated here, please double check the
|
||||
@@ -36,29 +40,39 @@ class CommandLineExampleIntegrationTests extends AbstractInitializrControllerInt
|
||||
|
||||
@Test
|
||||
void generateDefaultProject() {
|
||||
downloadZip("/starter.zip").isJavaProject().isMavenProject().hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterTest().hasDependenciesCount(2);
|
||||
ProjectStructure project = downloadZip("/starter.zip");
|
||||
assertDefaultProject(project);
|
||||
assertDoesNotHaveWebResources(project);
|
||||
assertThat(project).mavenBuild().hasDependency(Dependency.createSpringBootStarter(""))
|
||||
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST))
|
||||
.hasDependenciesSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateWebProjectWithJava8() {
|
||||
downloadZip("/starter.zip?dependencies=web&javaVersion=1.8").isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(true).pomAssert().hasJavaVersion("1.8")
|
||||
.hasSpringBootStarterDependency("web").hasSpringBootStarterTest().hasDependenciesCount(2);
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateWebDataJpaGradleProject() {
|
||||
downloadTgz("/starter.tgz?dependencies=web,data-jpa&type=gradle-project&baseDir=my-dir").hasBaseDir("my-dir")
|
||||
.isJavaProject().isGradleProject().hasStaticAndTemplatesResources(true).gradleBuildAssert()
|
||||
.contains("spring-boot-starter-web").contains("spring-boot-starter-data-jpa");
|
||||
ProjectStructure project = downloadTgz(
|
||||
"/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");
|
||||
}
|
||||
|
||||
@Test
|
||||
void generateMavenPomWithWarPackaging() {
|
||||
ResponseEntity<String> response = getRestTemplate().getForEntity(createUrl("/pom.xml?packaging=war"),
|
||||
String.class);
|
||||
PomAssert pomAssert = new PomAssert(response.getBody());
|
||||
MavenBuildAssert pomAssert = new MavenBuildAssert(response.getBody());
|
||||
pomAssert.hasPackaging("war");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
|
||||
package io.spring.initializr.web.project;
|
||||
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
/**
|
||||
@@ -30,8 +30,8 @@ public class MainControllerArchiveIntegrationTests extends AbstractFullStackInit
|
||||
|
||||
@Test
|
||||
void baseDirectorySeparatedBySpace() {
|
||||
ResponseEntity<byte[]> entity = downloadArchive("/starter.zip?artifactId=demo&baseDir=demo trial");
|
||||
zipProjectAssert(entity.getBody()).hasBaseDir("demo trial").hasExecutableFile("mvnw").isJavaProject();
|
||||
ProjectStructure project = downloadZip("/starter.zip?artifactId=demo&baseDir=demo trial");
|
||||
assertDefaultProject(project.resolveModule("demo trial"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package io.spring.initializr.web.project;
|
||||
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.PomAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.MavenBuildAssert;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -33,7 +33,7 @@ class MainControllerDefaultsIntegrationTests extends AbstractInitializrControlle
|
||||
@Test
|
||||
void generateDefaultPom() {
|
||||
String content = getRestTemplate().getForObject(createUrl("/pom.xml?style=web"), String.class);
|
||||
PomAssert pomAssert = new PomAssert(content);
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,8 @@ package io.spring.initializr.web.project;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import io.spring.initializr.generator.test.project.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -46,10 +47,15 @@ class MainControllerEnvIntegrationTests extends AbstractInitializrControllerInte
|
||||
|
||||
@Test
|
||||
void generateProjectWithInvalidName() {
|
||||
downloadZip("/starter.zip?style=data-jpa&name=Invalid")
|
||||
.isJavaProject(ProjectAssert.DEFAULT_PACKAGE_NAME, "FooBarApplication").isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
||||
.hasSpringBootStarterDependency("data-jpa").hasSpringBootStarterTest();
|
||||
ProjectStructure project = downloadZip("/starter.zip?style=data-jpa&name=Invalid");
|
||||
assertThat(project).containsFiles("src/main/java/com/example/demo/FooBarApplication.java",
|
||||
"src/test/java/com/example/demo/FooBarApplicationTests.java");
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package io.spring.initializr.web.project;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.metadata.Dependency;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import io.spring.initializr.web.AbstractInitializrIntegrationTests;
|
||||
@@ -49,22 +50,25 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
void simpleZipProject() {
|
||||
ResponseEntity<byte[]> entity = downloadArchive("/starter.zip?style=web&style=jpa");
|
||||
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/zip"), "demo.zip");
|
||||
zipProjectAssert(entity.getBody()).isJavaProject().hasFile(".gitignore").hasExecutableFile("mvnw")
|
||||
.isMavenProject().hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterDependency("web").hasSpringBootStarterDependency("data-jpa") // alias
|
||||
// jpa
|
||||
// ->
|
||||
// data-jpa
|
||||
.hasSpringBootStarterTest();
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void simpleTgzProject() {
|
||||
ResponseEntity<byte[]> entity = downloadArchive("/starter.tgz?style=org.acme:foo");
|
||||
assertArchiveResponseHeaders(entity, MediaType.valueOf("application/x-compress"), "demo.tar.gz");
|
||||
tgzProjectAssert(entity.getBody()).isJavaProject().hasFile(".gitignore").hasExecutableFile("mvnw")
|
||||
.isMavenProject().hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(2)
|
||||
.hasDependency("org.acme", "foo", "1.3.5");
|
||||
ProjectStructure project = tgzProjectAssert(entity.getBody());
|
||||
assertDefaultProject(project);
|
||||
assertDoesNotHaveWebResources(project);
|
||||
assertThat(project).doesNotContainDirectories("src/main/resources/templates", "src/main/resources/static");
|
||||
assertThat(project).mavenBuild().hasDependenciesSize(2).hasDependency("org.acme", "foo", "1.3.5");
|
||||
}
|
||||
|
||||
private void assertArchiveResponseHeaders(ResponseEntity<byte[]> entity, MediaType contentType, String fileName) {
|
||||
@@ -76,8 +80,10 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
@Test
|
||||
void dependencyInRange() {
|
||||
Dependency biz = Dependency.create("org.acme", "biz", "1.3.5", "runtime");
|
||||
downloadTgz("/starter.tgz?style=org.acme:biz&bootVersion=2.2.1.RELEASE").isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(false).pomAssert().hasDependenciesCount(3).hasDependency(biz);
|
||||
ProjectStructure project = downloadTgz("/starter.tgz?style=org.acme:biz&bootVersion=2.2.1.RELEASE");
|
||||
assertDefaultProject(project);
|
||||
assertDoesNotHaveWebResources(project);
|
||||
assertThat(project).mavenBuild().hasDependenciesSize(3).hasDependency(biz);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -92,44 +98,56 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
|
||||
@Test
|
||||
void noDependencyProject() {
|
||||
downloadZip("/starter.zip").isJavaProject().isMavenProject().hasStaticAndTemplatesResources(false).pomAssert()
|
||||
.hasDependenciesCount(2)
|
||||
ProjectStructure project = downloadZip("/starter.zip");
|
||||
assertDefaultProject(project);
|
||||
assertDoesNotHaveWebResources(project);
|
||||
assertThat(project).mavenBuild().hasDependenciesSize(2)
|
||||
// the root dep is added if none is specified
|
||||
.hasSpringBootStarterRootDependency().hasSpringBootStarterTest();
|
||||
.hasDependency(Dependency.createSpringBootStarter(""))
|
||||
.hasDependency(Dependency.createSpringBootStarter("test", Dependency.SCOPE_TEST));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependenciesIsAnAliasOfStyle() {
|
||||
downloadZip("/starter.zip?dependencies=web&dependencies=jpa").isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterDependency("web").hasSpringBootStarterDependency("data-jpa") // alias
|
||||
// jpa
|
||||
// ->
|
||||
// data-jpa
|
||||
.hasSpringBootStarterTest();
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dependenciesIsAnAliasOfStyleCommaSeparated() {
|
||||
downloadZip("/starter.zip?dependencies=web,jpa").isJavaProject().isMavenProject()
|
||||
.hasStaticAndTemplatesResources(true).pomAssert().hasDependenciesCount(3)
|
||||
.hasSpringBootStarterDependency("web").hasSpringBootStarterDependency("data-jpa") // alias
|
||||
// jpa
|
||||
// ->
|
||||
// data-jpa
|
||||
.hasSpringBootStarterTest();
|
||||
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));
|
||||
}
|
||||
|
||||
@Test
|
||||
void kotlinRange() {
|
||||
downloadZip("/starter.zip?style=web&language=kotlin&bootVersion=2.0.1.RELEASE").isKotlinProject()
|
||||
.isMavenProject().pomAssert().hasDependenciesCount(4).hasProperty("kotlin.version", "1.1");
|
||||
ProjectStructure project = downloadZip("/starter.zip?style=web&language=kotlin&bootVersion=2.0.1.RELEASE");
|
||||
assertThat(project).containsFiles("src/main/kotlin/com/example/demo/DemoApplication.kt",
|
||||
"src/test/kotlin/com/example/demo/DemoApplicationTests.kt",
|
||||
"src/main/resources/application.properties");
|
||||
assertThat(project).mavenBuild().hasDependenciesSize(4).hasProperty("kotlin.version", "1.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void gradleWarProject() {
|
||||
downloadZip("/starter.zip?style=web&style=security&packaging=war&type=gradle-project").isJavaWarProject()
|
||||
.isGradleProject();
|
||||
ProjectStructure project = downloadZip(
|
||||
"/starter.zip?style=web&style=security&packaging=war&type=gradle-project");
|
||||
assertThat(project).hasGroovyDslGradleBuild().hasGradleWrapper();
|
||||
assertThat(project).containsFiles("src/main/java/com/example/demo/DemoApplication.java",
|
||||
"src/main/java/com/example/demo/ServletInitializer.java",
|
||||
"src/test/java/com/example/demo/DemoApplicationTests.java",
|
||||
"src/main/resources/application.properties");
|
||||
assertHasWebResources(project);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,13 +244,13 @@ class MainControllerIntegrationTests extends AbstractInitializrControllerIntegra
|
||||
@Test
|
||||
void curlCanStillDownloadZipArchive() {
|
||||
ResponseEntity<byte[]> response = execute("/starter.zip", byte[].class, "curl/1.2.4", "*/*");
|
||||
zipProjectAssert(response.getBody()).isMavenProject().isJavaProject();
|
||||
assertDefaultProject(projectFromArchive(response.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void curlCanStillDownloadTgzArchive() {
|
||||
ResponseEntity<byte[]> response = execute("/starter.tgz", byte[].class, "curl/1.2.4", "*/*");
|
||||
tgzProjectAssert(response.getBody()).isMavenProject().isJavaProject();
|
||||
assertDefaultProject(tgzProjectAssert(response.getBody()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,6 +19,7 @@ package io.spring.initializr.web.project;
|
||||
import io.spring.initializr.generator.language.java.JavaLanguage;
|
||||
import io.spring.initializr.generator.project.ProjectDescription;
|
||||
import io.spring.initializr.generator.project.ProjectDescriptionCustomizer;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.generator.version.Version;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import io.spring.initializr.web.project.ProjectGenerationDescriptionCustomizerTests.ProjectDescriptionCustomizerConfiguration;
|
||||
@@ -29,14 +30,19 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@ActiveProfiles("test-default")
|
||||
@Import(ProjectDescriptionCustomizerConfiguration.class)
|
||||
class ProjectGenerationDescriptionCustomizerTests extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
@Test
|
||||
void projectDescriptionCustomizersAreInvoked() {
|
||||
downloadZip("/starter.zip?bootVersion=2.0.4.RELEASE&javaVersion=1.8").isJavaProject().isMavenProject()
|
||||
.pomAssert().hasSpringBootParent("2.2.3.RELEASE").hasProperty("java.version", "1.7");
|
||||
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");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -27,9 +27,9 @@ import io.spring.initializr.generator.io.SimpleIndentStrategy;
|
||||
import io.spring.initializr.generator.io.template.MustacheTemplateRenderer;
|
||||
import io.spring.initializr.generator.project.ProjectDirectoryFactory;
|
||||
import io.spring.initializr.generator.test.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.generator.test.buildsystem.gradle.GradleBuildAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.PomAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.gradle.GroovyDslGradleBuildAssert;
|
||||
import io.spring.initializr.generator.test.buildsystem.maven.MavenBuildAssert;
|
||||
import io.spring.initializr.generator.test.project.ProjectStructure;
|
||||
import io.spring.initializr.metadata.InitializrMetadata;
|
||||
import io.spring.initializr.metadata.InitializrMetadataProvider;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
@@ -87,7 +87,7 @@ public class ProjectGenerationInvokerTests {
|
||||
request.setType("maven-project");
|
||||
request.initialize(metadata);
|
||||
ProjectGenerationResult result = this.invoker.invokeProjectStructureGeneration(request);
|
||||
new ProjectAssert(result.getRootDirectory()).isJavaProject();
|
||||
assertThat(new ProjectStructure(result.getRootDirectory())).hasMavenBuild();
|
||||
Map<Path, List<Path>> tempFiles = (Map<Path, List<Path>>) ReflectionTestUtils.getField(this.invoker,
|
||||
"temporaryFiles");
|
||||
assertThat(tempFiles.get(result.getRootDirectory())).contains(result.getRootDirectory());
|
||||
@@ -114,10 +114,10 @@ public class ProjectGenerationInvokerTests {
|
||||
request.initialize(metadata);
|
||||
byte[] bytes = this.invoker.invokeBuildGeneration(request);
|
||||
String content = new String(bytes);
|
||||
new PomAssert(content).hasGroupId(request.getGroupId()).hasArtifactId(request.getArtifactId())
|
||||
new MavenBuildAssert(content).hasGroupId(request.getGroupId()).hasArtifactId(request.getArtifactId())
|
||||
.hasVersion(request.getVersion()).doesNotHaveNode("/project/packaging").hasName(request.getName())
|
||||
.hasDescription(request.getDescription()).hasJavaVersion(request.getJavaVersion())
|
||||
.hasSpringBootParent(request.getBootVersion());
|
||||
.hasDescription(request.getDescription()).hasProperty("java.version", request.getJavaVersion())
|
||||
.hasParent("org.springframework.boot", "spring-boot-starter-parent", request.getBootVersion());
|
||||
verifyProjectSuccessfulEventFor(request);
|
||||
}
|
||||
|
||||
@@ -128,8 +128,9 @@ public class ProjectGenerationInvokerTests {
|
||||
request.setType("gradle-project");
|
||||
byte[] bytes = this.invoker.invokeBuildGeneration(request);
|
||||
String content = new String(bytes);
|
||||
new GradleBuildAssert(content).hasVersion(request.getVersion()).hasSpringBootPlugin(request.getBootVersion())
|
||||
.hasJavaVersion(request.getJavaVersion());
|
||||
new GroovyDslGradleBuildAssert(content).hasVersion(request.getVersion())
|
||||
.hasPlugin("org.springframework.boot", request.getBootVersion())
|
||||
.hasSourceCompatibility(request.getJavaVersion());
|
||||
verifyProjectSuccessfulEventFor(request);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user