-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for specifying a custom mapper implementation for a Deplo…
- Loading branch information
Showing
5 changed files
with
127 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import org.jboss.arquillian.config.descriptor.api.ProtocolDef; | ||
import org.jboss.arquillian.container.spi.Container; | ||
import org.jboss.arquillian.container.spi.ServerKillProcessor; | ||
import org.jboss.arquillian.container.spi.client.container.ConfigurationMapper; | ||
import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration; | ||
import org.jboss.arquillian.container.spi.client.container.DeployableContainer; | ||
import org.jboss.arquillian.container.spi.client.container.LifecycleException; | ||
|
@@ -47,25 +48,25 @@ | |
* @author <a href="mailto:[email protected]">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
public class ContainerImpl implements Container { | ||
public class ContainerImpl<T extends ContainerConfiguration> implements Container<T> { | ||
@Inject | ||
private Event<ContainerEvent> event; | ||
|
||
@Inject | ||
@ContainerScoped | ||
private InstanceProducer<Container> containerProducer; | ||
private InstanceProducer<Container<T>> containerProducer; | ||
|
||
@Inject | ||
private Instance<ServiceLoader> serviceLoader; | ||
|
||
private DeployableContainer<?> deployableContainer; | ||
private DeployableContainer<T> deployableContainer; | ||
private String name; | ||
private State state = State.STOPPED; | ||
private Throwable failureCause; | ||
|
||
private ContainerDef containerConfiguration; | ||
|
||
public ContainerImpl(String name, DeployableContainer<?> deployableContainer, ContainerDef containerConfiguration) { | ||
public ContainerImpl(String name, DeployableContainer<T> deployableContainer, ContainerDef containerConfiguration) { | ||
Validate.notNull(name, "Name must be specified"); | ||
Validate.notNull(deployableContainer, "DeployableContainer must be specified"); | ||
Validate.notNull(containerConfiguration, "ConfigurationConfiguration must be specified"); | ||
|
@@ -87,7 +88,7 @@ public String getName() { | |
* @see org.jboss.arquillian.container.impl.ContainerT#getDeployableContainer() | ||
*/ | ||
@Override | ||
public DeployableContainer<?> getDeployableContainer() { | ||
public DeployableContainer<T> getDeployableContainer() { | ||
return deployableContainer; | ||
} | ||
|
||
|
@@ -103,10 +104,15 @@ public ContainerDef getContainerConfiguration() { | |
* @see org.jboss.arquillian.container.impl.ContainerT#createDeployableConfiguration() | ||
*/ | ||
@Override | ||
public ContainerConfiguration createDeployableConfiguration() throws Exception { | ||
ContainerConfiguration config = SecurityActions.newInstance( | ||
deployableContainer.getConfigurationClass(), new Class<?>[0], new Object[0]); | ||
MapObject.populate(config, containerConfiguration.getContainerProperties()); | ||
public T createDeployableConfiguration() throws Exception { | ||
Class<T> configClass = (Class<T>) deployableContainer.getConfigurationClass(); | ||
T config = SecurityActions.newInstance(configClass, new Class<?>[0], new Object[0]); | ||
ConfigurationMapper<T> mapper = deployableContainer.getConfigurationMapper(); | ||
if(mapper != null) { | ||
mapper.populateConfiguration(config, containerConfiguration); | ||
} else { | ||
MapObject.populate(config, containerConfiguration.getContainerProperties()); | ||
} | ||
config.validate(); | ||
return config; | ||
} | ||
|
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 |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
* @author <a href="mailto:[email protected]">Aslak Knutsen</a> | ||
* @version $Revision: $ | ||
*/ | ||
public interface Container { | ||
public interface Container<T extends ContainerConfiguration> { | ||
|
||
/** | ||
* @return the name | ||
|
@@ -40,7 +40,7 @@ public interface Container { | |
/** | ||
* @return the deployableContainer | ||
*/ | ||
DeployableContainer<?> getDeployableContainer(); | ||
DeployableContainer<T> getDeployableContainer(); | ||
|
||
/** | ||
* @return the containerConfiguration | ||
|
@@ -50,7 +50,7 @@ public interface Container { | |
/** | ||
* @return the configuration | ||
*/ | ||
ContainerConfiguration createDeployableConfiguration() throws Exception; | ||
T createDeployableConfiguration() throws Exception; | ||
|
||
boolean hasProtocolConfiguration(ProtocolDescription description); | ||
|
||
|
@@ -73,4 +73,4 @@ public interface Container { | |
enum State { | ||
SETUP, SETUP_FAILED, STARTED, STARTED_FAILED, STOPPED, STOPPED_FAILED, KILLED, KILLED_FAILED; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...rc/main/java/org/jboss/arquillian/container/spi/client/container/ConfigurationMapper.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,36 @@ | ||
/* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2024 Red Hat Inc. and/or its affiliates and other contributors | ||
* by the @authors tag. See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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.jboss.arquillian.container.spi.client.container; | ||
|
||
import org.jboss.arquillian.config.descriptor.api.ContainerDef; | ||
|
||
/** | ||
* An interface that {@link DeployableContainer<T>} can use to control how the mapping | ||
* from the externalized container definition, as found in an arquillian.xml file | ||
* for example, is applied to the {@link ContainerConfiguration} instances | ||
* | ||
* @param <T> the type of ContainerConfiguration | ||
*/ | ||
public interface ConfigurationMapper<T extends ContainerConfiguration> { | ||
/** | ||
* | ||
* @param containerConfiguration - the deployable container configuration instance to populate | ||
* @param definition - the container definition from the ArquillianDescriptor that | ||
* was parsed | ||
*/ | ||
void populateConfiguration(T containerConfiguration, ContainerDef definition); | ||
} |
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