WarIntegrationTests Class — spring-boot Architecture
Architecture documentation for the WarIntegrationTests class in WarIntegrationTests.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/WarIntegrationTests.java lines 46–261
@ExtendWith(MavenBuildExtension.class)
class WarIntegrationTests extends AbstractArchiveIntegrationTests {
@Override
protected String getLayersIndexLocation() {
return "WEB-INF/layers.idx";
}
@TestTemplate
void warRepackaging(MavenBuild mavenBuild) {
mavenBuild.project("war")
.execute((project) -> assertThat(jar(new File(project, "target/war-0.0.1.BUILD-SNAPSHOT.war")))
.hasEntryWithNameStartingWith("WEB-INF/lib/spring-context")
.hasEntryWithNameStartingWith("WEB-INF/lib/spring-core")
.hasEntryWithNameStartingWith("WEB-INF/lib/commons-logging")
.hasEntryWithNameStartingWith("WEB-INF/lib-provided/jakarta.servlet-api-6")
.hasEntryWithName("org/springframework/boot/loader/launch/WarLauncher.class")
.hasEntryWithName("WEB-INF/classes/org/test/SampleApplication.class")
.hasEntryWithName("index.html")
.manifest((manifest) -> manifest.hasMainClass("org.springframework.boot.loader.launch.WarLauncher")
.hasStartClass("org.test.SampleApplication")
.hasAttribute("Not-Used", "Foo")));
}
@TestTemplate
void jarDependencyWithCustomFinalNameBuiltInSameReactorIsPackagedUsingArtifactIdAndVersion(MavenBuild mavenBuild) {
mavenBuild.project("war-reactor")
.execute(((project) -> assertThat(jar(new File(project, "war/target/war-0.0.1.BUILD-SNAPSHOT.war")))
.hasEntryWithName("WEB-INF/lib/jar-0.0.1.BUILD-SNAPSHOT.jar")
.doesNotHaveEntryWithName("WEB-INF/lib/jar.jar")));
}
@TestTemplate
void whenRequiresUnpackConfigurationIsProvidedItIsReflectedInTheRepackagedWar(MavenBuild mavenBuild) {
mavenBuild.project("war-with-unpack")
.execute((project) -> assertThat(jar(new File(project, "target/war-with-unpack-0.0.1.BUILD-SNAPSHOT.war")))
.hasUnpackEntryWithNameStartingWith("WEB-INF/lib/spring-core-")
.hasEntryWithNameStartingWith("WEB-INF/lib/spring-context-")
.hasEntryWithNameStartingWith("WEB-INF/lib/commons-logging-"));
}
@TestTemplate
void whenWarIsRepackagedWithOutputTimestampConfiguredThenWarIsReproducible(MavenBuild mavenBuild)
throws InterruptedException {
String firstHash = buildWarWithOutputTimestamp(mavenBuild);
Thread.sleep(1500);
String secondHash = buildWarWithOutputTimestamp(mavenBuild);
assertThat(firstHash).isEqualTo(secondHash);
}
private String buildWarWithOutputTimestamp(MavenBuild mavenBuild) {
AtomicReference<String> warHash = new AtomicReference<>();
mavenBuild.project("war-output-timestamp").execute((project) -> {
File repackaged = new File(project, "target/war-output-timestamp-0.0.1.BUILD-SNAPSHOT.war");
assertThat(repackaged).isFile();
long expectedModified = 1584352800000L;
assertThat(repackaged.lastModified()).isEqualTo(expectedModified);
long offsetExpectedModified = expectedModified - TimeZone.getDefault().getOffset(expectedModified);
try (JarFile jar = new JarFile(repackaged)) {
List<String> unreproducibleEntries = jar.stream()
.filter((entry) -> entry.getLastModifiedTime().toMillis() != offsetExpectedModified)
.map((entry) -> entry.getName() + ": " + entry.getLastModifiedTime())
.toList();
assertThat(unreproducibleEntries).isEmpty();
warHash.set(FileUtils.sha1Hash(repackaged));
FileSystemUtils.deleteRecursively(project);
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
});
String hash = warHash.get();
assertThat(hash).isNotNull();
return hash;
}
@TestTemplate
void whenWarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) {
mavenBuild.project("war-output-timestamp").execute((project) -> {
File repackaged = new File(project, "target/war-output-timestamp-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
List<String> sortedLibs = Arrays.asList(
// these libraries are copied from the original war, sorted when
// packaged by Maven
"WEB-INF/lib/commons-logging", "WEB-INF/lib/jspecify", "WEB-INF/lib/micrometer-commons",
"WEB-INF/lib/micrometer-observation", "WEB-INF/lib/spring-aop", "WEB-INF/lib/spring-beans",
"WEB-INF/lib/spring-context", "WEB-INF/lib/spring-core", "WEB-INF/lib/spring-expression",
// these libraries are contributed by Spring Boot repackaging, and
// sorted separately
"WEB-INF/lib/" + coordinates.getArtifactId());
assertThat(jar(repackaged)).entryNamesInPath("WEB-INF/lib/")
.zipSatisfy(sortedLibs,
(String jarLib, String expectedLib) -> assertThat(jarLib).startsWith(expectedLib));
});
}
@TestTemplate
void whenADependencyHasSystemScopeAndInclusionOfSystemScopeDependenciesIsEnabledItIsIncludedInTheRepackagedJar(
MavenBuild mavenBuild) {
mavenBuild.project("war-system-scope").execute((project) -> {
File main = new File(project, "target/war-system-scope-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(main)).hasEntryWithName("WEB-INF/lib-provided/sample-1.0.0.jar");
});
}
@TestTemplate
void repackagedWarContainsTheLayersIndexByDefault(MavenBuild mavenBuild) {
mavenBuild.project("war-layered").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.hasEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId());
try (JarFile jarFile = new JarFile(repackaged)) {
Map<String, List<String>> layerIndex = readLayerIndex(jarFile);
assertThat(layerIndex.keySet()).containsExactly("dependencies", "spring-boot-loader",
"snapshot-dependencies", "application");
List<String> dependenciesAndSnapshotDependencies = new ArrayList<>();
dependenciesAndSnapshotDependencies.addAll(layerIndex.get("dependencies"));
dependenciesAndSnapshotDependencies.addAll(layerIndex.get("snapshot-dependencies"));
assertThat(layerIndex.get("application")).contains("WEB-INF/lib/jar-release-0.0.1.RELEASE.jar",
"WEB-INF/lib/jar-snapshot-0.0.1.BUILD-SNAPSHOT.jar");
assertThat(dependenciesAndSnapshotDependencies)
.anyMatch((dependency) -> dependency.startsWith("WEB-INF/lib/spring-context"));
assertThat(layerIndex.get("dependencies"))
.anyMatch((dependency) -> dependency.startsWith("WEB-INF/lib-provided/"));
}
catch (IOException ex) {
// Ignore
}
});
}
@TestTemplate
void whenWarIsRepackagedWithTheLayersDisabledDoesNotContainLayersIndex(MavenBuild mavenBuild) {
mavenBuild.project("war-layered-disabled").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.hasEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId())
.doesNotHaveEntryWithName("WEB-INF/layers.idx");
});
}
@TestTemplate
void whenWarIsRepackagedWithToolsExclude(MavenBuild mavenBuild) {
mavenBuild.project("war-no-tools").execute((project) -> {
File repackaged = new File(project, "war/target/war-no-tools-0.0.1.BUILD-SNAPSHOT.war");
LibraryCoordinates coordinates = JarModeLibrary.TOOLS.getCoordinates();
assertThat(coordinates).isNotNull();
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot")
.doesNotHaveEntryWithNameStartingWith("WEB-INF/lib/" + coordinates.getArtifactId());
});
}
@TestTemplate
void whenWarIsRepackagedWithTheCustomLayers(MavenBuild mavenBuild) {
mavenBuild.project("war-layered-custom").execute((project) -> {
File repackaged = new File(project, "war/target/war-layered-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(repackaged)).hasEntryWithNameStartingWith("WEB-INF/classes/")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-release")
.hasEntryWithNameStartingWith("WEB-INF/lib/jar-snapshot");
try (JarFile jarFile = new JarFile(repackaged)) {
Map<String, List<String>> layerIndex = readLayerIndex(jarFile);
assertThat(layerIndex.keySet()).containsExactly("my-dependencies-name", "snapshot-dependencies",
"configuration", "application");
assertThat(layerIndex.get("application"))
.contains("WEB-INF/lib/jar-release-0.0.1.RELEASE.jar",
"WEB-INF/lib/jar-snapshot-0.0.1.BUILD-SNAPSHOT.jar",
"WEB-INF/lib/jar-classifier-0.0.1-bravo.jar")
.doesNotContain("WEB-INF/lib/jar-classifier-0.0.1-alpha.jar");
}
});
}
@TestTemplate
void repackagedWarContainsClasspathIndex(MavenBuild mavenBuild) {
mavenBuild.project("war").execute((project) -> {
File repackaged = new File(project, "target/war-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(repackaged))
.manifest((manifest) -> manifest.hasAttribute("Spring-Boot-Classpath-Index", "WEB-INF/classpath.idx"));
assertThat(jar(repackaged)).hasEntryWithName("WEB-INF/classpath.idx");
try (JarFile jarFile = new JarFile(repackaged)) {
List<String> index = readClasspathIndex(jarFile, "WEB-INF/classpath.idx");
assertThat(index)
.allMatch((entry) -> entry.startsWith("WEB-INF/lib/") || entry.startsWith("WEB-INF/lib-provided/"));
}
});
}
@TestTemplate
void whenEntryIsExcludedItShouldNotBePresentInTheRepackagedWar(MavenBuild mavenBuild) {
mavenBuild.project("war-exclude-entry").execute((project) -> {
File war = new File(project, "target/war-exclude-entry-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(war)).hasEntryWithNameStartingWith("WEB-INF/lib/spring-context")
.doesNotHaveEntryWithNameStartingWith("WEB-INF/lib/spring-core");
});
}
@TestTemplate
void whenSigned(MavenBuild mavenBuild) {
mavenBuild.project("war-signed").execute((project) -> {
File repackaged = new File(project, "target/war-signed-0.0.1.BUILD-SNAPSHOT.war");
assertThat(jar(repackaged)).hasEntryWithName("META-INF/BOOT.SF");
});
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free