Package org.wildfly.testing.tools.module


package org.wildfly.testing.tools.module
Utilities for creating and managing WildFly modules programmatically during testing.

This package provides a fluent API for building custom WildFly modules, adding module dependencies, and managing module lifecycle. This is useful when tests need to provision custom modules that aren't part of the standard WildFly distribution.

Key Classes

  • ModuleBuilder - Fluent builder for creating WildFly modules
  • ModuleDescription - Represents a built module with lifecycle management
  • ModuleDependency - Represents a module dependency with optional export and services configuration
  • Modules - Utility methods for working with WildFly module paths

Example: Creating a Simple Module


 // Create a module with JAR resources
 ModuleDescription module = ModuleBuilder.of("com.example.mymodule")
         .addResourcePath("/path/to/mylib.jar")
         .addDependency("org.jboss.logging")
         .build(Path.of(System.getProperty("jboss.home"), "modules"));

 // Module is automatically written to disk
 // Clean up when done (usually in @AfterAll)
 module.close();
 

Example: Module with Dependencies and Exports


 ModuleDescription module = ModuleBuilder.of("com.example.api", "1.0")
         .addResource(ShrinkWrap.create(JavaArchive.class)
                 .addClass(MyApi.class))
         .addDependency(ModuleDependency.of("javax.api")
                 .setExport(true)
                 .setServices(ModuleDependency.ServiceType.IMPORT))
         .addDependency("org.jboss.logging")
         .build(modulePath);

 // Use in tests, then clean up
 module.close();
 

Example: Creating META-INF/services Files


 // Automatically generate META-INF/services files in the module
 ModuleDescription module = ModuleBuilder.of("com.example.plugin")
         .addResource(archive)
         .addMetaInfServices(PluginInterface.class,
                 PluginImpl1.class.getName(),
                 PluginImpl2.class.getName())
         .build(modulePath);
 

Lifecycle Management

ModuleDescription implements AutoCloseable, making it easy to clean up modules after tests:


 try (ModuleDescription module = ModuleBuilder.of("com.example.test").build(modulePath)) {
     // Run tests that use the module
 } // Module directory is automatically deleted
 

Module Paths and Immutability

The Modules utility helps manage module paths and can enforce immutability to prevent accidental modification of WildFly's core modules. Use the system property org.wildfly.testing.tools.modules.immutable.paths to mark paths as read-only.

Framework Compatibility

This package has no dependencies on JUnit or any specific testing framework. It can be used with any Java-based testing framework that needs to provision custom WildFly modules.

Author:
James R. Perkins
See Also: