|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2021 the original author or authors. |
| 2 | + * Copyright 2012-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
18 | 18 |
|
19 | 19 | import java.io.File;
|
20 | 20 | 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; |
21 | 25 |
|
22 |
| -import org.junit.jupiter.api.Test; |
| 26 | +import org.junit.jupiter.params.ParameterizedTest; |
| 27 | +import org.junit.jupiter.params.provider.MethodSource; |
23 | 28 | import org.testcontainers.containers.GenericContainer;
|
24 | 29 | import org.testcontainers.containers.output.ToStringConsumer;
|
25 | 30 | 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; |
28 | 32 | import org.testcontainers.utility.DockerImageName;
|
29 | 33 | import org.testcontainers.utility.MountableFile;
|
30 | 34 |
|
|
37 | 41 | *
|
38 | 42 | * @author Phillip Webb
|
39 | 43 | */
|
40 |
| -@Testcontainers(disabledWithoutDocker = true) |
41 | 44 | class LoaderIntegrationTests {
|
42 | 45 |
|
43 |
| - private static final DockerImageName JRE = DockerImageName.parse("eclipse-temurin:17.0.1_12-jdk-alpine"); |
| 46 | + private final ToStringConsumer output = new ToStringConsumer(); |
44 | 47 |
|
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 | + } |
46 | 58 |
|
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 | + } |
52 | 65 |
|
53 |
| - private static File findApplication() { |
| 66 | + private File findApplication() { |
54 | 67 | String name = String.format("build/%1$s/build/libs/%1$s.jar", "spring-boot-loader-tests-app");
|
55 | 68 | File jar = new File(name);
|
56 | 69 | Assert.state(jar.isFile(), () -> "Could not find " + name + ". Have you built it?");
|
57 | 70 | return jar;
|
58 | 71 | }
|
59 | 72 |
|
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("17")); |
| 76 | + javaRuntimes.add(JavaRuntime.oracleJdk17()); |
| 77 | + return javaRuntimes.stream(); |
| 78 | + } |
| 79 | + |
| 80 | + static final class JavaRuntime { |
| 81 | + |
| 82 | + private final Supplier<GenericContainer<?>> container; |
| 83 | + |
| 84 | + private JavaRuntime(Supplier<GenericContainer<?>> container) { |
| 85 | + this.container = container; |
| 86 | + } |
| 87 | + |
| 88 | + GenericContainer<?> getContainer() { |
| 89 | + return this.container.get(); |
| 90 | + } |
| 91 | + |
| 92 | + static JavaRuntime openJdk(String version) { |
| 93 | + DockerImageName image = DockerImageName.parse("bellsoft/liberica-openjdk-debian:" + version); |
| 94 | + return new JavaRuntime(() -> new GenericContainer<>(image)); |
| 95 | + } |
| 96 | + |
| 97 | + static JavaRuntime oracleJdk17() { |
| 98 | + ImageFromDockerfile image = new ImageFromDockerfile("spring-boot-loader/oracle-jdk-17") |
| 99 | + .withFileFromFile("Dockerfile", new File("src/intTest/resources/conf/oracle-jdk-17/Dockerfile")); |
| 100 | + return new JavaRuntime(() -> new GenericContainer<>(image)); |
| 101 | + } |
| 102 | + |
65 | 103 | }
|
66 | 104 |
|
67 | 105 | }
|
0 commit comments