@ -1,5 +1,5 @@
/ *
* Copyright 2012 - 202 0 the original author or authors .
* Copyright 2012 - 202 2 the original author or authors .
*
* Licensed under the Apache License , Version 2.0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,13 +18,17 @@ package org.springframework.boot.loader;
import java.io.File ;
import java.time.Duration ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.function.Supplier ;
import java.util.stream.Stream ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.params.ParameterizedTest ;
import org.junit.jupiter.params.provider.MethodSource ;
import org.testcontainers.containers.GenericContainer ;
import org.testcontainers.containers.output.ToStringConsumer ;
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy ;
import org.testcontainers.junit.jupiter.Container ;
import org.testcontainers.junit.jupiter.Testcontainers ;
import org.testcontainers.images.builder.ImageFromDockerfile ;
import org.testcontainers.utility.DockerImageName ;
import org.testcontainers.utility.MountableFile ;
@ -37,31 +41,67 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
* /
@Testcontainers ( disabledWithoutDocker = true )
class LoaderIntegrationTests {
private static final DockerImageName JRE = DockerImageName . parse ( "adoptopenjdk:15-jre-hotspot" ) ;
private final ToStringConsumer output = new ToStringConsumer ( ) ;
private static ToStringConsumer output = new ToStringConsumer ( ) ;
@ParameterizedTest
@MethodSource ( "javaRuntimes" )
void readUrlsWithoutWarning ( JavaRuntime javaRuntime ) {
try ( GenericContainer < ? > container = createContainer ( javaRuntime ) ) {
container . start ( ) ;
System . out . println ( this . output . toUtf8String ( ) ) ;
assertThat ( this . output . toUtf8String ( ) ) . contains ( ">>>>> 287649 BYTES from" ) . doesNotContain ( "WARNING:" )
. doesNotContain ( "illegal" ) . doesNotContain ( "jar written to temp" ) ;
}
}
@Container
public static GenericContainer < ? > container = new GenericContainer < > ( JRE ) . withLogConsumer ( output )
. withCopyFileToContainer ( MountableFile . forHostPath ( findApplication ( ) . toPath ( ) ) , "/app.jar" )
. withStartupCheckStrategy ( new OneShotStartupCheckStrategy ( ) . withTimeout ( Duration . ofMinutes ( 5 ) ) )
. withCommand ( "java" , "-jar" , "app.jar" ) ;
private GenericContainer < ? > createContainer ( JavaRuntime javaRuntime ) {
return javaRuntime . getContainer ( ) . withLogConsumer ( this . output )
. withCopyFileToContainer ( MountableFile . forHostPath ( findApplication ( ) . toPath ( ) ) , "/app.jar" )
. withStartupCheckStrategy ( new OneShotStartupCheckStrategy ( ) . withTimeout ( Duration . ofMinutes ( 5 ) ) )
. withCommand ( "java" , "-jar" , "app.jar" ) ;
}
private static File findApplication ( ) {
private File findApplication ( ) {
String name = String . format ( "build/%1$s/build/libs/%1$s.jar" , "spring-boot-loader-tests-app" ) ;
File jar = new File ( name ) ;
Assert . state ( jar . isFile ( ) , ( ) - > "Could not find " + name + ". Have you built it?" ) ;
return jar ;
}
@Test
void readUrlsWithoutWarning ( ) {
System . out . println ( output . toUtf8String ( ) ) ;
assertThat ( output . toUtf8String ( ) ) . contains ( ">>>>> 287649 BYTES from" ) . doesNotContain ( "WARNING:" )
. doesNotContain ( "illegal" ) . doesNotContain ( "jar written to temp" ) ;
static Stream < JavaRuntime > javaRuntimes ( ) {
List < JavaRuntime > javaRuntimes = new ArrayList < > ( ) ;
javaRuntimes . add ( JavaRuntime . openJdk ( "8" ) ) ;
javaRuntimes . add ( JavaRuntime . openJdk ( "11" ) ) ;
javaRuntimes . add ( JavaRuntime . openJdk ( "17" ) ) ;
javaRuntimes . add ( JavaRuntime . oracleJdk17 ( ) ) ;
return javaRuntimes . stream ( ) ;
}
static final class JavaRuntime {
private final Supplier < GenericContainer < ? > > container ;
private JavaRuntime ( Supplier < GenericContainer < ? > > container ) {
this . container = container ;
}
GenericContainer < ? > getContainer ( ) {
return this . container . get ( ) ;
}
static JavaRuntime openJdk ( String version ) {
DockerImageName image = DockerImageName . parse ( "bellsoft/liberica-openjdk-debian:" + version ) ;
return new JavaRuntime ( ( ) - > new GenericContainer < > ( image ) ) ;
}
static JavaRuntime oracleJdk17 ( ) {
ImageFromDockerfile image = new ImageFromDockerfile ( "spring-boot-loader/oracle-jdk-17" )
. withFileFromFile ( "Dockerfile" , new File ( "src/intTest/resources/conf/oracle-jdk-17/Dockerfile" ) ) ;
return new JavaRuntime ( ( ) - > new GenericContainer < > ( image ) ) ;
}
}
}