[jboss-svn-commits] JBoss Common SVN: r3883 - in arquillian/trunk: testng and 11 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Dec 25 17:47:58 EST 2009


Author: aslak
Date: 2009-12-25 17:47:57 -0500 (Fri, 25 Dec 2009)
New Revision: 3883

Added:
   arquillian/trunk/testng/
   arquillian/trunk/testng/pom.xml
   arquillian/trunk/testng/src/
   arquillian/trunk/testng/src/main/
   arquillian/trunk/testng/src/main/java/
   arquillian/trunk/testng/src/main/java/org/
   arquillian/trunk/testng/src/main/java/org/jboss/
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestListener.java
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppender.java
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppenderTestCase.java
   arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java
   arquillian/trunk/testng/src/main/resources/
   arquillian/trunk/testng/src/main/resources/META-INF/
   arquillian/trunk/testng/src/main/resources/META-INF/services/
   arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender
   arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestRunner
   arquillian/trunk/testng/src/test/
   arquillian/trunk/testng/src/test/java/
   arquillian/trunk/testng/src/test/resources/
Log:
ARQ-9 Added TestNG TestRunner impl



Property changes on: arquillian/trunk/testng
___________________________________________________________________
Name: svn:ignore
   + .classpath
.project
.settings
target


Added: arquillian/trunk/testng/pom.xml
===================================================================
--- arquillian/trunk/testng/pom.xml	                        (rev 0)
+++ arquillian/trunk/testng/pom.xml	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+   <!--
+  vi:ts=2:sw=2:expandtab:
+-->
+<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/maven-v4_0_0.xsd">
+
+   <!-- Parent -->
+   <parent>
+      <groupId>org.jboss.arquillian</groupId>
+      <artifactId>arquillian-build</artifactId>
+      <version>1.0.0-SNAPSHOT</version>
+      <relativePath>../build/pom.xml</relativePath>
+   </parent>
+
+   <!-- Model Version -->
+   <modelVersion>4.0.0</modelVersion>
+
+   <!-- Artifact Configuration -->
+   <artifactId>arquillian-testng</artifactId>
+   <name>Arquillian TestRunner TestNG</name>
+   <description>TestNG Implementations for the Arquillian Project</description>
+
+
+   <!-- Properties -->
+   <properties>
+
+   </properties>
+
+   <!-- Dependencies -->
+   <dependencies>
+
+      <!-- 
+    org.jboss.arquillian
+     -->
+      <dependency>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-impl-base</artifactId>
+         <version>${project.version}</version>
+      </dependency>
+
+      <!-- 
+    org.jboss.shrinkwrap    
+     -->
+      <dependency>
+         <groupId>org.jboss.shrinkwrap</groupId>
+         <artifactId>shrinkwrap-impl-base</artifactId>
+      </dependency>
+
+      <!-- 
+    External Projects
+     -->
+      <dependency>
+         <groupId>org.testng</groupId>
+         <artifactId>testng</artifactId>
+         <scope>provided</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>ant</groupId>
+         <artifactId>ant</artifactId>
+         <version>1.6.5</version>
+      </dependency>
+
+   </dependencies>
+
+   <build>
+      <plugins>
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-jar-plugin</artifactId>
+            <executions>
+               <execution>
+                  <goals>
+                     <goal>test-jar</goal>
+                  </goals>
+               </execution>
+            </executions>
+         </plugin>
+      </plugins>
+   </build>
+</project>
+

Added: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java	                        (rev 0)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/Arquillian.java	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual 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.testng;
+
+import java.lang.reflect.Method;
+
+import org.jboss.arquillian.impl.DeployableTest;
+import org.jboss.arquillian.impl.DeployableTestBuilder;
+import org.jboss.arquillian.spi.ContainerMethodExecutor;
+import org.jboss.arquillian.spi.DeploymentException;
+import org.jboss.arquillian.spi.LifecycleException;
+import org.jboss.arquillian.spi.TestMethodExecutor;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.shrinkwrap.api.Archive;
+import org.testng.IHookCallBack;
+import org.testng.IHookable;
+import org.testng.ITestResult;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterSuite;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeSuite;
+
+/**
+ * Arquillian
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public abstract class Arquillian implements IHookable
+{
+   private static DeployableTest deployableTest = null;
+
+   private Archive<?> archive = null;
+   private ContainerMethodExecutor methodExecutor;
+   
+   @BeforeSuite
+   public void createAndStartContainer() throws LifecycleException
+   {
+      if (deployableTest == null)
+      {
+         deployableTest = DeployableTestBuilder.build(null);
+      }
+      deployableTest.getContainerController().start();
+   }
+
+   @AfterSuite
+   public void destoryAndStopContainer() throws LifecycleException
+   {
+      if (deployableTest == null)
+      {
+         return;
+      }
+      deployableTest.getContainerController().stop();
+   }
+
+   @BeforeClass
+   public void createAndDeployArtifact() throws DeploymentException
+   {
+      archive = deployableTest.generateArchive(this.getClass());
+      methodExecutor = deployableTest.getDeployer().deploy(archive);
+   }
+
+   @AfterClass
+   public void destoryAndUndeployArtifact() throws DeploymentException
+   {
+      deployableTest.getDeployer().undeploy(archive);
+   }
+
+   public void run(final IHookCallBack callback, final ITestResult testResult)
+   {
+      TestResult result = methodExecutor.invoke(new TestMethodExecutor()
+      {
+         @Override
+         public void invoke() throws Throwable
+         {
+            callback.runTestMethod(testResult);
+         }
+         
+         @Override
+         public Method getMethod()
+         {
+            return testResult.getMethod().getMethod();
+         }
+         
+         @Override
+         public Object getInstance()
+         {
+            return Arquillian.this;
+         }
+      });
+      if(result.getThrowable() != null)
+      {
+         testResult.setThrowable(result.getThrowable());
+      }
+   }
+}

Added: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestListener.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestListener.java	                        (rev 0)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestListener.java	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual 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.testng;
+
+import org.jboss.arquillian.impl.TestResultImpl;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.arquillian.spi.TestResult.Status;
+import org.testng.ITestContext;
+import org.testng.ITestListener;
+import org.testng.ITestResult;
+
+/**
+ * TestListener
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestListener implements ITestListener
+{
+
+   private ITestContext context;
+   
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onFinish(org.testng.ITestContext)
+    */
+   @Override
+   public void onFinish(ITestContext paramITestContext)
+   {
+      context = paramITestContext;
+   }
+
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onStart(org.testng.ITestContext)
+    */
+   @Override
+   public void onStart(ITestContext paramITestContext)
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onTestFailedButWithinSuccessPercentage(org.testng.ITestResult)
+    */
+   @Override
+   public void onTestFailedButWithinSuccessPercentage(ITestResult paramITestResult)
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onTestFailure(org.testng.ITestResult)
+    */
+   @Override
+   public void onTestFailure(ITestResult paramITestResult)
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onTestSkipped(org.testng.ITestResult)
+    */
+   @Override
+   public void onTestSkipped(ITestResult paramITestResult)
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onTestStart(org.testng.ITestResult)
+    */
+   @Override
+   public void onTestStart(ITestResult paramITestResult)
+   {
+   }
+
+   /* (non-Javadoc)
+    * @see org.testng.ITestListener#onTestSuccess(org.testng.ITestResult)
+    */
+   @Override
+   public void onTestSuccess(ITestResult paramITestResult)
+   {
+   }
+
+   public TestResult getTestResult() 
+   {
+      if(context.getFailedTests().size() > 0) 
+      {
+         return new TestResultImpl(
+               Status.FAILED, 
+               context.getFailedTests().getAllResults().iterator().next().getThrowable());
+      } 
+      else if(context.getSkippedTests().size() > 0)
+      {
+         return new TestResultImpl(Status.SKIPPED);
+      }
+      return new TestResultImpl(Status.PASSED); 
+   }
+}

Added: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppender.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppender.java	                        (rev 0)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppender.java	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual 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.testng;
+
+import org.jboss.arquillian.spi.DeploymentAppender;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.testng.TestNG;
+import org.testng.annotations.Test;
+import org.testng.internal.AnnotationTypeEnum;
+import org.testng.log.TextFormatter;
+import org.testng.log4testng.Logger;
+import org.testng.util.RetryAnalyzerCount;
+import org.testng.v6.TestPlan;
+import org.testng.xml.XmlSuite;
+
+import com.thoughtworks.qdox.Searcher;
+
+/**
+ * TestNGDeploymentAppender
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestNGDeploymentAppender implements DeploymentAppender
+{
+   /* (non-Javadoc)
+    * @see org.jboss.arquillian.spi.DeploymentAppender#createArchive()
+    */
+   @Override
+   public Archive<?> createArchive()
+   {
+      return Archives.create("arquillian-testng.jar", JavaArchive.class)
+               .addPackages(
+                     true, 
+                     Test.class.getPackage(),
+                     AnnotationTypeEnum.class.getPackage(),
+                     RetryAnalyzerCount.class.getPackage(),
+                     TextFormatter.class.getPackage(),
+                     Logger.class.getPackage(),
+                     TestPlan.class.getPackage(),
+                     XmlSuite.class.getPackage(),
+                     Searcher.class.getPackage(),
+                     Package.getPackage("org.jboss.arquillian.testng"))
+               .addPackage(TestNG.class.getPackage())
+               .addManifestResource(
+                     "META-INF/services/org.jboss.arquillian.spi.TestRunner",
+                     "services/org.jboss.arquillian.spi.TestRunner");
+   }
+}

Added: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppenderTestCase.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppenderTestCase.java	                        (rev 0)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGDeploymentAppenderTestCase.java	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual 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.testng;
+
+import junit.framework.Assert;
+
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Paths;
+import org.junit.Test;
+
+/**
+ * TestNGDeploymentAppenderTestCase
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestNGDeploymentAppenderTestCase
+{
+
+   @Test
+   public void shouldGenerateDependencies() throws Exception 
+   {
+      Archive<?> archive = new TestNGDeploymentAppender().createArchive();
+
+      Assert.assertTrue(
+            "Should have added TestRunner SPI",
+            archive.contains(Paths.create("/META-INF/services/org.jboss.arquillian.spi.TestRunner")));
+      
+      Assert.assertTrue(
+            "Should have added TestRunner Impl",
+            archive.contains(Paths.create("/org/jboss/arquillian/testng/TestNGTestRunner.class")));
+
+      System.out.println(archive.toString(true));      
+
+   }
+}

Added: arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java
===================================================================
--- arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java	                        (rev 0)
+++ arquillian/trunk/testng/src/main/java/org/jboss/arquillian/testng/TestNGTestRunner.java	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual 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.testng;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.jboss.arquillian.impl.DeployableTest;
+import org.jboss.arquillian.spi.TestResult;
+import org.jboss.arquillian.spi.TestRunner;
+import org.jboss.shrinkwrap.impl.base.Validate;
+import org.testng.TestNG;
+import org.testng.internal.AnnotationTypeEnum;
+import org.testng.xml.XmlClass;
+import org.testng.xml.XmlSuite;
+import org.testng.xml.XmlTest;
+
+/**
+ * TestNGTestRunner
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class TestNGTestRunner implements TestRunner
+{
+   private ExecutionMode executionMode = ExecutionMode.STANDALONE; 
+   
+   /* (non-Javadoc)
+    * @see org.jboss.arquillian.spi.TestRunner#setExecutionMode(org.jboss.arquillian.spi.TestRunner.ExecutionMode)
+    */
+   @Override
+   public void setExecutionMode(ExecutionMode executionMode)
+   {
+      Validate.notNull(executionMode, "ExecutionMode must be specified");
+      this.executionMode = executionMode;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.arquillian.spi.TestRunner#execute(java.lang.Class, java.lang.String)
+    */
+   @Override
+   public TestResult execute(Class<?> testClass, String methodName)
+   {
+      setExecutionMode();
+
+      TestListener resultListener = new TestListener();
+      
+      TestNG runner = new TestNG(false);
+      runner.setVerbose(0);
+      runner.addListener(resultListener);
+      runner.setXmlSuites(
+            Arrays.asList(createSuite(testClass, methodName)));
+      
+      runner.run();
+
+      TestResult testResult = resultListener.getTestResult(); 
+      
+      resetExecutionMode();
+      
+      return testResult;
+   }
+   
+   private XmlSuite createSuite(Class<?> className, String methodName)
+   {
+      XmlSuite suite = new XmlSuite();
+      suite.setName("Arquillian");
+      suite.setAnnotations(AnnotationTypeEnum.JDK.getName());
+
+      XmlTest test = new XmlTest(suite);
+      test.setName("Arquillian - " + className);
+      List<XmlClass> testClasses = new ArrayList<XmlClass>();
+      XmlClass testClass = new XmlClass(className);
+      testClass.getIncludedMethods().add(methodName);
+      testClasses.add(testClass);
+      test.setXmlClasses(testClasses);
+      return suite;
+   }
+
+   private void setExecutionMode() 
+   {
+      switch (executionMode)
+      {
+         case CONTAINER:
+            DeployableTest.setInContainer(true);
+            break;
+      }
+   }
+   
+   private void resetExecutionMode() 
+   {
+      switch (executionMode)
+      {
+         case CONTAINER:
+            DeployableTest.setInContainer(false);
+            break;
+      }
+   }
+}

Added: arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender
===================================================================
--- arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender	                        (rev 0)
+++ arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentAppender	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1 @@
+org.jboss.arquillian.testng.TestNGDeploymentAppender
\ No newline at end of file

Added: arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestRunner
===================================================================
--- arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestRunner	                        (rev 0)
+++ arquillian/trunk/testng/src/main/resources/META-INF/services/org.jboss.arquillian.spi.TestRunner	2009-12-25 22:47:57 UTC (rev 3883)
@@ -0,0 +1 @@
+org.jboss.arquillian.testng.TestNGTestRunner
\ No newline at end of file



More information about the jboss-svn-commits mailing list