Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.quarkus.it.jaxb;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.containsString;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -31,7 +31,7 @@ void book() {
.then()
.statusCode(200)
// The height in pixels of the book's cover image.
.body(equalTo("\"10\""));
.body(containsString("10"));
}

/**
Expand All @@ -47,6 +47,6 @@ void lambda() {
.post()
.then()
.statusCode(200)
.body(equalTo("\"10\""));
.body(containsString("10"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import io.quarkus.bootstrap.app.CuratedApplication;

public interface ArtifactLauncher<T extends ArtifactLauncher.InitContext> extends Closeable {

void init(T t);

void start() throws IOException;
Optional<ListeningAddress> start() throws IOException;

LaunchResult runToCompletion(String[] args);

void includeAsSysProps(Map<String, String> systemProps);

boolean listensOnSsl();

interface InitContext {

int httpPort();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.common;

import static io.quarkus.test.common.LauncherUtil.createStartedFunction;
import static io.quarkus.test.common.LauncherUtil.updateConfigForPort;
import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData;
import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction;
import static java.lang.ProcessBuilder.Redirect.DISCARD;
Expand Down Expand Up @@ -52,7 +51,6 @@ public class DefaultDockerContainerLauncher implements DockerContainerArtifactLa
private Map<String, String> volumeMounts;
private Map<String, String> labels;
private final Map<String, String> systemProps = new HashMap<>();
private boolean isSsl;
private final String containerName = "quarkus-integration-test-" + RandomStringUtils.insecure().next(5, true, false);
private String containerRuntimeBinaryName;
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
Expand Down Expand Up @@ -96,8 +94,6 @@ public LaunchResult runToCompletion(String[] argz) {
}
}

System.setProperty("test.url", TestHTTPResourceManager.getUri());

final List<String> args = new ArrayList<>();
args.add(containerRuntimeBinaryName);
args.add("run");
Expand Down Expand Up @@ -188,7 +184,7 @@ public LaunchResult runToCompletion(String[] argz) {
}

@Override
public void start() throws IOException {
public Optional<ListeningAddress> start() throws IOException {
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);

Expand All @@ -208,8 +204,6 @@ public void start() throws IOException {
}
}

System.setProperty("test.url", TestHTTPResourceManager.getUri());

if (httpPort == 0) {
httpPort = getRandomPort();
}
Expand Down Expand Up @@ -301,15 +295,13 @@ public void start() throws IOException {
.start();

if (startedFunction != null) {
final IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, containerProcess,
waitTimeSeconds, logPath);
isSsl = result.isSsl();
waitForStartedFunction(startedFunction, containerProcess, waitTimeSeconds, logPath);
return Optional.empty();
} else {
log.info("Wait for server to start by capturing listening data...");
final ListeningAddress result = waitForCapturedListeningData(containerProcess, logPath, waitTimeSeconds);
ListeningAddress result = waitForCapturedListeningData(containerProcess, logPath, waitTimeSeconds);
log.infof("Server started on port %s", result.getPort());
updateConfigForPort(result.getPort());
isSsl = result.isSsl();
return Optional.of(result);
}
}

Expand All @@ -319,10 +311,6 @@ private int getRandomPort() throws IOException {
}
}

public boolean listensOnSsl() {
return isSsl;
}

public void includeAsSysProps(Map<String, String> systemProps) {
this.systemProps.putAll(systemProps);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.common;

import static io.quarkus.test.common.LauncherUtil.createStartedFunction;
import static io.quarkus.test.common.LauncherUtil.updateConfigForPort;
import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData;
import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction;

Expand All @@ -15,6 +14,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

import org.eclipse.microprofile.config.ConfigProvider;
Expand Down Expand Up @@ -55,7 +55,6 @@ public class DefaultJarLauncher implements JarArtifactLauncher {
private final Map<String, String> systemProps = new HashMap<>();
private Process quarkusProcess;

private boolean isSsl;
private Path logFile;

@Override
Expand All @@ -70,21 +69,20 @@ public void init(JarArtifactLauncher.JarInitContext initContext) {
this.generateAotFile = initContext.generateAotFile();
}

public void start() throws IOException {
@Override
public Optional<ListeningAddress> start() throws IOException {
start(new String[0], true);
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
.getConfigMapping(LogRuntimeConfig.class);
logFile = logRuntimeConfig.file().path().toPath();
if (startedFunction != null) {
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
waitTimeSeconds, logFile);
isSsl = result.isSsl();
waitForStartedFunction(startedFunction, quarkusProcess, waitTimeSeconds, logFile);
return Optional.empty();
} else {
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
waitTimeSeconds);
updateConfigForPort(result.getPort());
isSsl = result.isSsl();
return Optional.of(result);
}
}

Expand All @@ -110,7 +108,6 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
logFile = logRuntimeConfig.file().path().toPath();
System.setProperty("test.url", TestHTTPResourceManager.getUri());

List<String> args = new ArrayList<>();
args.add(determineJavaPath());
Expand Down Expand Up @@ -180,11 +177,6 @@ private String determineJavaPath() {
return "java";
}

@Override
public boolean listensOnSsl() {
return isSsl;
}

@Override
public void includeAsSysProps(Map<String, String> systemProps) {
this.systemProps.putAll(systemProps);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.common;

import static io.quarkus.test.common.LauncherUtil.createStartedFunction;
import static io.quarkus.test.common.LauncherUtil.updateConfigForPort;
import static io.quarkus.test.common.LauncherUtil.waitForCapturedListeningData;
import static io.quarkus.test.common.LauncherUtil.waitForStartedFunction;

Expand All @@ -19,14 +18,15 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;

import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.logging.Logger;

import io.quarkus.runtime.logging.LogRuntimeConfig;
import io.quarkus.test.common.http.TestHTTPResourceManager;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.SmallRyeConfig;

public class DefaultNativeImageLauncher implements NativeImageLauncher {
Expand All @@ -47,7 +47,6 @@ public class DefaultNativeImageLauncher implements NativeImageLauncher {
private Process quarkusProcess;
private final Map<String, String> systemProps = new HashMap<>();

private boolean isSsl;
private Path logFile;

@Override
Expand Down Expand Up @@ -83,28 +82,26 @@ public LaunchResult runToCompletion(String[] args) {
}
}

public void start() throws IOException {
@Override
public Optional<ListeningAddress> start() throws IOException {
start(new String[0], true);
LogRuntimeConfig logRuntimeConfig = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class)
.getConfigMapping(LogRuntimeConfig.class);
logFile = logRuntimeConfig.file().path().toPath();
Function<IntegrationTestStartedNotifier.Context, IntegrationTestStartedNotifier.Result> startedFunction = createStartedFunction();
if (startedFunction != null) {
IntegrationTestStartedNotifier.Result result = waitForStartedFunction(startedFunction, quarkusProcess,
waitTimeSeconds, logRuntimeConfig.file().path().toPath());
isSsl = result.isSsl();
waitForStartedFunction(startedFunction, quarkusProcess, waitTimeSeconds, logRuntimeConfig.file().path().toPath());
return Optional.empty();
} else {
ListeningAddress result = waitForCapturedListeningData(quarkusProcess, logRuntimeConfig.file().path().toPath(),
waitTimeSeconds);
updateConfigForPort(result.getPort());
isSsl = result.isSsl();
return Optional.of(result);
}
}

public void start(String[] programArgs, boolean handleIo) throws IOException {
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
LogRuntimeConfig logRuntimeConfig = config.getConfigMapping(LogRuntimeConfig.class);
System.setProperty("test.url", TestHTTPResourceManager.getUri());

if (nativeImagePath == null) {
nativeImagePath = guessPath(testClass);
Expand All @@ -117,9 +114,15 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
if (DefaultJarLauncher.HTTP_PRESENT) {
args.add("-Dquarkus.http.port=" + httpPort);
args.add("-Dquarkus.http.ssl-port=" + httpsPort);
// this won't be correct when using the random port but it's really only used by us for the rest client tests
// in the main module, since those tests hit the application itself
args.add("-Dtest.url=" + TestHTTPResourceManager.getUri());
// Check io.quarkus.test.common.http.TestHTTPConfigSourceInterceptor.sanitizeUrl
String rootPath = "";
// These are build time properties so it is fine to evaluate them here
ConfigValue rootPathValue = config.getConfigValue("${quarkus.http.root-path:${quarkus.servlet.context-path:}}");
if (rootPathValue.getValue() != null && rootPathValue.getValue().endsWith("/")) {
rootPath = rootPathValue.getValue().substring(0, rootPathValue.getValue().length() - 1);
}
// We want to keep `quarkus.http.test-port` as an expression so it is evaluated correctly
args.add("-Dtest.url=http://localhost:${quarkus.http.test-port:8081}" + rootPath);
}
logFile = logRuntimeConfig.file().path().toPath();
args.add("-Dquarkus.log.file.path=" + logFile.toAbsolutePath());
Expand Down Expand Up @@ -148,7 +151,6 @@ public void start(String[] programArgs, boolean handleIo) throws IOException {
} else {
quarkusProcess = LauncherUtil.launchProcess(args, env);
}

}

private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process quarkusProcess, long waitTime) {
Expand All @@ -161,7 +163,6 @@ private void waitForStartedSupplier(Supplier<Boolean> startedSupplier, Process q
try {
Thread.sleep(100);
if (startedSupplier.get()) {
isSsl = false;
started = true;
break;
}
Expand Down Expand Up @@ -264,10 +265,6 @@ private static void logGuessedPath(String guessedPath) {
System.err.println("======================================================================================");
}

public boolean listensOnSsl() {
return isSsl;
}

@Override
public void includeAsSysProps(Map<String, String> systemProps) {
this.systemProps.putAll(systemProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import io.quarkus.test.common.http.TestHTTPResourceManager;
import io.smallrye.common.os.OS;

public final class LauncherUtil {
Expand Down Expand Up @@ -208,19 +207,6 @@ static IntegrationTestStartedNotifier.Result waitForStartedFunction(
return result;
}

/**
* Updates the configuration necessary to make all test systems knowledgeable about the port on which the launched
* process is listening
*/
static void updateConfigForPort(Integer effectivePort) {
if (effectivePort != null) {
System.setProperty("quarkus.http.port", effectivePort.toString()); //set the port as a system property in order to have it applied to Config
System.setProperty("quarkus.http.test-port", effectivePort.toString()); // needed for RestAssuredManager
System.clearProperty("test.url"); // make sure the old value does not interfere with setting the new one
System.setProperty("test.url", TestHTTPResourceManager.getUri());
}
}

static void toStdOut(Path log) {
if (log != null) {
try (var r = Files.newBufferedReader(log, StandardCharsets.UTF_8)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -110,7 +111,7 @@ public LaunchResult runToCompletion(String[] args) {
}

@Override
public void start() throws IOException {
public Optional<ListeningAddress> start() throws IOException {
System.setProperty("test.url", TestHTTPResourceManager.getUri());

Path logFile = logFilePath;
Expand Down Expand Up @@ -161,10 +162,8 @@ public void start() throws IOException {
LauncherUtil.destroyProcess(quarkusProcess, true);
throw new RuntimeException("Unable to start target quarkus application " + this.waitTimeSeconds + "s");
}
}

public boolean listensOnSsl() {
return false;
return Optional.empty();
}

public void includeAsSysProps(Map<String, String> systemProps) {
Expand Down
Loading
Loading