Skip to content

Commit 44537d4

Browse files
committed
Merge branch '2.5.x' into 2.6.x
Closes gh-29462
2 parents 3b44093 + 3d90807 commit 44537d4

File tree

3 files changed

+71
-18
lines changed

3 files changed

+71
-18
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,13 +18,17 @@
1818

1919
import java.io.File;
2020
import java.time.Duration;
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import java.util.function.Supplier;
24+
import java.util.stream.Stream;
2125

22-
import org.junit.jupiter.api.Test;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.provider.MethodSource;
2328
import org.testcontainers.containers.GenericContainer;
2429
import org.testcontainers.containers.output.ToStringConsumer;
2530
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
26-
import org.testcontainers.junit.jupiter.Container;
27-
import org.testcontainers.junit.jupiter.Testcontainers;
31+
import org.testcontainers.images.builder.ImageFromDockerfile;
2832
import org.testcontainers.utility.DockerImageName;
2933
import org.testcontainers.utility.MountableFile;
3034

@@ -37,31 +41,67 @@
3741
*
3842
* @author Phillip Webb
3943
*/
40-
@Testcontainers(disabledWithoutDocker = true)
4144
class LoaderIntegrationTests {
4245

43-
private static final DockerImageName JRE = DockerImageName.parse("adoptopenjdk:15-jre-hotspot");
46+
private final ToStringConsumer output = new ToStringConsumer();
4447

45-
private static ToStringConsumer output = new ToStringConsumer();
48+
@ParameterizedTest
49+
@MethodSource("javaRuntimes")
50+
void readUrlsWithoutWarning(JavaRuntime javaRuntime) {
51+
try (GenericContainer<?> container = createContainer(javaRuntime)) {
52+
container.start();
53+
System.out.println(this.output.toUtf8String());
54+
assertThat(this.output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:")
55+
.doesNotContain("illegal").doesNotContain("jar written to temp");
56+
}
57+
}
4658

47-
@Container
48-
public static GenericContainer<?> container = new GenericContainer<>(JRE).withLogConsumer(output)
49-
.withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar")
50-
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
51-
.withCommand("java", "-jar", "app.jar");
59+
private GenericContainer<?> createContainer(JavaRuntime javaRuntime) {
60+
return javaRuntime.getContainer().withLogConsumer(this.output)
61+
.withCopyFileToContainer(MountableFile.forHostPath(findApplication().toPath()), "/app.jar")
62+
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
63+
.withCommand("java", "-jar", "app.jar");
64+
}
5265

53-
private static File findApplication() {
66+
private File findApplication() {
5467
String name = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-loader-tests-app");
5568
File jar = new File(name);
5669
Assert.state(jar.isFile(), () -> "Could not find " + name + ". Have you built it?");
5770
return jar;
5871
}
5972

60-
@Test
61-
void readUrlsWithoutWarning() {
62-
System.out.println(output.toUtf8String());
63-
assertThat(output.toUtf8String()).contains(">>>>> 287649 BYTES from").doesNotContain("WARNING:")
64-
.doesNotContain("illegal").doesNotContain("jar written to temp");
73+
static Stream<JavaRuntime> javaRuntimes() {
74+
List<JavaRuntime> javaRuntimes = new ArrayList<>();
75+
javaRuntimes.add(JavaRuntime.openJdk("8"));
76+
javaRuntimes.add(JavaRuntime.openJdk("11"));
77+
javaRuntimes.add(JavaRuntime.openJdk("17"));
78+
javaRuntimes.add(JavaRuntime.oracleJdk17());
79+
return javaRuntimes.stream();
80+
}
81+
82+
static final class JavaRuntime {
83+
84+
private final Supplier<GenericContainer<?>> container;
85+
86+
private JavaRuntime(Supplier<GenericContainer<?>> container) {
87+
this.container = container;
88+
}
89+
90+
GenericContainer<?> getContainer() {
91+
return this.container.get();
92+
}
93+
94+
static JavaRuntime openJdk(String version) {
95+
DockerImageName image = DockerImageName.parse("bellsoft/liberica-openjdk-debian:" + version);
96+
return new JavaRuntime(() -> new GenericContainer<>(image));
97+
}
98+
99+
static JavaRuntime oracleJdk17() {
100+
ImageFromDockerfile image = new ImageFromDockerfile("spring-boot-loader/oracle-jdk-17")
101+
.withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/Dockerfile"));
102+
return new JavaRuntime(() -> new GenericContainer<>(image));
103+
}
104+
65105
}
66106

67107
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM ubuntu:focal-20211006
2+
RUN apt-get update && \
3+
apt-get install -y software-properties-common curl && \
4+
mkdir -p /opt/oraclejdk && \
5+
cd /opt/oraclejdk && \
6+
curl -L https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz | tar zx --strip-components=1
7+
ENV JAVA_HOME /opt/oraclejdk
8+
ENV PATH $JAVA_HOME/bin:$PATH
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This folder contains a Dockerfile that will create an Oracle JDK instance for use in integration tests.
2+
The resulting Docker image should not be published.
3+
4+
Oracle JDK is subject to the https://www.oracle.com/downloads/licenses/no-fee-license.html["Oracle No-Fee Terms and Conditions" License (NFTC)] license.
5+
We are specifically using the unmodified JDK for the purposes of developing and testing.

0 commit comments

Comments
 (0)