[jboss-svn-commits] JBoss Common SVN: r3787 - arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Nov 25 08:47:07 EST 2009


Author: aslak
Date: 2009-11-25 08:47:07 -0500 (Wed, 25 Nov 2009)
New Revision: 3787

Added:
   arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAppenderArchiveGenerator.java
   arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java
Modified:
   arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/UserCreatedArchiveGenerator.java
Log:
ARQ-25 ArchiveGenerator that combines the user defined Deployment and all the runtime modules DeploymentAppender spi archives

Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAppenderArchiveGenerator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAppenderArchiveGenerator.java	                        (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/DeploymentAppenderArchiveGenerator.java	2009-11-25 13:47:07 UTC (rev 3787)
@@ -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.impl;
+
+import java.util.List;
+
+import org.jboss.arquillian.spi.util.DeploymentAppenders;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+
+/**
+ * DeploymentAppenderArchiveGenerator
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class DeploymentAppenderArchiveGenerator implements ArchiveGenerator
+{
+   private ArchiveGenerator generator;
+   
+   public DeploymentAppenderArchiveGenerator(ArchiveGenerator generator)
+   {
+      Validate.notNull(generator, "Generator must be specified");
+      this.generator = generator;
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.arquillian.impl.ArchiveGenerator#generateArchive(java.lang.Class)
+    */
+   @Override
+   public Archive<?> generateArchive(Class<?> testCase)
+   {
+      Validate.notNull(testCase, "TestCase must be specified");
+      List<Archive<?>> moduleArchives = DeploymentAppenders.getArchives();
+      
+      Archive<?> userArchive = generator.generateArchive(testCase);
+      
+      EnterpriseArchive fullDeployment = Archives.create("test.ear", EnterpriseArchive.class)
+                  .addModule(userArchive);
+      
+      for(Archive<?> moduleArchive : moduleArchives )
+      {
+         fullDeployment.addModule(moduleArchive);
+      }
+    
+      //fullDeployment.as(ExplodedExporter.class).exportExploded(new File("target"));
+      
+      return fullDeployment;
+   }
+}

Modified: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/UserCreatedArchiveGenerator.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/UserCreatedArchiveGenerator.java	2009-11-25 13:39:12 UTC (rev 3786)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/UserCreatedArchiveGenerator.java	2009-11-25 13:47:07 UTC (rev 3787)
@@ -20,6 +20,7 @@
 
 import org.jboss.arquillian.api.Deployment;
 import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.container.ClassContainer;
 
 /**
  * UserCreatedArchiveGenerator
@@ -33,6 +34,8 @@
    @Override
    public Archive<?> generateArchive(Class<?> testCase)
    {
+      Validate.notNull(testCase, "TestCase must be specified");
+      
       Method deploymentMethod = findDeploymentMethod(testCase);
       if(deploymentMethod == null) 
       {
@@ -40,20 +43,29 @@
       }
       try 
       {
-         return (Archive<?>)deploymentMethod.invoke(null);
+         Archive<?> archive = (Archive<?>)deploymentMethod.invoke(null);
+         // TODO: handle deployment attributes like autoAddPakcage etc..
+         if(ClassContainer.class.isInstance(archive)) 
+         {
+            ClassContainer<?> classContainer = ClassContainer.class.cast(archive);
+            classContainer.addClass(testCase);
+         }
+         
+         return archive;
       } 
       catch (Exception e) 
       {
-         throw new RuntimeException("Could not get Deploymnet", e);
+         throw new RuntimeException("Could not get Deployment", e);
       }
    }
    
-   private Method findDeploymentMethod(Class<?> testCase) {
-      
+   private Method findDeploymentMethod(Class<?> testCase) 
+   {
       Method[] methods = testCase.getMethods();
       for(Method method: methods)
       {
-         if(method.isAnnotationPresent(Deployment.class)) {
+         if(method.isAnnotationPresent(Deployment.class)) 
+         {
             return method;
          }
       }

Added: arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java
===================================================================
--- arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java	                        (rev 0)
+++ arquillian/trunk/impl-base/src/main/java/org/jboss/arquillian/impl/Validate.java	2009-11-25 13:47:07 UTC (rev 3787)
@@ -0,0 +1,63 @@
+/*
+ * 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.impl;
+
+/**
+ * Validate
+ * 
+ * Validation utility
+ *
+ * @author <a href="mailto:aslak at conduct.no">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public final class Validate
+{
+   private Validate()
+   {
+   }
+
+   /**
+    * Checks that object is not null, throws exception if it is.
+    * 
+    * @param obj The object to check
+    * @param message The exception message
+    * @throws IllegalArgumentException Thrown if obj is null 
+    */
+   public static void notNull(final Object obj, final String message) throws IllegalArgumentException
+   {
+      if (obj == null)
+      {
+         throw new IllegalArgumentException(message);
+      }
+   }
+
+   /**
+    * Checks that the specified String is not null or empty, 
+    * throws exception if it is.
+    * 
+    * @param string The object to check
+    * @param message The exception message
+    * @throws IllegalArgumentException Thrown if obj is null 
+    */
+   public static void notNullOrEmpty(final String string, final String message) throws IllegalArgumentException
+   {
+      if (string == null || string.length() == 0)
+      {
+         throw new IllegalArgumentException(message);
+      }
+   }
+}



More information about the jboss-svn-commits mailing list