Skip to content

Commit

Permalink
Export application name and version in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Apr 12, 2022
1 parent 5601444 commit 2f1ec52
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 9 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 @@ -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,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,
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 2f1ec52

Please sign in to comment.