Skip to content

8. Advanced Quarkus Modes

Troitskii Georgii edited this page Jun 26, 2023 · 1 revision

Quarkus Dev Mode

The test framework supports bare metal testing of DEV mode Quarkus testing:

@QuarkusScenario
public class DevModeGreetingResourceIT {
    @DevModeQuarkusApplication
    static DevModeQuarkusService app = new DevModeQuarkusService();
}

The application will start on DEV mode and will have enabled all the live coding features.

This feature includes a new DevModeQuarkusService service with the following functionality:

  • enableContinuousTesting - to enable continuous testing
app.enableContinuousTesting();

Internally, the framework will load the DEV UI and enable the continuous testing by clicking on the HTML element.

  • modifyFile - to modify a Java source or resources file:
app.modifyFile("src/main/java/io/quarkus/qe/GreetingResource.java",content -> content.replace("victor", "manuel"));
  • copyFile - to copy a Java source or resources file from one source to a destination. Note that the framework will overwrite the destination file if it exists:
app.copyFile("src/test/resources/jose.properties", "src/main/resources/application.properties");

Quarkus Remote Dev Mode

The test framework supports the Remote DEV mode in Quarkus for baremetal, OpenShift and Kubernetes. Basically, we can deploy a Quarkus application in Remote DEV and after applying changes in the source code, these changes will be automatically deployed in the running application:

@QuarkusScenario
public class RemoteDevGreetingResourceIT {

    static final String VICTOR_NAME = "victor";

    static final String HELLO_IN_ENGLISH = "Hello";
    static final String HELLO_IN_SPANISH = "Hola";

    @RemoteDevModeQuarkusApplication
    static DevModeQuarkusService app = new DevModeQuarkusService();

    @Test
    public void shouldUpdateResourcesAndSources() {
        // Should say first Victor (the default name)
        app.given().get("/greeting").then().statusCode(HttpStatus.SC_OK).body(is(HELLO_IN_ENGLISH + ", I'm " + VICTOR_NAME));

        // Modify default name to manuel
        app.modifyFile("src/main/java/io/quarkus/qe/GreetingResource.java",
                content -> content.replace(HELLO_IN_ENGLISH, HELLO_IN_SPANISH));

        // Now, the app should say Manuel
        AwaitilityUtils.untilAsserted(
                () -> app.given().get("/greeting").then().statusCode(HttpStatus.SC_OK)
                        .body(is(HELLO_IN_SPANISH + ", I'm " + VICTOR_NAME)));
    }
}

Quarkus CLI

The Quarkus Test Framework supports the usage of the Quarkus CLI tool:

@QuarkusScenario
public class QuarkusCliClientIT {

    @Inject
    static QuarkusCliClient cliClient;

    @Test
    public void shouldVersionMatchQuarkusVersion() {
        String cliVersion = cliClient.getVersion();
        assertEquals("Client Version " + QuarkusProperties.getVersion(), cliVersion);
    }

    @Test
    public void shouldCreateApplicationOnJvm() {
        // Create application
        QuarkusCliRestService app = cliClient.createApplication("app");

        // Should build on Jvm
        QuarkusCliClient.Result result = app.buildOnJvm();
        assertTrue(result.isSuccessful(), "The application didn't build on JVM. Output: " + result.getOutput());

        // Start using DEV mode
        app.start();
        app.given().get().then().statusCode(HttpStatus.SC_OK);
    }
}

Current features:

  • run - run any command
  • createApplication - create a service at target/<APP NAME>
  • buildOnJvm - build the service in JVM mode
  • buildOnNative - build the service in Native mode
  • runOnDev - run the service on DEV mode (it's the same as using QuarkusCliRestService.start)
  • getInstalledExtensions - get the installed extensions
  • installExtension - install a concrete Quarkus extension
  • removeExtension - remove a concrete Quarkus extension

The framework will not install the Quarkus CLI tool, so before running these scenarios, it needs to be installed it beforehand. The default command name is quarkus, but it can be changed using the property ts.quarkus.cli.cmd. For example:

mvn clean verify -Dts.quarkus.cli.cmd="java -jar quarkus-cli.jar"

The above command will use directly the binary from Quarkus upstream build.

Helm

The framework supports testing the Quarkus Helm extension functionality. See the extension documentation.

Running helm and helmfile CLI is possible:

@QuarkusScenario
public class QuarkusHelmFileClientIT {

    private static Path helmfilesFolder;

    @Inject
    static QuarkusHelmFileClient helmFileClient;

    @BeforeAll
    public static void tearUp() {
        helmfilesFolder = Paths.get("src", "test", "resources", "helmfiles").toAbsolutePath();
    }

    @Test
    public void verifyHelmFileInjection() {
        QuarkusHelmFileClient.Result helmCmdResult = helmFileClient.run(helmfilesFolder.toAbsolutePath(), "-version");
        assertTrue(
                helmCmdResult.isSuccessful(),
                String.format("Command %s fails", helmCmdResult.getCommandExecuted()));
        assertFalse(
                helmCmdResult.getOutput().isEmpty(),
                "Unexpected helm version");
    }
}

The CLI tools, helm and helmfile, must be installed in the environment. For installation instructions, see:

Quarkus Test Framework expects the Helm / Helmfile tool to be available in CLI under the name helm / helmfile, aliases are not supported.

Clone this wiki locally