Skip to content

Commit

Permalink
Merge pull request #24666 from glefloch/fix/15013
Browse files Browse the repository at this point in the history
Export application name and version in tests
  • Loading branch information
aloubyansky authored Apr 20, 2022
2 parents 34ac54b + 4b79122 commit 30b369c
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testOpenApiPathAccessResource() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-smallrye-openapi-deployment API"))
.body("tags.name[0]", Matchers.equalTo("test"))
.body("paths.'/resource'.get.servers[0]", Matchers.hasKey("url"))
.body("paths.'/resource'.get.security[0]", Matchers.hasKey("securityRequirement"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testOpenApiPathAccessResource() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-smallrye-openapi-deployment API"))
.body("paths", Matchers.hasKey("/foo/resource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void testOpenApiResteasyPathHttpRootDefaultPath() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-smallrye-openapi-deployment API"))
.body("paths", Matchers.hasKey("/http-root-path/resteasy-path/resource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void testOpenApiResteasyPath() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-smallrye-openapi-deployment API"))
.body("paths", Matchers.hasKey("/foo/bar/resource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testOpenApiPathAccessResource() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-smallrye-openapi-deployment API"))
.body("paths", Matchers.hasKey("/resource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void testOpenApiPathAccessResource() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-smallrye-openapi-deployment API"))
.body("paths", Matchers.hasKey("/foo/resource"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class KafkaDevServicesDevModeTestCase {
"mp.messaging.outgoing.generated-price.topic=prices\n" +
"mp.messaging.incoming.prices.connector=smallrye-kafka\n" +
"mp.messaging.incoming.prices.health-readiness-enabled=false\n" +
"mp.messaging.incoming.prices.topic=prices\n";
"mp.messaging.incoming.prices.topic=prices\n" +
"quarkus.application.name=\n";

@RegisterExtension
public static QuarkusDevModeTest test = new QuarkusDevModeTest()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private QuarkusBootstrap(Builder builder, ConfiguredClassLoading classLoadingCon
this.additionalApplicationArchives = new ArrayList<>(builder.additionalApplicationArchives);
this.excludeFromClassPath = new ArrayList<>(builder.excludeFromClassPath);
this.projectRoot = builder.projectRoot != null ? builder.projectRoot.normalize() : null;
this.buildSystemProperties = builder.buildSystemProperties;
this.buildSystemProperties = builder.buildSystemProperties != null ? builder.buildSystemProperties : new Properties();
this.mode = builder.mode;
this.offline = builder.offline;
this.test = builder.test;
Expand Down Expand Up @@ -159,7 +159,19 @@ public CuratedApplication bootstrap() throws BootstrapException {
appModelFactory.setEnableClasspathCache(true);
}
}
return new CuratedApplication(this, appModelFactory.resolveAppModel(), classLoadingConfig);
CurationResult curationResult = appModelFactory.resolveAppModel();
if (curationResult.getApplicationModel().getAppArtifact() != null) {
if (curationResult.getApplicationModel().getAppArtifact().getArtifactId() != null) {
buildSystemProperties.putIfAbsent("quarkus.application.name",
curationResult.getApplicationModel().getAppArtifact().getArtifactId());
}
if (curationResult.getApplicationModel().getAppArtifact().getVersion() != null) {
buildSystemProperties.putIfAbsent("quarkus.application.version",
curationResult.getApplicationModel().getAppArtifact().getVersion());
}
}

return new CuratedApplication(this, curationResult, classLoadingConfig);
}

public static ConfiguredClassLoading createClassLoadingConfig(PathCollection applicationRoot, Mode mode,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.acme;


import org.eclipse.microprofile.config.inject.ConfigProperty;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("/app-config")
public class ApplicationConfigResource {

@ConfigProperty(name = "quarkus.application.name")
String name;

@ConfigProperty(name = "quarkus.application.version")
String version;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return String.format("%s:%s", name, version);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.acme;

import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusTest
public class ApplicationConfigResourceTest {

@Test
public void testAppConfigEndpoint() {
given()
.when().get("/app-config")
.then()
.statusCode(200)
.body(is("application:1.0.0-SNAPSHOT"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.quarkus.gradle;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;

import org.junit.jupiter.api.Test;

public class ApplicationConfigurationTest extends QuarkusGradleWrapperTestBase {

@Test
public void shouldSuccessfullyInjectApplicationConfigInTest() throws Exception {
File projectDir = getProjectDir("basic-java-library-module");

BuildResult testResult = runGradleWrapper(projectDir, "clean", ":application:test");

assertThat(testResult.getTasks().get(":application:test")).isEqualTo(BuildResult.SUCCESS_OUTCOME);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void testOpenApiPathAccessResource() {
.then()
.header("Content-Type", "application/json;charset=UTF-8")
.body("openapi", Matchers.startsWith("3.0"))
.body("info.title", Matchers.equalTo("Generated API"))
.body("info.title", Matchers.equalTo("quarkus-integration-test-spring-web API"))
.body("paths", Matchers.hasKey("/resource"));
}
}

0 comments on commit 30b369c

Please sign in to comment.