|
1 | 1 | /* |
2 | | - * Copyright 2012-2020 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("adoptopenjdk:15-jre-hotspot"); |
| 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("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 | + |
65 | 105 | } |
66 | 106 |
|
67 | 107 | } |
0 commit comments