Skip to content

Commit

Permalink
feat: add test extension (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrejpetras authored Aug 12, 2024
1 parent eec94eb commit 3be2716
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/modules/tkit-quarkus/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
* xref:tkit-quarkus-rest.adoc[Rest Extension]
* xref:tkit-quarkus-rest-context.adoc[Rest Context Extension]
* xref:tkit-quarkus-security.adoc[Rest Security]
* xref:tkit-quarkus-security-test.adoc[Rest Security Tests]
* xref:tkit-quarkus-security-test.adoc[Rest Security Tests]
* xref:tkit-quarkus-test.adoc[Tests]
114 changes: 114 additions & 0 deletions docs/modules/tkit-quarkus/pages/includes/tkit-quarkus-test.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

:summaryTableId: tkit-quarkus-test
[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===

h|[[tkit-quarkus-test_configuration]]link:#tkit-quarkus-test_configuration[Configuration property]

h|Type
h|Default

a| [[tkit-quarkus-test_tkit-test-integration-test-enabled]]`link:#tkit-quarkus-test_tkit-test-integration-test-enabled[tkit.test.integration-test-enabled]`


[.description]
--
Disable or enabled integration test flag

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++TKIT_TEST_INTEGRATION_TEST_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++TKIT_TEST_INTEGRATION_TEST_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`false`


a| [[tkit-quarkus-test_tkit-test-ci-enabled]]`link:#tkit-quarkus-test_tkit-test-ci-enabled[tkit.test.ci.enabled]`


[.description]
--
Disable or enabled for ci pipeline

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++TKIT_TEST_CI_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++TKIT_TEST_CI_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[tkit-quarkus-test_tkit-test-ci-env-name]]`link:#tkit-quarkus-test_tkit-test-ci-env-name[tkit.test.ci.env-name]`


[.description]
--
The name of environment variable to check if we are running in the pipe.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++TKIT_TEST_CI_ENV_NAME+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++TKIT_TEST_CI_ENV_NAME+++`
endif::add-copy-button-to-env-var[]
--|string
|`GITLAB_CI`


a| [[tkit-quarkus-test_tkit-test-rest-assured-enabled]]`link:#tkit-quarkus-test_tkit-test-rest-assured-enabled[tkit.test.rest-assured.enabled]`


[.description]
--
Disable or enabled rest-assured config.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++TKIT_TEST_REST_ASSURED_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++TKIT_TEST_REST_ASSURED_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[tkit-quarkus-test_tkit-test-rest-assured-overwrite-uri-enabled]]`link:#tkit-quarkus-test_tkit-test-rest-assured-overwrite-uri-enabled[tkit.test.rest-assured.overwrite-uri.enabled]`


[.description]
--
Disable or enabled URI overwrite

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++TKIT_TEST_REST_ASSURED_OVERWRITE_URI_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++TKIT_TEST_REST_ASSURED_OVERWRITE_URI_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[tkit-quarkus-test_tkit-test-rest-assured-overwrite-uri-uri]]`link:#tkit-quarkus-test_tkit-test-rest-assured-overwrite-uri-uri[tkit.test.rest-assured.overwrite-uri.uri]`


[.description]
--
Overwrite the RestAssured URI with a new value.

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++TKIT_TEST_REST_ASSURED_OVERWRITE_URI_URI+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++TKIT_TEST_REST_ASSURED_OVERWRITE_URI_URI+++`
endif::add-copy-button-to-env-var[]
--|string
|`http://docker`

|===
52 changes: 52 additions & 0 deletions docs/modules/tkit-quarkus/pages/tkit-quarkus-test.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
== tkit-quarkus-security-test

include::./includes/attributes.adoc[]

Enhanced test configuration

=== Installation

If you want to use this extension, you need to add the `org.tkit.quarkus.lib:tkit-quarkus-test` extension first to your build file.

For instance, with Maven, add the following dependency to your POM file:

[source,xml,subs=attributes+]
----
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-test</artifactId>
<version>{project-version}</version>
<scope>test</scope>
</dependency>
----

=== Usage

==== Rest-Assured URI overwrite

To enabled URI overwrite for integration test add `tkit.test.integration-test-enabled` system property to the `maven-failsafe-plugin` plugin.

[source,xml,subs=attributes+]
----
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<tkit.test.integration-test-enabled>true</tkit.test.integration-test-enabled>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
----

=== Configuration

include::includes/tkit-quarkus-test.adoc[leveloffset=+1, opts=optional]
6 changes: 6 additions & 0 deletions docs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<artifactId>tkit-quarkus-test-db-import-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-test</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -88,6 +93,7 @@
<include>tkit-quarkus-rest-context.adoc</include>
<include>tkit-quarkus-security.adoc</include>
<include>tkit-quarkus-security-test.adoc</include>
<include>tkit-quarkus-test.adoc</include>
</includes>
<filtering>false</filtering>
</resource>
Expand Down
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<module>test-db-import</module>
<module>security</module>
<module>security-test</module>
<module>test</module>
</modules>
<dependencies>
<dependency>
Expand Down
50 changes: 50 additions & 0 deletions extensions/test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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>org.tkit.quarkus.lib</groupId>
<artifactId>tkit-quarkus-extensions-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>tkit-quarkus-test</artifactId>
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.tkit.quarkus.test;

import io.quarkus.runtime.annotations.ConfigDocFilename;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.quarkus.runtime.annotations.StaticInitSafe;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;
import io.smallrye.config.WithName;

@StaticInitSafe
@ConfigDocFilename("tkit-quarkus-test.adoc")
@ConfigMapping(prefix = "tkit.test")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface TestConfig {

/**
* Disable or enabled integration test flag
*/
@WithName("integration-test-enabled")
@WithDefault("false")
boolean integrationTestEnabled();

/**
* CI pipe configuration.
*/
@WithName("ci")
CiConfig ciConfig();

/**
* CI pipe configuration.
*/
interface CiConfig {

/**
* Disable or enabled for ci pipeline
*/
@WithName("enabled")
@WithDefault("true")
boolean enabled();

/**
* The name of environment variable to check if we are running in the pipe.
*/
@WithName("env-name")
@WithDefault("GITLAB_CI")
String envName();

}

/**
* Rest assured configuration.
*/
@WithName("rest-assured")
RestAssuredConfig restAssuredConfig();

/**
* Rest assured configuration.
*/
interface RestAssuredConfig {

/**
* Disable or enabled rest-assured config.
*/
@WithName("enabled")
@WithDefault("true")
boolean enabled();

/**
* Rest assured overwrite URI configuration.
*/
@WithName("overwrite-uri")
RestAssuredOverwriteUriConfig uriOverwrite();

}

/**
* Rest assured overwrite URI configuration.
*/
interface RestAssuredOverwriteUriConfig {
/**
* Disable or enabled URI overwrite
*/
@WithName("enabled")
@WithDefault("true")
boolean enabled();

/**
* Overwrite the RestAssured URI with a new value.
*/
@WithName("uri")
@WithDefault("http://docker")
String uri();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.tkit.quarkus.test;

import io.smallrye.config.SmallRyeConfigBuilder;

public final class TestConfigUtil {

private final static TestConfig TEST_CONFIG;

static {
TEST_CONFIG = new SmallRyeConfigBuilder()
.addDefaultSources()
.withMapping(TestConfig.class)
.build()
.getConfigMapping(TestConfig.class);
}

static public TestConfig config() {
return TEST_CONFIG;
}
}
Loading

0 comments on commit 3be2716

Please sign in to comment.