package io.spring.gradle.convention; import io.spring.gradle.TestKit; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.TaskOutcome; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import static org.assertj.core.api.Assertions.assertThat; public class ShowcaseITest { private TestKit testKit; @BeforeEach void setup(@TempDir Path tempDir) { this.testKit = new TestKit(tempDir.toFile()); } @Test public void build() throws Exception { BuildResult result = this.testKit.withProjectResource("samples/showcase/") .withArguments("build", "--stacktrace") .forwardOutput() .build(); assertThat(result.getOutput()).contains("BUILD SUCCESSFUL"); } @Test @Disabled public void install() throws Exception { BuildResult result = this.testKit .withProjectResource("samples/showcase/") .withArguments("install", "--stacktrace") .build(); assertThat(result.getOutput()).contains("SUCCESS"); File pom = new File(testKit.getRootDir(), "sgbcs-core/build/poms/pom-default.xml"); assertThat(pom).exists(); String pomText = new String(Files.readAllBytes(pom.toPath())); String pomTextNoSpace = pomText.replaceAll("\\s", ""); assertThat(pomText).doesNotContain(""); assertThat(pomTextNoSpace).contains("\n org.springframework\n spring-test\n test\n 4.3.6.RELEASE\n ".replaceAll("\\s", "")); assertThat(pomTextNoSpace).contains("\n \n rwinch\n Rob Winch\n rwinch@pivotal.io\n \n \n jgrandja\n Joe Grandja\n jgrandja@pivotal.io\n \n ".replaceAll("\\s", "")); assertThat(pomTextNoSpace).contains("\n scm:git:git://github.com/spring-projects/spring-security\n scm:git:git://github.com/spring-projects/spring-security\n https://github.com/spring-projects/spring-security\n ".replaceAll("\\s", "")); assertThat(pomTextNoSpace).contains("sgbcs-core"); assertThat(pomTextNoSpace).contains("https://spring.io/spring-security"); assertThat(pomTextNoSpace).contains("\n spring.io\n https://spring.io/\n ".replaceAll("\\s", "")); assertThat(pomTextNoSpace).contains(" \n \n The Apache Software License, Version 2.0\n https://www.apache.org/licenses/LICENSE-2.0.txt\n repo\n \n ".replaceAll("\\s", "")); assertThat(pomTextNoSpace).contains("\n scm:git:git://github.com/spring-projects/spring-security\n scm:git:git://github.com/spring-projects/spring-security\n https://github.com/spring-projects/spring-security\n ".replaceAll("\\s", "")); File bom = new File(testKit.getRootDir(), "bom/build/poms/pom-default.xml"); assertThat(bom).exists(); assertThat(bom).hasContent("sgbcs-core"); BuildResult secondBuild = this.testKit.withProjectResource("samples/showcase/").withArguments("mavenBom", "--stacktrace").build(); // mavenBom is not up to date since install is never up to date assertThat(result.task(":bom:mavenBom").getOutcome()).isEqualTo(TaskOutcome.SUCCESS); } }