Skip to main content

Overview

The ProductFactory class is a factory utility that creates instances of TNB products based on system properties. It uses Java’s ServiceLoader mechanism to discover and instantiate the appropriate product implementation (Camel Quarkus, Camel Spring Boot, etc.) for either local or OpenShift environments.

Class information

Package: software.tnb.product Type: Final utility class (cannot be instantiated)

Methods

create()

Creates an instance of a product based on system properties.
public static Product create()

Returns

Product
Product
The product instance matching the configured product type and deployment environment

Example

Product product = ProductFactory.create();
This method automatically determines the product type from TestConfiguration.product() and whether to create a local or OpenShift instance based on OpenshiftConfiguration.isOpenshift().

create(Class<P>)

Creates an instance of a product and returns it as the specified class type.
public static <P extends Product> P create(Class<P> clazz)

Parameters

clazz
Class<P>
required
The class type to cast the product instance to (must extend Product)

Returns

P
P extends Product
The product instance cast to the specified class type

Throws

  • IllegalArgumentException - If no product implementation is found matching the configuration

Example

// Create and cast to specific product type
LocalCamelQuarkus product = ProductFactory.create(LocalCamelQuarkus.class);

How it works

The ProductFactory uses the following selection criteria:
  1. Product type matching: Filters products where the class name contains the configured product value from TestConfiguration.product()
  2. Environment matching: Ensures the product type matches the deployment environment:
    • OpenshiftProduct implementations for OpenShift environments
    • Local product implementations for local environments
  3. ServiceLoader discovery: Uses Java’s ServiceLoader to find all available Product implementations on the classpath

Error handling

If no matching product is found, the factory throws an IllegalArgumentException with a descriptive message indicating:
  • The configured product type
  • The deployment environment (OpenShift or local)
The exception stacktrace is printed before throwing to aid debugging, as initialization errors may be swallowed by the JVM.

Usage in tests

@ExtendWith(IntegrationLifecycleManager.class)
public class MyTest {
    private Product product = ProductFactory.create();
    
    @Test
    void testIntegration() {
        App app = product.createIntegration(
            new IntegrationBuilder("my-integration")
                .fromRouteBuilder(new MyRouteBuilder())
        );
    }
}

Configuration

The factory relies on these system properties:
  • test.product: Product type identifier (e.g., “quarkus”, “springboot”)
  • test.openshift: Boolean indicating if running on OpenShift
These are typically configured via:
  • Maven profiles
  • System properties (-Dtest.product=quarkus)
  • Environment variables
  • Test configuration files

Build docs developers (and LLMs) love