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);
}
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);
}
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);
}
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);
}
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"));
}
Aggregations