-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for generating and running a sample Quarkus app
- Loading branch information
1 parent
8be6b0d
commit ee3e3f4
Showing
4 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,5 +12,6 @@ | |
|
||
<modules> | ||
<module>platform-generator</module> | ||
<module>sample-app</module> | ||
</modules> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-platform-bom-it-parent</artifactId> | ||
<version>0.0.114-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>quarkus-platform-sample-app-test</artifactId> | ||
<name>Quarkus - Platform BOM Tools - IT - Sample Application Generator</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-bootstrap-app-model</artifactId> | ||
<version>${quarkus.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.logging</groupId> | ||
<artifactId>jboss-logging</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.logmanager</groupId> | ||
<artifactId>jboss-logmanager</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire-plugin.version}</version> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager> | ||
<maven.home>${maven.home}</maven.home> | ||
<project.version>${project.version}</project.version> | ||
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id> | ||
<quarkus.platform.version>${quarkus.version}</quarkus.platform.version> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
151 changes: 151 additions & 0 deletions
151
...-tests/sample-app/src/test/java/io/quarkus/platform/test/SampleProjectGenerationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package io.quarkus.platform.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import io.quarkus.bootstrap.util.IoUtils; | ||
import io.quarkus.bootstrap.util.PropertyUtils; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.concurrent.TimeUnit; | ||
import org.jboss.logging.Logger; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* This test generates, builds and tests a sample Quarkus application (unit and integration tests). | ||
*/ | ||
public class SampleProjectGenerationTest { | ||
|
||
private static final Logger log = Logger.getLogger(SampleProjectGenerationTest.class); | ||
|
||
private static final String SAMPLE_APP = "sample-app"; | ||
private static final String GENERATE_APP_TIMEOUT = "sample-app.generate-timeout"; | ||
private static final String BUILD_APP_TIMEOUT = "sample-app.build-timeout"; | ||
|
||
@Test | ||
public void testSampleProjectGeneration() throws Exception { | ||
final Path projectDir = generateSampleAppWithMaven(); | ||
buildApp(projectDir); | ||
} | ||
|
||
private static void buildApp(Path projectDir) throws IOException { | ||
|
||
final Path cliLog = projectDir.resolve("build.log"); | ||
final Path cliErrors = projectDir.resolve("build-errors.log"); | ||
final long startTime = System.currentTimeMillis(); | ||
Process process = new ProcessBuilder() | ||
.directory(projectDir.toFile()) | ||
.command("./mvnw", "verify", "-DskipITs=false") | ||
.redirectOutput(cliLog.toFile()) | ||
.redirectError(cliErrors.toFile()) | ||
.start(); | ||
log.info("Building the application with '" + process.info().commandLine().orElse("<command not available>") + "'"); | ||
try { | ||
if (!process.waitFor(getBuildAppTimeout(), TimeUnit.SECONDS)) { | ||
try { | ||
process.destroy(); | ||
} catch (Exception e) { | ||
log.error("Failed to destroy the process", e); | ||
} | ||
fail("The process has exceeded the time out limit of " + getBuildAppTimeout() + " seconds"); | ||
} | ||
} catch (InterruptedException e) { | ||
log.error("Interrupted waiting for the process to complete", e); | ||
} | ||
process = process.onExit().join(); | ||
log.infof("Done in %.1f seconds", ((double) (System.currentTimeMillis() - startTime)) / 1000); | ||
|
||
if (process.exitValue() != 0) { | ||
var message = Files.readString(cliErrors); | ||
if (message.isEmpty()) { | ||
fail(Files.readString(cliLog)); | ||
} | ||
fail(Files.readString(cliErrors)); | ||
} | ||
} | ||
|
||
private static String getMvnPath() { | ||
var mavenHome = System.getProperty("maven.home"); | ||
if (mavenHome == null) { | ||
return "mvn"; | ||
} | ||
return Path.of(mavenHome).resolve("bin").resolve( | ||
PropertyUtils.isWindows() ? "mvn.bat" : "mvn").toString(); | ||
} | ||
|
||
private static Path generateSampleAppWithMaven() throws IOException { | ||
final String quarkusPlatformGroupId = getRequiredProperty("quarkus.platform.group-id"); | ||
final String quarkusPlatformVersion = getRequiredProperty("quarkus.platform.version"); | ||
|
||
final Path workDir = Path.of("").normalize().toAbsolutePath().resolve("target").resolve("sample-app"); | ||
IoUtils.recursiveDelete(workDir); | ||
Files.createDirectories(workDir); | ||
final Path cliLog = workDir.resolve("cli.log"); | ||
final Path cliErrors = workDir.resolve("cli-errors.log"); | ||
final long startTime = System.currentTimeMillis(); | ||
Process process = new ProcessBuilder() | ||
.directory(workDir.toFile()) | ||
.command(getMvnPath(), | ||
quarkusPlatformGroupId + ":quarkus-maven-plugin:" + quarkusPlatformVersion + ":create", | ||
"-DplatformGroupId=" + quarkusPlatformGroupId, | ||
"-DplatformVersion=" + quarkusPlatformVersion, | ||
"-DprojectGroupId=org.acme", | ||
"-DprojectArtifactId=" + SAMPLE_APP, | ||
"-DprojectVersion=1.0-SNAPSHOT", | ||
"-DquarkusRegistryClient=false") | ||
.redirectOutput(cliLog.toFile()) | ||
.redirectError(cliErrors.toFile()) | ||
.start(); | ||
log.info("Generating application with '" + process.info().commandLine().orElse("<command not available>") + "'"); | ||
try { | ||
if (!process.waitFor(getGenerateAppTimeout(), TimeUnit.SECONDS)) { | ||
try { | ||
process.destroy(); | ||
} catch (Exception e) { | ||
log.error("Failed to destroy the process", e); | ||
} | ||
fail("The process has exceeded the time out limit of " + getGenerateAppTimeout() + " seconds"); | ||
} | ||
} catch (InterruptedException e) { | ||
log.error("Interrupted waiting for the process to complete", e); | ||
} | ||
process = process.onExit().join(); | ||
log.infof("Done in %.1f seconds", ((double) (System.currentTimeMillis() - startTime)) / 1000); | ||
|
||
if (process.exitValue() != 0) { | ||
var message = Files.readString(cliErrors); | ||
if (message.isEmpty()) { | ||
fail(Files.readString(cliLog)); | ||
} | ||
fail(Files.readString(cliErrors)); | ||
} | ||
var projectDir = workDir.resolve(SAMPLE_APP); | ||
assertThat(projectDir).exists(); | ||
return projectDir; | ||
} | ||
|
||
private static String getRequiredProperty(String name) { | ||
var value = System.getProperty(name); | ||
if (value == null) { | ||
fail("Required property " + name + " is not set"); | ||
} | ||
return value; | ||
} | ||
|
||
private static long getBuildAppTimeout() { | ||
var propValue = System.getProperty(BUILD_APP_TIMEOUT); | ||
if (propValue == null) { | ||
return 20; | ||
} | ||
return Long.parseLong(propValue); | ||
} | ||
|
||
private static long getGenerateAppTimeout() { | ||
var propValue = System.getProperty(GENERATE_APP_TIMEOUT); | ||
if (propValue == null) { | ||
return 3; | ||
} | ||
return Long.parseLong(propValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters