Skip to content

Commit

Permalink
WFARQ-12 Allow extending ArquillianConfig service
Browse files Browse the repository at this point in the history
Against 2.0 branch
  • Loading branch information
arcivanov committed Mar 10, 2016
1 parent 9cc0621 commit c68945f
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public Archive<?> generateDeployment(TestDeployment testDeployment, Collection<P
try {
Collection<Archive<?>> auxArchives = testDeployment.getAuxiliaryArchives();
JavaArchive archive = generateArquillianServiceArchive(auxArchives);

for (ProtocolArchiveProcessor processor : protocolProcessors) {
processor.process(testDeployment, archive);
}

archiveHolder.setArchive(archive);
} catch (Exception ex) {
throw new IllegalStateException("Cannot generate arquillian service", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Set;

import org.jboss.arquillian.container.test.spi.util.ServiceLoader;
import org.jboss.arquillian.testenricher.msc.ServiceTargetAssociation;
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.Attachments;
Expand All @@ -41,12 +42,14 @@
*
* @author Thomas.Diesler@jboss.com
*/
class ArquillianConfig implements Service<ArquillianConfig> {
public class ArquillianConfig implements Service<ArquillianConfig> {

private static final Logger log = Logger.getLogger(ArquillianConfig.class);

static final AttachmentKey<ArquillianConfig> KEY = AttachmentKey.create(ArquillianConfig.class);

private final List<ArquillianConfigServiceCustomizer> serviceCustomizers = new ArrayList<ArquillianConfigServiceCustomizer>();

private final ArquillianService arqService;
private final DeploymentUnit depUnit;
private final ServiceName serviceName;
Expand All @@ -63,11 +66,18 @@ static ServiceName getServiceName(DeploymentUnit depUnit) {
this.depUnit = depUnit;
this.serviceName = getServiceName(depUnit);
this.testClasses.addAll(testClasses);

for(ArquillianConfigServiceCustomizer customizer : ServiceLoader.load(ArquillianConfigServiceCustomizer.class)) {
serviceCustomizers.add(customizer);
}
}

ServiceBuilder<ArquillianConfig> buildService(ServiceTarget serviceTarget, ServiceController<?> depController) {
ServiceBuilder<ArquillianConfig> builder = serviceTarget.addService(getServiceName(), this);
builder.addDependency(depController.getName());
for(ArquillianConfigServiceCustomizer customizer : serviceCustomizers) {
customizer.customizeService(this, builder, depController);
}
return builder;
}

Expand All @@ -91,6 +101,10 @@ Class<?> loadClass(String className) throws ClassNotFoundException {
Module module = depUnit.getAttachment(Attachments.MODULE);
Class<?> testClass = module.getClassLoader().loadClass(className);

for(ArquillianConfigServiceCustomizer customizer : serviceCustomizers) {
customizer.customizeLoadClass(depUnit, testClass);
}

ServiceTargetAssociation.setServiceTarget(serviceTarget);
return testClass;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2016 Red Hat, Inc.
*
* 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.as.arquillian.service;

import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;

/**
* Allows to customize ArquillianConfig service (e.g. get values injected and
* add dependencies) and to use the dependencies in test class loading.
*
* @author <a href="mailto:arcadiy@ivanov.biz">Arcadiy Ivanov</a>
* @version $Revision: $
*/
public interface ArquillianConfigServiceCustomizer {

void customizeService(ArquillianConfig arquillianConfig, ServiceBuilder<ArquillianConfig> builder,
ServiceController<?> depController);

void customizeLoadClass(DeploymentUnit depUnit, Class<?> testClass);
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public void transition(ServiceController<? extends Object> serviceController, Se
}
}
}
break;
case STARTING: {
ServiceName serviceName = serviceController.getName();
String simpleName = serviceName.getSimpleName();
Expand All @@ -125,6 +126,7 @@ public void transition(ServiceController<? extends Object> serviceController, Se
ArquillianConfigBuilder.handleParseAnnotations(depUnit);
}
}
break;
}
}
};
Expand Down

0 comments on commit c68945f

Please sign in to comment.