Skip to content

Commit d174021

Browse files
Andrew Lee Rubingerdmlloyd
Andrew Lee Rubinger
authored andcommitted
[JBAS-8946] Add new Arquillian 1.0.0.Alpha5 Container/Connector in "arquillian2" subsystem, add new "testsuite2" subsystem. These to be the porting layers for moving to the unified test plan.
1 parent ca2ac17 commit d174021

File tree

27 files changed

+2049
-0
lines changed

27 files changed

+2049
-0
lines changed

arquillian2/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin/

arquillian2/common/pom.xml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<!-- Parent -->
8+
<parent>
9+
<groupId>org.jboss.as.arquillian2</groupId>
10+
<artifactId>jboss-as-arquillian2</artifactId>
11+
<version>7.0.0.Beta3-SNAPSHOT</version>
12+
<relativePath>../pom.xml</relativePath>
13+
</parent>
14+
15+
<artifactId>jboss-as-arquillian2-common</artifactId>
16+
<name>JBoss Application Server: Arquillian Container Commons</name>
17+
<description>A Common Base Implementation for the JBoss AS 7.x Container Integrations for the Arquillian Project</description>
18+
19+
<properties>
20+
21+
<!-- Versioning -->
22+
23+
</properties>
24+
25+
<packaging>jar</packaging>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.jboss.arquillian</groupId>
30+
<artifactId>arquillian-spi</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.jboss.arquillian.protocol</groupId>
34+
<artifactId>arquillian-protocol-servlet</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.jboss.arquillian.testenricher</groupId>
38+
<artifactId>arquillian-testenricher-cdi</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.jboss.arquillian.testenricher</groupId>
42+
<artifactId>arquillian-testenricher-ejb</artifactId>
43+
</dependency>
44+
<dependency>
45+
<groupId>org.jboss.arquillian.testenricher</groupId>
46+
<artifactId>arquillian-testenricher-resource</artifactId>
47+
</dependency>
48+
49+
<dependency>
50+
<groupId>org.jboss.as</groupId>
51+
<artifactId>jboss-as-controller-client</artifactId>
52+
<version>${project.version}</version>
53+
<scope>provided</scope>
54+
</dependency>
55+
</dependencies>
56+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.as.arquillian.container;
18+
19+
import java.io.ByteArrayInputStream;
20+
import java.io.InputStream;
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import java.util.concurrent.Future;
24+
import java.util.logging.Logger;
25+
26+
import javax.management.MalformedObjectNameException;
27+
import javax.management.ObjectName;
28+
29+
import org.jboss.arquillian.spi.client.container.DeployableContainer;
30+
import org.jboss.arquillian.spi.client.container.DeploymentException;
31+
import org.jboss.arquillian.spi.client.protocol.ProtocolDescription;
32+
import org.jboss.arquillian.spi.client.protocol.metadata.HTTPContext;
33+
import org.jboss.arquillian.spi.client.protocol.metadata.ProtocolMetaData;
34+
import org.jboss.arquillian.spi.client.protocol.metadata.Servlet;
35+
import org.jboss.as.controller.client.ModelControllerClient;
36+
import org.jboss.as.controller.client.helpers.standalone.DeploymentAction;
37+
import org.jboss.as.controller.client.helpers.standalone.DeploymentPlan;
38+
import org.jboss.as.controller.client.helpers.standalone.DeploymentPlanBuilder;
39+
import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentActionResult;
40+
import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentManager;
41+
import org.jboss.as.controller.client.helpers.standalone.ServerDeploymentPlanResult;
42+
import org.jboss.modules.management.ObjectProperties;
43+
import org.jboss.shrinkwrap.api.Archive;
44+
import org.jboss.shrinkwrap.api.exporter.ZipExporter;
45+
import org.jboss.shrinkwrap.descriptor.api.Descriptor;
46+
47+
/**
48+
* A JBossAS server connector
49+
*
50+
51+
* @since 17-Nov-2010
52+
*/
53+
public abstract class AbstractDeployableContainer<T extends JBossAsCommonConfiguration> implements DeployableContainer<T> {
54+
55+
protected static final ObjectName OBJECT_NAME;
56+
57+
static {
58+
try {
59+
OBJECT_NAME = new ObjectName("jboss.msc", ObjectProperties.properties(
60+
ObjectProperties.property("type", "container"), ObjectProperties.property("name", "jboss-as")));
61+
} catch (MalformedObjectNameException e) {
62+
throw new IllegalStateException(e);
63+
}
64+
}
65+
66+
private static final Logger log = Logger.getLogger(AbstractDeployableContainer.class.getName());
67+
68+
private T containerConfig;
69+
private ServerDeploymentManager deploymentManager;
70+
71+
private final Map<Object, String> registry = new HashMap<Object, String>();
72+
73+
@Override
74+
public ProtocolDescription getDefaultProtocol() {
75+
return new ProtocolDescription("Servlet 3.0");
76+
}
77+
78+
@Override
79+
public void setup(T configuration) {
80+
containerConfig = configuration;
81+
ModelControllerClient client = ModelControllerClient.Factory.create(containerConfig.getBindAddress(),
82+
containerConfig.getManagementPort());
83+
84+
deploymentManager = ServerDeploymentManager.Factory.create(client);
85+
}
86+
87+
@Override
88+
public void deploy(Descriptor descriptor) throws DeploymentException {
89+
deploy(descriptor.getDescriptorName(), descriptor, new ByteArrayInputStream(descriptor.exportAsString().getBytes()));
90+
}
91+
92+
@Override
93+
public void undeploy(Descriptor descriptor) throws DeploymentException {
94+
undeploy((Object) descriptor);
95+
}
96+
97+
@Override
98+
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
99+
String uniqueDeploymentName = deploy(archive.getName(), archive, archive.as(ZipExporter.class).exportAsInputStream());
100+
101+
return getProtocolMetaData(archive, uniqueDeploymentName);
102+
}
103+
104+
@Override
105+
public void undeploy(Archive<?> archive) throws DeploymentException {
106+
undeploy((Object) archive);
107+
}
108+
109+
// TODO: can't be done in a proper way, hack until Management API support Deployment Metadata
110+
// protected abstract ProtocolMetaData getProtocolMetaData(String uniqueDeploymentName);
111+
112+
protected ProtocolMetaData getProtocolMetaData(Archive<?> archive, String uniqueDeploymentName) {
113+
ProtocolMetaData protocol = new ProtocolMetaData().addContext(new HTTPContext(containerConfig.getBindAddress()
114+
.getHostAddress(), containerConfig.getHttpPort()).add(new Servlet("ArquillianServletRunner",
115+
getContextRootName(archive))));
116+
117+
return protocol;
118+
}
119+
120+
protected T getContainerConfiguration() {
121+
return containerConfig;
122+
}
123+
124+
private String getContextRootName(Archive<?> archive) {
125+
String archiveName = archive.getName();
126+
if (archiveName.indexOf('.') != -1) {
127+
return archiveName.substring(0, archiveName.indexOf('.'));
128+
}
129+
return archiveName;
130+
}
131+
132+
private void undeploy(Object deployment) throws DeploymentException {
133+
String runtimeName = registry.remove(deployment);
134+
if (runtimeName != null) {
135+
try {
136+
DeploymentPlanBuilder builder = deploymentManager.newDeploymentPlan().withRollback();
137+
DeploymentPlan plan = builder.undeploy(runtimeName).remove(runtimeName).build();
138+
Future<ServerDeploymentPlanResult> future = deploymentManager.execute(plan);
139+
future.get();
140+
} catch (Exception ex) {
141+
log.warning("Cannot undeploy: " + runtimeName + ":" + ex.getMessage());
142+
}
143+
}
144+
}
145+
146+
private String deploy(String deploymentName, Object deployment, InputStream content) throws DeploymentException {
147+
try {
148+
DeploymentPlanBuilder builder = deploymentManager.newDeploymentPlan().withRollback();
149+
builder = builder.add(deploymentName, content).andDeploy();
150+
DeploymentPlan plan = builder.build();
151+
DeploymentAction deployAction = builder.getLastAction();
152+
153+
return executeDeploymentPlan(plan, deployAction, deployment);
154+
155+
} catch (Exception e) {
156+
throw new DeploymentException("Could not deploy to container", e);
157+
}
158+
}
159+
160+
private String executeDeploymentPlan(DeploymentPlan plan, DeploymentAction deployAction, Object deployment)
161+
throws Exception {
162+
Future<ServerDeploymentPlanResult> future = deploymentManager.execute(plan);
163+
registry.put(deployment, deployAction.getDeploymentUnitUniqueName());
164+
ServerDeploymentPlanResult planResult = future.get();
165+
166+
ServerDeploymentActionResult actionResult = planResult.getDeploymentActionResult(deployAction.getId());
167+
if (actionResult != null) {
168+
Exception deploymentException = (Exception) actionResult.getDeploymentException();
169+
if (deploymentException != null)
170+
throw deploymentException;
171+
}
172+
return deployAction.getDeploymentUnitUniqueName();
173+
}
174+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.as.arquillian.container;
18+
19+
import org.jboss.arquillian.spi.TestEnricher;
20+
import org.jboss.arquillian.spi.client.deployment.AuxiliaryArchiveAppender;
21+
import org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher;
22+
import org.jboss.arquillian.testenricher.ejb.EJBInjectionEnricher;
23+
import org.jboss.arquillian.testenricher.resource.ResourceInjectionEnricher;
24+
import org.jboss.shrinkwrap.api.Archive;
25+
import org.jboss.shrinkwrap.api.ShrinkWrap;
26+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
27+
28+
/**
29+
* EmbeddedDeploymentAppender
30+
*
31+
* Package the required dependencies needed by the Jboss Embedded Container plugin to run in container.
32+
*
33+
* @author <a href="mailto:[email protected]">Aslak Knutsen</a>
34+
* @version $Revision: $
35+
*/
36+
public class JBossASDeploymentAppender implements AuxiliaryArchiveAppender {
37+
38+
public Archive<?> createAuxiliaryArchive() {
39+
JavaArchive archive = ShrinkWrap
40+
.create(JavaArchive.class, "arquillian-jboss-testenrichers.jar")
41+
.addPackages(true, EJBInjectionEnricher.class.getPackage(), ResourceInjectionEnricher.class.getPackage(),
42+
CDIInjectionEnricher.class.getPackage())
43+
.addAsServiceProvider(TestEnricher.class, CDIInjectionEnricher.class, EJBInjectionEnricher.class,
44+
ResourceInjectionEnricher.class);
45+
return archive;
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* JBoss, Home of Professional Open Source
3+
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
4+
* by the @authors tag. See the copyright.txt in the distribution for a
5+
* full listing of individual contributors.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.jboss.as.arquillian.container;
18+
19+
import java.net.InetAddress;
20+
import java.net.UnknownHostException;
21+
22+
import org.jboss.arquillian.spi.ConfigurationException;
23+
import org.jboss.arquillian.spi.client.container.ContainerConfiguration;
24+
25+
/**
26+
* JBossAS7 server configuration
27+
*
28+
29+
* @since 17-Nov-2010
30+
*/
31+
public class JBossAsCommonConfiguration implements ContainerConfiguration {
32+
33+
private InetAddress bindAddress;
34+
private int managementPort;
35+
private int jmxPort;
36+
private int httpPort;
37+
38+
public JBossAsCommonConfiguration() {
39+
bindAddress = getInetAddress("127.0.0.1");
40+
managementPort = 9999;
41+
jmxPort = 1090;
42+
httpPort = 8080;
43+
}
44+
45+
public InetAddress getBindAddress() {
46+
return bindAddress;
47+
}
48+
49+
public void setBindAddress(String host) {
50+
this.bindAddress = getInetAddress(host);
51+
}
52+
53+
public int getManagementPort() {
54+
return managementPort;
55+
}
56+
57+
public void setManagementPort(int managementPort) {
58+
this.managementPort = managementPort;
59+
}
60+
61+
public int getJmxPort() {
62+
return jmxPort;
63+
}
64+
65+
public void setJmxPort(int jmxPort) {
66+
this.jmxPort = jmxPort;
67+
}
68+
69+
public int getHttpPort() {
70+
return httpPort;
71+
}
72+
73+
public void setHttpPort(int httpPort) {
74+
this.httpPort = httpPort;
75+
}
76+
77+
private InetAddress getInetAddress(String name) {
78+
try {
79+
return InetAddress.getByName(name);
80+
} catch (UnknownHostException e) {
81+
throw new IllegalArgumentException("Unknown host: " + name);
82+
}
83+
}
84+
85+
@Override
86+
public void validate() throws ConfigurationException {
87+
}
88+
}

0 commit comments

Comments
 (0)