Skip to content

Commit

Permalink
[AS7-1303] Add failing case showing TestNG not working in ARQ AS7; Ma…
Browse files Browse the repository at this point in the history
…ke ArquillianConfigBuilder support both JUnit and TestNG
  • Loading branch information
ALRubinger authored and n1hility committed Aug 16, 2011
1 parent d032667 commit 127b12b
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 18 deletions.
1 change: 1 addition & 0 deletions arquillian/pom.xml
Expand Up @@ -42,6 +42,7 @@
<module>container-remote</module>
<module>protocol-jmx</module>
<module>testenricher-msc</module>
<module>testng-integration</module>
<module>container-managed-domain</module>
<module>container-managed-clustering</module>
<!--
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

import org.jboss.arquillian.testenricher.msc.ServiceContainerAssociation;
import org.jboss.arquillian.testenricher.msc.ServiceTargetAssociation;
Expand All @@ -32,9 +33,6 @@
import org.jboss.as.server.deployment.AttachmentKey;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.modules.Module;
import org.jboss.msc.service.Service;
import org.jboss.msc.service.ServiceBuilder;
Expand Down Expand Up @@ -75,18 +73,11 @@ static ServiceName getServiceName(DeploymentUnit depUnit) {
return ServiceName.JBOSS.append("arquillian", "config", depUnit.getName());
}

ArquillianConfig(ArquillianService arqService, DeploymentUnit depUnit, List<AnnotationInstance> runWithList) {
ArquillianConfig(ArquillianService arqService, DeploymentUnit depUnit, Set<String> testClasses) {
this.arqService = arqService;
this.depUnit = depUnit;
this.serviceName = getServiceName(depUnit);
for (AnnotationInstance instance : runWithList) {
final AnnotationTarget target = instance.target();
if (target instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) target;
final String testClassName = classInfo.name().toString();
testClasses.add(testClassName);
}
}
this.testClasses.addAll(testClasses);
}

ServiceBuilder<ArquillianConfig> buildService(ServiceTarget serviceTarget, ServiceController<?> depController) {
Expand Down
Expand Up @@ -22,18 +22,22 @@

package org.jboss.as.arquillian.service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.annotation.CompositeIndex;
import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.logging.Logger;
import org.junit.runner.RunWith;

/**
* Uses the annotation index to check whether there is a class annotated with @RunWith.
* Uses the annotation index to check whether there is a class annotated
* with JUnit @RunWith, or extending from the TestNG Arquillian runner.
* In which case an {@link ArquillianConfig} service is created.
*
* @author Thomas.Diesler@jboss.com
Expand All @@ -42,6 +46,17 @@ public class ArquillianConfigBuilder {

private static final Logger log = Logger.getLogger("org.jboss.as.arquillian");

/*
* Note: Do not put direct class references on JUnit or TestNG here; this
* must be compatible with both without resulting in NCDFE
*
* AS7-1303
*/

private static final String CLASS_NAME_JUNIT_RUNNER = "org.junit.runner.RunWith";

private static final String CLASS_NAME_TESTNG_RUNNER = "org.jboss.arquillian.testng.Arquillian";

ArquillianConfigBuilder(DeploymentUnit deploymentUnit) {
}

Expand All @@ -53,14 +68,37 @@ static ArquillianConfig processDeployment(ArquillianService arqService, Deployme
return null;
}

final DotName runWithName = DotName.createSimple(RunWith.class.getName());
// Got JUnit?
final DotName runWithName = DotName.createSimple(CLASS_NAME_JUNIT_RUNNER);
final List<AnnotationInstance> runWithList = compositeIndex.getAnnotations(runWithName);
if (runWithList.isEmpty()) {

// Got TestNG?
final DotName testNGClassName = DotName.createSimple(CLASS_NAME_TESTNG_RUNNER);
final Set<ClassInfo> testNgTests = compositeIndex.getAllKnownSubclasses(testNGClassName);

// Get Test Class Names
final Set<String> testClasses = new HashSet<String>();
// JUnit
for (AnnotationInstance instance : runWithList) {
final AnnotationTarget target = instance.target();
if (target instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) target;
final String testClassName = classInfo.name().toString();
testClasses.add(testClassName);
}
}
// TestNG
for(final ClassInfo classInfo : testNgTests){
testClasses.add(classInfo.name().toString());
}

// No tests found
if (testClasses.isEmpty()) {
return null;
}

// FIXME: Why do we get another service started event from a deployment INSTALLED service?
ArquillianConfig arqConfig = new ArquillianConfig(arqService, depUnit, runWithList);
ArquillianConfig arqConfig = new ArquillianConfig(arqService, depUnit, testClasses);
if (arqService.getServiceContainer().getService(arqConfig.getServiceName()) != null) {
log.warnf("Arquillian config already registered: %s", arqConfig);
return null;
Expand Down
124 changes: 124 additions & 0 deletions arquillian/testng-integration/pom.xml
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ JBoss, Home of Professional Open Source.
~ Copyright 2010, Red Hat, Inc., and individual contributors
~ as indicated by the @author tags. See the copyright.txt file in the
~ distribution for a full listing of individual contributors.
~
~ This is free software; you can redistribute it and/or modify it
~ under the terms of the GNU Lesser General Public License as
~ published by the Free Software Foundation; either version 2.1 of
~ the License, or (at your option) any later version.
~
~ This software is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this software; if not, write to the Free
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian</artifactId>
<version>7.1.0.Alpha1-SNAPSHOT</version>
</parent>

<artifactId>jboss-as-arquillian-testng-integration</artifactId>
<name>JBoss Application Server: Arquillian TestNG Integration</name>
<packaging>jar</packaging>

<properties>
<jboss.home>${project.basedir}/../../build/target/jboss-as-${jboss.as.release.version}</jboss.home>
</properties>

<dependencies>

<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-spec-api</artifactId>
<type>pom</type>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<!-- Why does this not come in via arquillian-testng-container? Required. -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>2.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-test-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/jbossas</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${jboss.home}</directory>
<excludes>
<exclude>modules/</exclude>
<exclude>bundles/</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>java.util.logging.manager</name>
<value>org.jboss.logmanager.LogManager</value>
</property>
<property>
<name>jboss.home</name>
<value>${basedir}/target/jbossas</value>
</property>
<property>
<name>module.path</name>
<value>${jboss.home}/modules</value>
</property>
</systemProperties>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* 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.as.arquillian.testng;

import javax.inject.Inject;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
* Ensures that the basic startup/deployment etc facilities of the Arquillian container are working with TestNG w/ AS7. AS7-1303
*
* @author <a href="mailto:alr@jboss.org">Andrew Lee Rubinger</a>
*/
public class BasicTestNGIntegrationTestCase extends Arquillian {

@Deployment
public static JavaArchive create() {
final JavaArchive archive = ShrinkWrap.create(JavaArchive.class).addClass(GreetingService.class);
archive.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
return archive;
}

@Inject
private GreetingService service;

@Test
public void shouldBeAbleToInject() throws Exception {
Assert.assertNotNull(service);
Assert.assertEquals("Hello Earthling!", service.greet("Earthling"));
}
}
@@ -0,0 +1,30 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors
* as indicated by the @authors tag. All rights reserved.
* 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.as.arquillian.testng;

/**
* GreetingService
*
* @author <a href="mailto:aslak@redhat.com">Aslak Knutsen</a>
* @version $Revision: $
*/
public class GreetingService {
public String greet(String name) {
return "Hello " + name + "!";
}
}
10 changes: 10 additions & 0 deletions arquillian/testng-integration/src/test/resources/arquillian.xml
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<arquillian xmlns="http://jboss.org/schema/arquillian" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">target/jbossas</property>
</configuration>
</container>
</arquillian>

0 comments on commit 127b12b

Please sign in to comment.