Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Export application name and version in tests
Browse files Browse the repository at this point in the history
glefloch committed Apr 13, 2022
1 parent 5601444 commit 24c2a44
Showing 12 changed files with 90 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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"))
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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()
Original file line number Diff line number Diff line change
@@ -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;
@@ -159,7 +159,20 @@ public CuratedApplication bootstrap() throws BootstrapException {
appModelFactory.setEnableClasspathCache(true);
}
}
return new CuratedApplication(this, appModelFactory.resolveAppModel(), classLoadingConfig);
CurationResult curationResult = appModelFactory.resolveAppModel();
if (curationResult.getApplicationModel().getApplicationModule() != null
&& curationResult.getApplicationModel().getApplicationModule().getId() != null) {
if (curationResult.getApplicationModel().getApplicationModule().getId().getArtifactId() != null) {
buildSystemProperties.putIfAbsent("quarkus.application.name",
curationResult.getApplicationModel().getApplicationModule().getId().getArtifactId());
}
if (curationResult.getApplicationModel().getApplicationModule().getId().getVersion() != null) {
buildSystemProperties.putIfAbsent("quarkus.application.version",
curationResult.getApplicationModel().getApplicationModule().getId().getVersion());
}
}

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

public static ConfiguredClassLoading createClassLoadingConfig(PathCollection applicationRoot, Mode mode,
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
@@ -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 24c2a44

Please sign in to comment.