Skip to content
This repository was archived by the owner on Apr 10, 2024. It is now read-only.

feat: support for quarkus using CDI #91

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,37 @@ class JUnitFabric8ClientInjectionTest {
}
```

### Quarkus Support

Quarkus is explicitly supported although it is currently limited. To use JEnvTest from Quarkus, include the following dependency:

```xml
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>jenvtest-quarkus-support</artifactId>
<version>[version]</version>
<scope>test</scope>
</dependency>
```

JEnvTest works by injecting a specific Kubernetes client in your tests that is configured to access an automatically started Kubernetes API server instance in the
background:

```java

@QuarkusTest
class QuarkusSupportTest {

@Inject
KubernetesClient client;

@Test
void testAgainstAPIServer() {
// test code using the client
}
}
```

### Support for Parallel Execution in Junit5

Parallel test execution is explicitly supported for JUnit5, in fact the project tests are running parallel.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<jackson.version>2.14.2</jackson.version>

<sonar.organization>java-operator-sdk</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
</properties>
Expand All @@ -84,6 +83,7 @@
<modules>
<module>core</module>
<module>fabric8</module>
<module>quarkus</module>
</modules>

<dependencyManagement>
Expand Down
128 changes: 128 additions & 0 deletions quarkus/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.javaoperatorsdk</groupId>
<artifactId>jenvtest-project</artifactId>
<version>0.9.1-SNAPSHOT</version>
</parent>

<artifactId>jenvtest-quarkus-support</artifactId>
<packaging>jar</packaging>
<name>JEnvTest Quarkus Support</name>

<properties>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
<quarkus.platform.version>2.16.6.Final</quarkus.platform.version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably target Quarkus 3 (which is already tagged).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK there is no officeial release yet: https://github.com/quarkusio/quarkus/releases
neother on the website, also the automatic update script updates it into CR2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final is already tagged so this is what should be used moving forward, imo.

<surefire-plugin.version>3.0.0-M7</surefire-plugin.version>
<compiler-plugin.version>3.10.1</compiler-plugin.version>
<slf4j.version>1.7.36</slf4j.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>${quarkus.platform.artifact-id}</artifactId>
<version>${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logmanager</groupId>
<artifactId>log4j2-jboss-logmanager</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.javaoperatorsdk</groupId>
<artifactId>jenvtest</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>io.smallrye</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>3.0.5</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.javaoperatorsdk.jenvtest.quarkus;

import javax.enterprise.inject.Disposes;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;

import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import io.javaoperatorsdk.jenvtest.KubeAPIServer;
import io.javaoperatorsdk.jenvtest.KubeAPIServerConfig;
import io.javaoperatorsdk.jenvtest.KubeAPIServerConfigBuilder;
import io.quarkus.arc.DefaultBean;

public class QuarkusTestConfiguration {

@Produces
@Singleton
public KubeAPIServer kubeAPIServer(KubeAPIServerConfig config) {
KubeAPIServer kubeAPIServer = new KubeAPIServer(config);
kubeAPIServer.start();

return kubeAPIServer;
}

@Produces
@Singleton
@DefaultBean
public KubeAPIServerConfig kubeAPIServerConfig() {
return new KubeAPIServerConfigBuilder().build();
}

public void stopKubeAPIServer(@Disposes KubeAPIServer kubeAPIServer) {
kubeAPIServer.stop();
}

@Produces
@Singleton
public KubernetesClient kubeApiServerClient(KubeAPIServer kubeAPIServer) {
return new KubernetesClientBuilder()
.withConfig(Config.fromKubeconfig(kubeAPIServer.getKubeConfigYaml()))
.build();
}

public void closeClient(@Disposes KubernetesClient kubernetesClient) {
kubernetesClient.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.javaoperatorsdk.jenvtest.quarkus;

import javax.inject.Inject;

import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.quarkus.test.junit.QuarkusTest;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
class QuarkusSupportTest {

@Inject
KubernetesClient client;

@Test
void setsUpJenvtestServerAndClient() {
assertThat(client.getKubernetesVersion().getGitVersion()).startsWith("v1.26");
}
}