Search in sources :

Example 26 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class AbstractBootArchiveIntegrationTests method multiModuleCustomLayers.

@TestTemplate
void multiModuleCustomLayers() throws IOException {
    writeSettingsGradle();
    writeMainClass();
    writeResource();
    BuildResult build = this.gradleBuild.build(this.taskName);
    assertThat(build.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    Map<String, List<String>> indexedLayers;
    String layerToolsJar = this.libPath + JarModeLibrary.LAYER_TOOLS.getName();
    try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
        assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "alpha-1.2.3.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "bravo-1.2.3.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "charlie-1.2.3.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "library-1.0-SNAPSHOT.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.classesPath + "example/Main.class")).isNotNull();
        assertThat(jarFile.getEntry(this.classesPath + "static/file.txt")).isNotNull();
        assertThat(jarFile.getEntry(this.indexPath + "layers.idx")).isNotNull();
        indexedLayers = readLayerIndex(jarFile);
    }
    List<String> layerNames = Arrays.asList("dependencies", "commons-dependencies", "snapshot-dependencies", "subproject-dependencies", "static", "app");
    assertThat(indexedLayers.keySet()).containsExactlyElementsOf(layerNames);
    Set<String> expectedSubprojectDependencies = new TreeSet<>();
    expectedSubprojectDependencies.add(this.libPath + "alpha-1.2.3.jar");
    expectedSubprojectDependencies.add(this.libPath + "bravo-1.2.3.jar");
    expectedSubprojectDependencies.add(this.libPath + "charlie-1.2.3.jar");
    Set<String> expectedDependencies = new TreeSet<>();
    expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar");
    expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar");
    List<String> expectedSnapshotDependencies = new ArrayList<>();
    expectedSnapshotDependencies.add(this.libPath + "library-1.0-SNAPSHOT.jar");
    (layerToolsJar.contains("SNAPSHOT") ? expectedSnapshotDependencies : expectedDependencies).add(layerToolsJar);
    assertThat(indexedLayers.get("subproject-dependencies")).containsExactlyElementsOf(expectedSubprojectDependencies);
    assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies);
    assertThat(indexedLayers.get("commons-dependencies")).containsExactly(this.libPath + "commons-lang3-3.9.jar");
    assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies);
    assertThat(indexedLayers.get("static")).containsExactly(this.classesPath + "static/");
    List<String> appLayer = new ArrayList<>(indexedLayers.get("app"));
    String[] appLayerContents = getExpectedApplicationLayerContents(this.classesPath + "example/");
    assertThat(appLayer).containsSubsequence(appLayerContents);
    appLayer.removeAll(Arrays.asList(appLayerContents));
    assertThat(appLayer).containsExactly("org/");
    BuildResult listLayers = this.gradleBuild.build("listLayers");
    assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    String listLayersOutput = listLayers.getOutput();
    assertThat(new BufferedReader(new StringReader(listLayersOutput)).lines()).containsSequence(layerNames);
    BuildResult extractLayers = this.gradleBuild.build("extractLayers");
    assertThat(extractLayers.task(":extractLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertExtractedLayers(layerNames, indexedLayers);
}
Also used : ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) BuildResult(org.gradle.testkit.runner.BuildResult) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) JarFile(java.util.jar.JarFile) File(java.io.File) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 27 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class AbstractBootArchiveIntegrationTests method implicitLayers.

@TestTemplate
void implicitLayers() throws IOException {
    writeMainClass();
    writeResource();
    assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    Map<String, List<String>> indexedLayers;
    String layerToolsJar = this.libPath + JarModeLibrary.LAYER_TOOLS.getName();
    try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
        assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "library-1.0-SNAPSHOT.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.classesPath + "example/Main.class")).isNotNull();
        assertThat(jarFile.getEntry(this.classesPath + "static/file.txt")).isNotNull();
        indexedLayers = readLayerIndex(jarFile);
    }
    List<String> layerNames = Arrays.asList("dependencies", "spring-boot-loader", "snapshot-dependencies", "application");
    assertThat(indexedLayers.keySet()).containsExactlyElementsOf(layerNames);
    Set<String> expectedDependencies = new TreeSet<>();
    expectedDependencies.add(this.libPath + "commons-lang3-3.9.jar");
    expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar");
    expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar");
    expectedDependencies.add(this.libPath + "jul-to-slf4j-1.7.28.jar");
    expectedDependencies.add(this.libPath + "log4j-api-2.12.1.jar");
    expectedDependencies.add(this.libPath + "log4j-to-slf4j-2.12.1.jar");
    expectedDependencies.add(this.libPath + "logback-classic-1.2.3.jar");
    expectedDependencies.add(this.libPath + "logback-core-1.2.3.jar");
    expectedDependencies.add(this.libPath + "slf4j-api-1.7.28.jar");
    expectedDependencies.add(this.libPath + "spring-boot-starter-logging-2.2.0.RELEASE.jar");
    Set<String> expectedSnapshotDependencies = new TreeSet<>();
    expectedSnapshotDependencies.add(this.libPath + "library-1.0-SNAPSHOT.jar");
    (layerToolsJar.contains("SNAPSHOT") ? expectedSnapshotDependencies : expectedDependencies).add(layerToolsJar);
    assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies);
    assertThat(indexedLayers.get("spring-boot-loader")).containsExactly("org/");
    assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies);
    assertThat(indexedLayers.get("application")).containsExactly(getExpectedApplicationLayerContents(this.classesPath));
    BuildResult listLayers = this.gradleBuild.build("listLayers");
    assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    String listLayersOutput = listLayers.getOutput();
    assertThat(new BufferedReader(new StringReader(listLayersOutput)).lines()).containsSequence(layerNames);
    BuildResult extractLayers = this.gradleBuild.build("extractLayers");
    assertThat(extractLayers.task(":extractLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertExtractedLayers(layerNames, indexedLayers);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 28 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class AbstractBootArchiveIntegrationTests method customLayers.

@TestTemplate
void customLayers() throws IOException {
    writeMainClass();
    writeResource();
    BuildResult build = this.gradleBuild.build(this.taskName);
    assertThat(build.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    Map<String, List<String>> indexedLayers;
    String layerToolsJar = this.libPath + JarModeLibrary.LAYER_TOOLS.getName();
    try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
        assertThat(jarFile.getEntry(layerToolsJar)).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "commons-lang3-3.9.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "spring-core-5.2.5.RELEASE.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "spring-jcl-5.2.5.RELEASE.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.libPath + "library-1.0-SNAPSHOT.jar")).isNotNull();
        assertThat(jarFile.getEntry(this.classesPath + "example/Main.class")).isNotNull();
        assertThat(jarFile.getEntry(this.classesPath + "static/file.txt")).isNotNull();
        assertThat(jarFile.getEntry(this.indexPath + "layers.idx")).isNotNull();
        indexedLayers = readLayerIndex(jarFile);
    }
    List<String> layerNames = Arrays.asList("dependencies", "commons-dependencies", "snapshot-dependencies", "static", "app");
    assertThat(indexedLayers.keySet()).containsExactlyElementsOf(layerNames);
    Set<String> expectedDependencies = new TreeSet<>();
    expectedDependencies.add(this.libPath + "spring-core-5.2.5.RELEASE.jar");
    expectedDependencies.add(this.libPath + "spring-jcl-5.2.5.RELEASE.jar");
    List<String> expectedSnapshotDependencies = new ArrayList<>();
    expectedSnapshotDependencies.add(this.libPath + "library-1.0-SNAPSHOT.jar");
    (layerToolsJar.contains("SNAPSHOT") ? expectedSnapshotDependencies : expectedDependencies).add(layerToolsJar);
    assertThat(indexedLayers.get("dependencies")).containsExactlyElementsOf(expectedDependencies);
    assertThat(indexedLayers.get("commons-dependencies")).containsExactly(this.libPath + "commons-lang3-3.9.jar");
    assertThat(indexedLayers.get("snapshot-dependencies")).containsExactlyElementsOf(expectedSnapshotDependencies);
    assertThat(indexedLayers.get("static")).containsExactly(this.classesPath + "static/");
    List<String> appLayer = new ArrayList<>(indexedLayers.get("app"));
    String[] appLayerContents = getExpectedApplicationLayerContents(this.classesPath + "example/");
    assertThat(appLayer).containsSubsequence(appLayerContents);
    appLayer.removeAll(Arrays.asList(appLayerContents));
    assertThat(appLayer).containsExactly("org/");
    BuildResult listLayers = this.gradleBuild.build("listLayers");
    assertThat(listLayers.task(":listLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    String listLayersOutput = listLayers.getOutput();
    assertThat(new BufferedReader(new StringReader(listLayersOutput)).lines()).containsSequence(layerNames);
    BuildResult extractLayers = this.gradleBuild.build("extractLayers");
    assertThat(extractLayers.task(":extractLayers").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertExtractedLayers(layerNames, indexedLayers);
}
Also used : ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) BuildResult(org.gradle.testkit.runner.BuildResult) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) JarFile(java.util.jar.JarFile) File(java.io.File) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 29 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class BootJarIntegrationTests method whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds.

@TestTemplate
void whenAResolvableCopyOfAnUnresolvableConfigurationIsResolvedThenResolutionSucceeds() {
    BuildResult build = this.gradleBuild.build("resolveResolvableCopyOfUnresolvableConfiguration");
    assertThat(build.task(":resolveResolvableCopyOfUnresolvableConfiguration").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) TestTemplate(org.junit.jupiter.api.TestTemplate)

Example 30 with BuildResult

use of org.gradle.testkit.runner.BuildResult in project spring-boot by spring-projects.

the class WarPluginActionIntegrationTests method assembleRunsBootWarAndWar.

@TestTemplate
void assembleRunsBootWarAndWar() {
    BuildResult result = this.gradleBuild.build("assemble");
    assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    assertThat(result.task(":war").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
    File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
    assertThat(buildLibs.listFiles()).containsExactlyInAnyOrder(new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".war"), new File(buildLibs, this.gradleBuild.getProjectDir().getName() + "-plain.war"));
}
Also used : BuildResult(org.gradle.testkit.runner.BuildResult) File(java.io.File) TestTemplate(org.junit.jupiter.api.TestTemplate)

Aggregations

BuildResult (org.gradle.testkit.runner.BuildResult)149 File (java.io.File)65 TestTemplate (org.junit.jupiter.api.TestTemplate)60 Test (org.junit.Test)47 Test (org.junit.jupiter.api.Test)21 StringWriter (java.io.StringWriter)19 GradleRunner (org.gradle.testkit.runner.GradleRunner)17 Test (org.testng.annotations.Test)10 ImageReference (org.springframework.boot.buildpack.platform.docker.type.ImageReference)8 JarFile (java.util.jar.JarFile)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 TestHelpers.findFile (me.tatarka.TestHelpers.findFile)6 TestHelpers.writeFile (me.tatarka.TestHelpers.writeFile)6 ContainerConfig (com.github.dockerjava.api.model.ContainerConfig)5 FileWriter (java.io.FileWriter)5 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 Path (java.nio.file.Path)5 BuildTask (org.gradle.testkit.runner.BuildTask)5