From 318374a4ad56139803a67841c281117d6f72ece5 Mon Sep 17 00:00:00 2001 From: Fedor Dudinskiy Date: Fri, 6 Jan 2023 13:04:15 +0100 Subject: [PATCH 1/2] Add an option to choose, which artifact to run Required for coverage of https://issues.redhat.com/browse/QUARKUS-2777 --- .../test/java/io/quarkus/qe/TodoDemoIT.java | 33 +++++++++++++++---- .../GitRepositoryQuarkusApplication.java | 2 ++ ...rkusApplicationManagedResourceBuilder.java | 1 + ...rkusApplicationManagedResourceBuilder.java | 32 +++++++++++++----- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java b/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java index 3dda1974e..b2fae2d0f 100644 --- a/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java +++ b/examples/external-applications/src/test/java/io/quarkus/qe/TodoDemoIT.java @@ -11,14 +11,35 @@ @DisabledOnNative(reason = "This scenario is using uber-jar, so it's incompatible with Native") @QuarkusScenario public class TodoDemoIT { - @GitRepositoryQuarkusApplication(repo = "https://github.com/quarkusio/todo-demo-app.git", mavenArgs = "-Dquarkus.package.type=uber-jar -DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_VERSION}") + private static final String REPO = "https://github.com/quarkusio/todo-demo-app.git"; + private static final String DEFAULT_ARGS = "-DskipTests=true -Dquarkus.platform.group-id=${QUARKUS_PLATFORM_GROUP-ID} -Dquarkus.platform.version=${QUARKUS_VERSION} "; + private static final String UBER = "-Dquarkus.package.type=uber-jar "; + + @GitRepositoryQuarkusApplication(repo = REPO, mavenArgs = DEFAULT_ARGS + UBER) static final RestService app = new RestService(); + @GitRepositoryQuarkusApplication(repo = REPO, artifact = "todo-backend-1.0-SNAPSHOT-runner.jar", mavenArgs = DEFAULT_ARGS + + UBER) + static final RestService explicit = new RestService(); + + private static final String NO_SUFFIX = "-Dquarkus.package.add-runner-suffix=false"; + + @GitRepositoryQuarkusApplication(repo = REPO, artifact = "todo-backend-1.0-SNAPSHOT.jar", mavenArgs = DEFAULT_ARGS + UBER + + NO_SUFFIX) + static final RestService unsuffixed = new RestService(); + @Test public void verify() { - app.given() - .get() - .then() - .statusCode(HttpStatus.SC_OK); + app.given().get().then().statusCode(HttpStatus.SC_OK); + } + + @Test + public void verifyExplicitArtifact() { + explicit.given().get().then().statusCode(HttpStatus.SC_OK); + } + + @Test + public void verifyNoSuffix() { + unsuffixed.given().get().then().statusCode(HttpStatus.SC_OK); } -} \ No newline at end of file +} diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/GitRepositoryQuarkusApplication.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/GitRepositoryQuarkusApplication.java index 6ff2c6f2d..c6ced5e87 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/GitRepositoryQuarkusApplication.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/GitRepositoryQuarkusApplication.java @@ -21,6 +21,8 @@ String mavenArgs() default "-DskipTests=true -DskipITs=true " boolean devMode() default false; + String artifact() default ""; + /** * @return the properties file to use to configure the Quarkus application. */ diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/GitRepositoryQuarkusApplicationManagedResourceBuilder.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/GitRepositoryQuarkusApplicationManagedResourceBuilder.java index d8b4d23b5..626c5b40a 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/GitRepositoryQuarkusApplicationManagedResourceBuilder.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/GitRepositoryQuarkusApplicationManagedResourceBuilder.java @@ -61,6 +61,7 @@ public void init(Annotation annotation) { contextDir = metadata.contextDir(); mavenArgs = metadata.mavenArgs(); devMode = metadata.devMode(); + setArtifactSuffix(metadata.artifact()); initAppClasses(new Class[0]); setPropertiesFile(metadata.properties()); } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/ProdQuarkusApplicationManagedResourceBuilder.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/ProdQuarkusApplicationManagedResourceBuilder.java index 635e8144f..234ccd478 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/ProdQuarkusApplicationManagedResourceBuilder.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/ProdQuarkusApplicationManagedResourceBuilder.java @@ -40,12 +40,21 @@ public class ProdQuarkusApplicationManagedResourceBuilder extends ArtifactQuarku private Path artifact; private QuarkusManagedResource managedResource; + private String artifactSuffix; @Override protected Path getArtifact() { return artifact; } + protected void setArtifactSuffix(String suffix) { + if (suffix == null || suffix.isEmpty() || suffix.isBlank()) { + this.artifactSuffix = null; + } else { + this.artifactSuffix = suffix; + } + } + @Override public void init(Annotation annotation) { QuarkusApplication metadata = (QuarkusApplication) annotation; @@ -70,7 +79,7 @@ public void build() { managedResource.onPreBuild(); copyResourcesToAppFolder(); if (managedResource.needsBuildArtifact()) { - tryToReuseOrBuildArtifact(); + this.artifact = tryToReuseOrBuildArtifact(); } managedResource.onPostBuild(); @@ -90,8 +99,16 @@ protected Path getTargetFolderForLocalArtifacts() { return Paths.get(TARGET); } - private void tryToReuseOrBuildArtifact() { + private Path tryToReuseOrBuildArtifact() { Optional artifactLocation = Optional.empty(); + final Path targetFolder = getTargetFolderForLocalArtifacts(); + if (artifactSuffix != null) { + return findTargetFile(targetFolder, artifactSuffix) + .map(Path::of) + .orElseThrow(() -> new IllegalStateException(String.format("Folder %s doesn't contain '%s'", + targetFolder, + artifactSuffix))); + } if (!containsBuildProperties() && !requiresCustomBuild()) { if (QuarkusProperties.isNativePackageType(getContext())) { String nativeRunnerExpectedLocation = NATIVE_RUNNER; @@ -99,18 +116,17 @@ private void tryToReuseOrBuildArtifact() { nativeRunnerExpectedLocation += EXE; } - artifactLocation = findTargetFile(getTargetFolderForLocalArtifacts(), nativeRunnerExpectedLocation); - + artifactLocation = findTargetFile(targetFolder, nativeRunnerExpectedLocation); } else { - artifactLocation = findTargetFile(getTargetFolderForLocalArtifacts(), JVM_RUNNER) - .or(() -> findTargetFile(getTargetFolderForLocalArtifacts().resolve(QUARKUS_APP), QUARKUS_RUN)); + artifactLocation = findTargetFile(targetFolder, JVM_RUNNER) + .or(() -> findTargetFile(targetFolder.resolve(QUARKUS_APP), QUARKUS_RUN)); } } if (artifactLocation.isEmpty()) { - this.artifact = buildArtifact(); + return buildArtifact(); } else { - this.artifact = Path.of(artifactLocation.get()); + return Path.of(artifactLocation.get()); } } From 1bc994d679c33e81e3cd42ee9e6b948702c17144 Mon Sep 17 00:00:00 2001 From: Fedor Dudinskiy Date: Fri, 6 Jan 2023 15:09:22 +0100 Subject: [PATCH 2/2] Add option to use ssl with Dev Mode Allows us to work with DevMode UI via https, required for https://issues.redhat.com/browse/QUARKUS-2748 --- .../quarkus/qe/DevModeGreetingResourceIT.java | 26 +++++++++++++++++++ .../quarkus/test/bootstrap/RestService.java | 4 +++ .../services/DevModeQuarkusApplication.java | 6 +++++ ...rkusApplicationManagedResourceBuilder.java | 1 + 4 files changed, 37 insertions(+) create mode 100644 examples/https/src/test/java/io/quarkus/qe/DevModeGreetingResourceIT.java diff --git a/examples/https/src/test/java/io/quarkus/qe/DevModeGreetingResourceIT.java b/examples/https/src/test/java/io/quarkus/qe/DevModeGreetingResourceIT.java new file mode 100644 index 000000000..78aefcc38 --- /dev/null +++ b/examples/https/src/test/java/io/quarkus/qe/DevModeGreetingResourceIT.java @@ -0,0 +1,26 @@ +package io.quarkus.qe; + +import org.apache.http.HttpStatus; +import org.junit.jupiter.api.Test; + +import io.quarkus.test.bootstrap.DevModeQuarkusService; +import io.quarkus.test.scenarios.QuarkusScenario; +import io.quarkus.test.scenarios.annotations.DisabledOnNative; +import io.quarkus.test.services.DevModeQuarkusApplication; + +@QuarkusScenario +@DisabledOnNative +public class DevModeGreetingResourceIT { + @DevModeQuarkusApplication(ssl = true) + static DevModeQuarkusService app = new DevModeQuarkusService(); + + @Test + public void shouldOpenDevUi() { + app.given().get("/q/dev").then().statusCode(HttpStatus.SC_OK); + } + + @Test + public void shouldOpenHttpsDevUi() { + app.relaxedHttps().get("/q/dev").then().statusCode(HttpStatus.SC_OK); + } +} diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/RestService.java b/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/RestService.java index a08477d45..bef470d8d 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/RestService.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/RestService.java @@ -29,6 +29,10 @@ public RequestSpecification https() { .port(host.getPort()); } + public RequestSpecification relaxedHttps() { + return this.https().relaxedHTTPSValidation(); + } + public WebClient mutiny() { return mutiny(new WebClientOptions()); } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/DevModeQuarkusApplication.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/DevModeQuarkusApplication.java index 4210ca8d3..5492650cc 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/DevModeQuarkusApplication.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/DevModeQuarkusApplication.java @@ -20,4 +20,10 @@ * Enable GRPC configuration. This property will map the gPRC service to a random port. */ boolean grpc() default false; + + /** + * Enable SSL configuration. This property needs `quarkus.http.ssl.certificate.key-store-file` and + * `quarkus.http.ssl.certificate.key-store-password` to be set. + */ + boolean ssl() default false; } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java index 425b4dcd6..e74cef707 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/services/quarkus/DevModeQuarkusApplicationManagedResourceBuilder.java @@ -18,6 +18,7 @@ public void init(Annotation annotation) { initAppClasses(metadata.classes()); setPropertiesFile(metadata.properties()); setGrpcEnabled(metadata.grpc()); + setSslEnabled(metadata.ssl()); } @Override