Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #264 from zanata/arquillian-1.1.1
Browse files Browse the repository at this point in the history
Update arquillian to the most recent version
  • Loading branch information
seanf committed Nov 11, 2013
2 parents c088a20 + 11b3ecf commit 265b370
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 141 deletions.
7 changes: 5 additions & 2 deletions pom.xml
Expand Up @@ -50,6 +50,9 @@

<!-- controls concordion output location-->
<concordion.output.dir>${project.build.directory}/concordion</concordion.output.dir>

<!-- JBoss version for dependencies (arquillian, jboss-as-parent) -->
<jboss.as.version>7.2.0.Final</jboss.as.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -77,7 +80,7 @@
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.0.3.Final</version>
<version>1.1.1.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down Expand Up @@ -112,7 +115,7 @@
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-parent</artifactId>
<version>7.1.3.Final</version>
<version>${jboss.as.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
14 changes: 12 additions & 2 deletions zanata-war/pom.xml
Expand Up @@ -117,6 +117,8 @@
<usedDependency>com.google.protobuf:protobuf-java</usedDependency>
<!-- used for annotations -->
<usedDependency>com.google.code.findbugs:jsr305</usedDependency>
<!-- used for arquillian tests -->
<usedDependency>org.jboss.as:jboss-as-controller</usedDependency>

<!-- Grandfathered entries: -->
<!-- TODO validate or remove each of these -->
Expand Down Expand Up @@ -1633,7 +1635,7 @@
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<version>7.1.3.Final</version>
<version>${jboss.as.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -1671,11 +1673,19 @@
<artifactId>jboss-as-controller</artifactId>
<scope>test</scope>
</dependency>
<!-- Currently only needed for our override of Arquillian's
ManagementClient -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-seam2</artifactId>
<version>1.0.0.Alpha2</version>
<version>1.0.0.Beta1</version>
<exclusions>
<!-- This obsolete package duplicates some of the classes found in the newer descriptors-spi package -->
<exclusion>
Expand Down
@@ -1,13 +1,10 @@
/**
* TODO This is a forceful override of Arquillian's class with the same name.
* Remove this when the issues have been fixed in Arquillian.
* This is due to some problems while connecting via JMX to check for the health of
* the deployment and EAP 6.0.1.
* See lines: 137 and 316 and for the respective alterations.
* 141: The root node does not contain the specified attribute. Fetching the attribute from a new request may solve it.
* Hardcoding it for our tests.
* 320: Specifying the recursive parameter on some nodes ("undefined,"which is the case when reading the root node; and
* a deployment node) makes the server return an undefined response or an error.
*/
* the deployment and EAP 6.1.0.
* TO find the changes, look for the CHANGED comment keyword.
* /
/*
* JBoss, Home of Professional Open Source
* Copyright 2009, Red Hat Middleware LLC, and individual contributors
Expand All @@ -26,8 +23,23 @@
*/
package org.jboss.as.arquillian.container;

import static org.jboss.as.controller.client.helpers.ClientConstants.CONTROLLER_PROCESS_STATE_STARTING;
import static org.jboss.as.controller.client.helpers.ClientConstants.CONTROLLER_PROCESS_STATE_STOPPING;
import static org.jboss.as.controller.client.helpers.ClientConstants.DEPLOYMENT;
import static org.jboss.as.controller.client.helpers.ClientConstants.FAILURE_DESCRIPTION;
import static org.jboss.as.controller.client.helpers.ClientConstants.OP;
import static org.jboss.as.controller.client.helpers.ClientConstants.OP_ADDR;
import static org.jboss.as.controller.client.helpers.ClientConstants.OUTCOME;
import static org.jboss.as.controller.client.helpers.ClientConstants.READ_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.client.helpers.ClientConstants.READ_RESOURCE_OPERATION;
import static org.jboss.as.controller.client.helpers.ClientConstants.RECURSIVE;
import static org.jboss.as.controller.client.helpers.ClientConstants.RESULT;
import static org.jboss.as.controller.client.helpers.ClientConstants.SUBSYSTEM;
import static org.jboss.as.controller.client.helpers.ClientConstants.SUCCESS;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Set;

Expand Down Expand Up @@ -59,22 +71,9 @@
import org.jboss.arquillian.container.spi.client.protocol.metadata.JMXContext;
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet;
import org.jboss.as.controller.ControlledProcessState;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.dmr.ModelNode;

import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DEPLOYMENT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_ATTRIBUTE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_RESOURCE_OPERATION;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RECURSIVE;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM;
import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
import org.jboss.logging.Logger;

/**
* A helper class to join management related operations, like extract sub system
Expand All @@ -84,6 +83,9 @@
*/
public class ManagementClient {

private static final Logger logger = Logger
.getLogger(ManagementClient.class);

private static final String SUBDEPLOYMENT = "subdeployment";

private static final String WEB = "web";
Expand Down Expand Up @@ -137,10 +139,21 @@ public URI getWebUri() {
} catch (Exception e) {
throw new RuntimeException(e);
}
String socketBinding =
ModelNode socketBinding =
rootNode.get("subsystem").get("web").get("connector")
.get("http").get("socket-binding").asString();
webUri = getBinding("http", /* socketBinding */"http");
.get("http").get("socket-binding");
if (!socketBinding.isDefined()) {
try {
// MODIFIED:
webUri = new URI("http://localhost:8080");
// Hard code the binding if it's not present
webUri = getBinding("http", "http");
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
} else {
webUri = getBinding("http", socketBinding.asString());
}
}
return webUri;
}
Expand Down Expand Up @@ -179,17 +192,17 @@ public ProtocolMetaData getProtocolMetaData(String deploymentName) {

public boolean isServerInRunningState() {
try {
ModelNode op =
Util.getEmptyOperation(READ_ATTRIBUTE_OPERATION,
PathAddress.EMPTY_ADDRESS.toModelNode());
ModelNode op = new ModelNode();
op.get(OP).set(READ_ATTRIBUTE_OPERATION);
op.get(OP_ADDR).setEmptyList();
op.get(NAME).set("server-state");

ModelNode rsp = client.execute(op);
return SUCCESS.equals(rsp.get(OUTCOME).asString())
&& !ControlledProcessState.State.STARTING.toString()
.equals(rsp.get(RESULT).asString())
&& !ControlledProcessState.State.STOPPING.toString()
.equals(rsp.get(RESULT).asString());
&& !CONTROLLER_PROCESS_STATE_STARTING.equals(rsp
.get(RESULT).asString())
&& !CONTROLLER_PROCESS_STATE_STOPPING.equals(rsp
.get(RESULT).asString());
} catch (Throwable ignored) {
return false;
}
Expand Down Expand Up @@ -303,32 +316,21 @@ private void extractWebArchiveContexts(HTTPContext context,

private void extractWebArchiveContexts(HTTPContext context,
String deploymentName, ModelNode deploymentNode) {
/*
* if (deploymentNode.hasDefined(SUBSYSTEM)) { ModelNode subsystem =
* deploymentNode.get(SUBSYSTEM); if (subsystem.hasDefined(WEB)) {
* ModelNode webSubSystem = subsystem.get(WEB); if
* (webSubSystem.isDefined() && webSubSystem.hasDefined("context-root"))
* { final String contextName =
* webSubSystem.get("context-root").asString(); if
* (webSubSystem.hasDefined(SERVLET)) { for (final ModelNode servletNode
* : webSubSystem.get(SERVLET).asList()) { for (final String servletName
* : servletNode.keys()) { context.add(new Servlet(servletName,
* toContextName(contextName))); } } }
*//*
* This is a WebApp, it has some form of webcontext whether it has a
* Servlet or not. AS7 does not expose jsp / default servlet in mgm
* api
*//*
* context.add(new Servlet("default",
* toContextName(contextName))); } } }
*/
// CHANGED :
// Added the try block and the 4 subsequent lines and commented out
// the lines below

// if (deploymentNode.hasDefined(SUBSYSTEM)) {
// ModelNode subsystem = deploymentNode.get(SUBSYSTEM);
// if (subsystem.hasDefined(WEB)) {
// ModelNode webSubSystem = subsystem.get(WEB);
try {
ModelNode address = new ModelNode();
address.add(DEPLOYMENT).add(DEPLOYMENT, deploymentNode.get(NAME))
.add(SUBSYSTEM, WEB);
ModelNode webSubSystem = readResource(address, true);

if (webSubSystem.hasDefined("context-root")) {
if (webSubSystem.isDefined()
&& webSubSystem.hasDefined("context-root")) {
final String contextName =
webSubSystem.get("context-root").asString();
if (webSubSystem.hasDefined(SERVLET)) {
Expand All @@ -340,6 +342,11 @@ private void extractWebArchiveContexts(HTTPContext context,
}
}
}
/*
* This is a WebApp, it has some form of webcontext whether it
* has a Servlet or not. AS7 does not expose jsp / default
* servlet in mgm api
*/
context.add(new Servlet("default", toContextName(contextName)));
}
} catch (Exception e) {
Expand All @@ -364,24 +371,22 @@ private String toContextName(String deploymentName) {
// ---------------------------------------------------||
// -------------------------------------------------------------------------------------||

/**
* Additional method that allows the recursive parameter to be defined
*/
// MODIFIED:
private ModelNode readResource(ModelNode address, boolean recursive)
throws Exception {
final ModelNode operation = new ModelNode();
operation.get(OP).set(READ_RESOURCE_OPERATION);
if (recursive) {
operation.get(RECURSIVE).set(recursive);
operation.get(RECURSIVE).set("true");
}
operation.get(OP_ADDR).set(address);

return executeForResult(operation);
}

/*
* private ModelNode readResource(ModelNode address) throws Exception {
* final ModelNode operation = new ModelNode();
* ORIGINAL: private ModelNode readResource(ModelNode address) throws
* Exception { final ModelNode operation = new ModelNode();
* operation.get(OP).set(READ_RESOURCE_OPERATION);
* operation.get(RECURSIVE).set("true");
* operation.get(OP_ADDR).set(address);
Expand All @@ -399,10 +404,10 @@ private ModelNode executeForResult(final ModelNode operation)
private void checkSuccessful(final ModelNode result,
final ModelNode operation) throws UnSuccessfulOperationException {
if (!SUCCESS.equals(result.get(OUTCOME).asString())) {
/*
* throw new UnSuccessfulOperationException(result.get(
* FAILURE_DESCRIPTION).toString());
*/
logger.error("Operation " + operation
+ " did not succeed. Result was " + result);
throw new UnSuccessfulOperationException(result.get(
FAILURE_DESCRIPTION).toString());
}
}

Expand Down
Expand Up @@ -8,9 +8,12 @@
import org.jboss.arquillian.container.spi.client.container.DeployableContainer;
import org.jboss.arquillian.container.spi.client.deployment.Deployment;
import org.jboss.arquillian.container.spi.client.deployment.DeploymentScenario;
import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData;
import org.jboss.arquillian.container.spi.event.DeployDeployment;
import org.jboss.arquillian.container.spi.event.DeployManagedDeployments;
import org.jboss.arquillian.container.spi.event.DeploymentEvent;
import org.jboss.arquillian.container.spi.event.UnDeployDeployment;
import org.jboss.arquillian.container.spi.event.UnDeployManagedDeployments;
import org.jboss.arquillian.container.spi.event.container.AfterStart;
import org.jboss.arquillian.container.spi.event.container.BeforeStop;
import org.jboss.arquillian.container.test.impl.client.deployment.event.GenerateDeployment;
Expand All @@ -22,28 +25,23 @@
import org.jboss.arquillian.core.api.event.ManagerStarted;
import org.jboss.arquillian.core.spi.EventContext;
import org.jboss.arquillian.core.spi.LoadableExtension;
import org.zanata.arquillian.Seam2ExtendedConfigurationProducer;
import org.jboss.arquillian.test.spi.TestClass;
import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.arquillian.test.spi.annotation.TestScoped;
import org.jboss.arquillian.test.spi.context.ClassContext;
import org.jboss.arquillian.test.spi.event.suite.AfterClass;
import org.jboss.arquillian.test.spi.event.suite.Before;
import org.jboss.arquillian.test.spi.event.suite.BeforeClass;

/**
* Arquillian Zanata Suite Extension.
*
* Taken from: https://gist.github.com/aslakknutsen/3975179
*/
public class ArquillianSuiteExtension implements LoadableExtension {

public void register(ExtensionBuilder builder) {
builder.observer(SuiteDeployer.class).observer(
Seam2ExtendedConfigurationProducer.class);
builder.observer(SuiteDeployer.class);
}

public static class SuiteDeployer {

private Class<?> deploymentClass;

private DeploymentScenario suiteDeploymentScenario;

@Inject
Expand All @@ -61,6 +59,12 @@ public static class SuiteDeployer {
// assumption bug in AS7 extension.
private Instance<ClassContext> classContext;

private ProtocolMetaData cachedProtocolMetaData;

@TestScoped
@Inject
private InstanceProducer<ProtocolMetaData> testScopedProtocolMetaData;

public void startup(@Observes(precedence = -100) ManagerStarted event,
ArquillianDescriptor descriptor) {
deploymentClass = getDeploymentClass(descriptor);
Expand Down Expand Up @@ -103,16 +107,32 @@ public Void call() throws Exception {
});
}

public void overrideBefore(@Observes EventContext<BeforeClass> event) {
// Don't continue TestClass's BeforeClass context as normal.
// No DeploymentGeneration or Deploy will take place.
public void blockDeployManagedDeployments(
@Observes EventContext<DeployManagedDeployments> ignored) {
// We need to block DeployManagedDeployments event
}

public void storeProtocolMetaData(
@Observes ProtocolMetaData protocolMetaData) {
cachedProtocolMetaData = protocolMetaData;
}

public void resotreProtocolMetaData(
@Observes EventContext<Before> eventContext) {
testScopedProtocolMetaData.set(cachedProtocolMetaData);
eventContext.proceed();
}

public void restoreDeploymentScenario(
@Observes EventContext<BeforeClass> event) {
// Setup the Suite level scenario as if it came from the TestClass
event.proceed();
classDeploymentScenario.set(suiteDeploymentScenario);
}

public void overrideAfter(@Observes EventContext<AfterClass> event) {
// Don't continue TestClass's AfterClass context as normal.
// No UnDeploy will take place.
public void blockUnDeployManagedDeployments(
@Observes EventContext<UnDeployManagedDeployments> ignored) {
// We need to block UnDeployManagedDeployments event
}

private void executeInClassScope(Callable<Void> call) {
Expand Down

0 comments on commit 265b370

Please sign in to comment.