arquillian / arquillian-core

Arquillian provides a component model for integration tests, which includes dependency injection and container life cycle management. Instead of managing a runtime in your test, Arquillian brings your test to the runtime.
http://arquillian.org
Apache License 2.0
366 stars 196 forks source link

Add support for externalizing the mapping from the ArquillianDescriptor container def to the DeployableContainer ContainerConfiguration instance #552

Closed starksm64 closed 1 week ago

starksm64 commented 2 weeks ago
Issue Overview

I have created a prototype json based ArquillianDescriptor implementation using the shrinkwrap DescriptorImporter SPI, but there is a limitation on where it can be used because of this org.jboss.arquillian.container.impl.ContainerImpl method:

    @Override
    public ContainerConfiguration createDeployableConfiguration() throws Exception {
        ContainerConfiguration config = SecurityActions.newInstance(
            deployableContainer.getConfigurationClass(), new Class<?>[0], new Object[0]);
        MapObject.populate(config, containerConfiguration.getContainerProperties()); // This line needs to be externalized
        config.validate();
        return config;
    }

The containerConfiguration instance variable is a org.jboss.arquillian.config.descriptor.api.ContainerDef that results from the parse of the arquillian.xml descriptor by default. If one has overriden the parser to use a different format, the call to get the ContainerDef#getContainerProperties() becomes limiting on the types one can pass from the parsed ArquillianDescriptor to the org.jboss.arquillian.container.spi.client.container.ContainerConfiguration implementation a container provides.

Expected Behaviour

One should be able to provide a mapper from the ContainerDef and the ContainerConfiguration to allow for richer types in configurations.

There needs to be an interface that is provided by the org.jboss.arquillian.container.spi.client.container.DeployableContainer

public interface DeployableContainer<T extends ContainerConfiguration> {
    // ControllableContainer
    Class<T> getConfigurationClass();

    default ConfigurationMapper<T> getConfigurationMapper() {
       // Return the old behavior ...
    }

where ConfigurationMapper is a new interface:

package org.jboss.arquillian.container.spi.client.container;

public interface ConfigurationMapper<T extends ContainerConfiguration> {
    void populate(T config, ContainerDef containerDef);
}
Current Behaviour

Only scalar types and strings are supported

starksm64 commented 2 weeks ago

This would be useful even with the current aquillian.xml parser because you can override how the string to object mapping is performed.