-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WFARQ=157] Add some JUnit 5 utilities for extending Arquillian and J…
…Unit 5. https://issues.redhat.com/browse/WFARA-157 Signed-off-by: James R. Perkins <jperkins@redhat.com>
- Loading branch information
Showing
24 changed files
with
1,421 additions
and
8 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
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,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. |
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,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> |
44 changes: 44 additions & 0 deletions
44
junit-api/src/main/java/org/wildfly/arquillian/junit/annotations/JBossHome.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,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 { | ||
} |
75 changes: 75 additions & 0 deletions
75
junit-api/src/main/java/org/wildfly/arquillian/junit/annotations/RequiresModule.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,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(); | ||
} |
Oops, something went wrong.