Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WFARQ-157] Add some JUnit 5 utilities for extending Arquillian and J… #432

Merged
merged 1 commit into from
Feb 28, 2024
Merged
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
7 changes: 0 additions & 7 deletions integration-tests/protocol-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<artifactId>protocol-tests</artifactId>
<name>WildFly: Arquillian Protocol Integration Tests</name>

<properties>
<version.jakarta.ws.rs-api>3.1.0</version.jakarta.ws.rs-api>
<version.org.jboss.resteasy>6.2.7.Final</version.org.jboss.resteasy>
</properties>

<dependencies>
<!-- Test Dependencies -->
<dependency>
Expand All @@ -46,7 +41,6 @@
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<version>${version.jakarta.ws.rs-api}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -68,7 +62,6 @@
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${version.org.jboss.resteasy}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
48 changes: 48 additions & 0 deletions junit-api/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
= WildFly Arquillian JUnit 5 Utilities

This library includes some utility for running Arquillian tests on WildFly with JUnit 5.

== Annotations

=== `@WildFlyArquillian`

The `@WildFlyArquillian` annotation is a simple shorthand annotation for `@ExtendsWith(ArquillianExtension.class)`.

=== `@RequiresModule`

The `@RequiresModule` annotation can be used on a class or test method and will disable a test if the required module
is not found. There is also an option to define minimum version of a module required for the test to be enabled.

.Example
[source,java]
----
import org.junit.jupiter.api.Test;import org.wildfly.arquillian.junit.annotations.RequiresModule;@WildFlyArquillian
@RequiresModule("org.jboss.as.ejb3")
public class Ejb3Test {

@Inject
private TestEjb ejb;

@Test
public void testEjb() {
Assertions.assertNotNull(ejb);
}

@Test
@RequiresModule(value = "org.jboss.as.ejb3", minVersion = "32.0.0.Beta1",
issueRef = "https://issues.redhat.com/browse/WFLY-1", reason = "This test only works on WildFly 32 or higher")
public void ejbNewFeature() {

}
}
----

The `minVersion`, `issueRef` and `reason` are all optional. The `value`, which is the module name, is required. The
`issueRef` and `reason` are used for the reason text when the test is disabled.

=== `@JBossHome`

The `@JBossHome` annotation is a simple helper annotation for injecting a `java.lang.String`, `java.nio.file.Path` or
`java.io.File` parameter with the JBoss Home directory. First the `jboss.home` system property is checked. If not found,
the `JBOSS_HOME` environment variable is checked. Finally, the `jboss.home.dir` is checked. If neither are set a
`org.junit.jupiter.api.extension.ParameterResolutionException` is thrown.
174 changes: 174 additions & 0 deletions junit-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~
~ Copyright 2024 Red Hat, Inc., and individual contributors
~ as indicated by the @author tags.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<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.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-parent</artifactId>
<version>5.1.0.Final-SNAPSHOT</version>
</parent>

<artifactId>wildfly-arquillian-junit-api</artifactId>
<name>WildFly: Arquillian JUnit API's</name>

<properties>
<jboss.home>${project.build.directory}/server</jboss.home>
</properties>

<dependencies>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-core</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-plugin-tools</artifactId>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>jakarta.ejb</groupId>
<artifactId>jakarta.ejb-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-testkit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<jboss.home>${project.build.testOutputDirectory}/fake-modules</jboss.home>
</systemPropertyVariables>
<groups>system.property</groups>
</configuration>
</execution>
<execution>
<id>env-var</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<environmentVariables>
<JBOSS_HOME>${project.build.testOutputDirectory}/fake-modules</JBOSS_HOME>
</environmentVariables>
<groups>env.var</groups>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<jboss.home>${jboss.home}</jboss.home>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<executions>
<execution>
<id>provision-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>provision</goal>
</goals>
<configuration>
<provisioning-dir>${jboss.home}</provisioning-dir>
<feature-packs>
<feature-pack>
<location>wildfly@maven(org.jboss.universe:community-universe)#${version.org.wildfly.full}</location>
</feature-pack>
</feature-packs>
<layers>ee-core-profile-server</layers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.junit.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;
import org.wildfly.arquillian.junit.condition.JBossHomeParameterResolver;

/**
* Sets a parameter value to the path of the JBoss Home directory. The parameter can be a {@link java.nio.file.Path},
* {@link java.io.File} or {@link String}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@Inherited
@Documented
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(JBossHomeParameterResolver.class)
public @interface JBossHome {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.junit.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.extension.ExtendWith;
import org.wildfly.arquillian.junit.condition.RequiresModuleExecutionCondition;

/**
* Enables or disables a test based on whether the module exists. You can optionally check the version of the module
* to determine if the modules version is greater than the {@linkplain #minVersion() minimum version}.
*
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@Inherited
@Documented
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(RequiresModuleExecutionCondition.class)
public @interface RequiresModule {

/**
* The minimum version of the module resource.
* <p>
* Note that if more than one resource is defined, only the first resource is used to determine the version.
* </p>
*
* @return the minimum version
*/
String minVersion() default "";

/**
* A reference for the issue tracker to be reported in the response for a disabled test.
*
* @return the issue reference
*/
String issueRef() default "";

/**
* The reason message for disabled test.
*
* @return the reason message
*/
String reason() default "";

/**
* The module that is required for the test to run.
*
* @return the module name
*/
String value();
}
Loading