[webbeans-commits] Webbeans SVN: r1975 - in test-harness/trunk: jboss and 14 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Mar 13 11:59:36 EDT 2009


Author: pete.muir at jboss.org
Date: 2009-03-13 11:59:36 -0400 (Fri, 13 Mar 2009)
New Revision: 1975

Added:
   test-harness/trunk/jboss/
   test-harness/trunk/jboss/pom.xml
   test-harness/trunk/jboss/src/
   test-harness/trunk/jboss/src/main/
   test-harness/trunk/jboss/src/main/java/
   test-harness/trunk/jboss/src/main/java/org/
   test-harness/trunk/jboss/src/main/java/org/jboss/
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/AbstractContainersImpl.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/ProfileServiceContainersImpl.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/DeploymentProperties.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterable.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterator.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/ResourceLoadingException.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/SimpleResourceLoader.java
   test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/Strings.java
   test-harness/trunk/jboss/src/main/resources/
   test-harness/trunk/jboss/src/main/resources/META-INF/
   test-harness/trunk/jboss/src/main/resources/META-INF/web-beans-tck.properties
   test-harness/trunk/jboss/src/main/resources/log4j.xml
   test-harness/trunk/jboss/src/test/
   test-harness/trunk/jboss/src/test/debug-resources/
   test-harness/trunk/jboss/src/test/debug-resources/META-INF/
   test-harness/trunk/jboss/src/test/debug-resources/META-INF/web-beans-tck.properties
   test-harness/trunk/jboss/src/test/java/
   test-harness/trunk/jboss/src/test/resources/
Modified:
   test-harness/trunk/pom.xml
Log:
add jboss-as-5 deployment

Added: test-harness/trunk/jboss/pom.xml
===================================================================
--- test-harness/trunk/jboss/pom.xml	                        (rev 0)
+++ test-harness/trunk/jboss/pom.xml	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,64 @@
+<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>
+      <artifactId>jboss-test-harness-parent</artifactId>
+      <groupId>org.jboss.test-harness</groupId>
+      <version>1.0.0-SNAPSHOT</version>
+   </parent>
+   <modelVersion>4.0.0</modelVersion>
+   <groupId>org.jboss.test-harness</groupId>
+   <artifactId>jboss-test-harness-jboss-as-5</artifactId>
+   <name>JBoss Test Harness deployment for JBoss AS 5</name>
+   <description>Implements the JBoss Test Harness deployment SPI for JBoss AS 5</description>
+
+   <dependencies>
+
+      <dependency>
+         <groupId>org.jboss.test-harness</groupId>
+         <artifactId>jboss-test-harness-api</artifactId>
+      </dependency>
+
+      <!--      <dependency>-->
+      <!--         <groupId>org.jboss.naming</groupId>-->
+      <!--         <artifactId>jnp-client</artifactId>-->
+      <!--         <scope>runtime</scope>-->
+      <!--      </dependency>-->
+      <!--      -->
+      <!--      <dependency>-->
+      <!--         <groupId>org.jboss.aspects</groupId>-->
+      <!--         <artifactId>jboss-security-aspects</artifactId>-->
+      <!--         <scope>runtime</scope>-->
+      <!--      </dependency>-->
+      <!--      -->
+      <!--      <dependency>-->
+      <!--         <groupId>org.jboss.aspects</groupId>-->
+      <!--         <artifactId>jboss-remoting-aspects</artifactId>-->
+      <!--         <scope>runtime</scope>-->
+      <!--      </dependency>-->
+      <!--      -->
+      <!--      <dependency>-->
+      <!--         <groupId>oswego-concurrent</groupId>-->
+      <!--         <artifactId>concurrent</artifactId>-->
+      <!--         <scope>runtime</scope>-->
+      <!--      </dependency>-->
+<!---->
+      <dependency>
+         <groupId>org.jboss.integration</groupId>
+         <artifactId>jboss-profileservice-spi</artifactId>
+      </dependency>
+
+      <dependency>
+         <groupId>org.jboss.jbossas</groupId>
+         <artifactId>jboss-as-client</artifactId>
+         <type>pom</type>
+         <scope>runtime</scope>
+      </dependency>
+
+      <dependency>
+         <groupId>log4j</groupId>
+         <artifactId>log4j</artifactId>
+      </dependency>
+
+   </dependencies>
+
+</project>

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/AbstractContainersImpl.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/AbstractContainersImpl.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/AbstractContainersImpl.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,288 @@
+package org.jboss.testharness.integration.jbossas;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.log4j.Logger;
+import org.jboss.testharness.api.Configurable;
+import org.jboss.testharness.api.Configuration;
+import org.jboss.testharness.integration.jbossas.util.DeploymentProperties;
+import org.jboss.testharness.spi.Containers;
+
+/**
+ *
+ * @author jeffgenender
+ * @author Pete Muir
+ *
+ */
+public abstract class AbstractContainersImpl implements Configurable, Containers
+{
+
+   public static String JAVA_OPTS = " -ea";
+
+   public static final String JBOSS_HOME_PROPERTY_NAME = "jboss.home";
+   public static final String JAVA_OPTS_PROPERTY_NAME = "java.opts";
+   public static final String JBOSS_AS_DIR_PROPERTY_NAME = "jboss-as.dir";
+   public static final String JBOSS_BOOT_TIMEOUT_PROPERTY_NAME = "jboss.boot.timeout";
+   public static final String FORCE_RESTART_PROPERTY_NAME = "jboss.force.restart";
+   public static final String MAX_DEPLOYMENTS_PROPERTY_NAME = "jboss.deployments.restart";
+   public static final String SHUTDOWN_DELAY_PROPERTY_NAME = "jboss.shutdown.delay";
+   public static final String JBOSS_BIND_ADDRESS_PROPERTY_NAME = "jboss.bind.address";
+
+   private static Logger log = Logger.getLogger(AbstractContainersImpl.class);
+
+   private final DeploymentProperties properties;
+
+   private Configuration configuration;
+   protected String jbossHome;
+   private String jbossHttpUrl;
+   private boolean jbossWasStarted;
+   private long bootTimeout;
+   private String javaOpts;
+
+   private boolean forceRestart;
+
+   protected int maxDeployments;
+
+   private int jbossShutdownDelay;
+
+   private String jbossBindAddress;
+
+   public AbstractContainersImpl()
+   {
+      this.properties = new DeploymentProperties();
+   }
+
+   protected static void copy(InputStream inputStream, File file) throws IOException
+   {
+      OutputStream os = new FileOutputStream(file);
+      try
+      {
+         byte[] buf = new byte[1024];
+         int i = 0;
+         while ((i = inputStream.read(buf)) != -1)
+         {
+             os.write(buf, 0, i);
+         }
+     }
+     finally
+     {
+         os.close();
+     }
+   }
+
+   public void setConfiguration(Configuration configuration)
+   {
+      this.configuration = configuration;
+   }
+
+   protected boolean isJBossUp()
+   {
+      // Check that JBoss is up!
+      try
+      {
+         URLConnection connection = new URL(jbossHttpUrl).openConnection();
+         if (!(connection instanceof HttpURLConnection))
+         {
+            throw new IllegalStateException("Not an http connection! " + connection);
+         }
+         HttpURLConnection httpConnection = (HttpURLConnection) connection;
+         httpConnection.connect();
+         if (httpConnection.getResponseCode() != HttpURLConnection.HTTP_OK)
+         {
+            return false;
+         }
+      }
+      catch (Exception e)
+      {
+         return false;
+      }
+      log.info("Successfully connected to JBoss AS at " + jbossHttpUrl);
+      return true;
+   }
+
+   public void setup() throws IOException
+   {
+      String jbossAsPath = properties.getStringValue(JBOSS_AS_DIR_PROPERTY_NAME, "../jboss-as", false);
+      if (jbossAsPath != null)
+      {
+         File jbossAsDir = new File(jbossAsPath);
+         if (jbossAsDir.isDirectory())
+         {
+            File buildProperties = new File(jbossAsDir, "build.properties");
+            if (buildProperties.exists())
+            {
+               loadProperties(buildProperties);
+            }
+            File localBuildProperties = new File(jbossAsDir, "local.build.properties");
+            if (localBuildProperties.exists())
+            {
+               loadProperties(localBuildProperties);
+            }
+         }
+      }
+      jbossHome = properties.getStringValue(JBOSS_HOME_PROPERTY_NAME, null, true);
+      jbossBindAddress = properties.getStringValue(JBOSS_BIND_ADDRESS_PROPERTY_NAME, "localhost", false);
+      configuration.setHost(jbossBindAddress + ":8080");
+      this.jbossHttpUrl = "http://" + configuration.getHost() + "/";
+      javaOpts = properties.getStringValue(JAVA_OPTS_PROPERTY_NAME, "", false);
+      javaOpts = javaOpts + JAVA_OPTS;
+      File jbossHomeFile = new File(jbossHome);
+      jbossHome = jbossHomeFile.getPath();
+      log.info("Using JBoss instance in " + jbossHome + " at URL " + jbossHttpUrl);
+      this.bootTimeout = properties.getLongValue(JBOSS_BOOT_TIMEOUT_PROPERTY_NAME, 240000, false);
+      this.forceRestart = properties.getBooleanValue(FORCE_RESTART_PROPERTY_NAME, false, false);
+      this.maxDeployments = properties.getIntValue(MAX_DEPLOYMENTS_PROPERTY_NAME, 25, false);
+      this.jbossShutdownDelay = properties.getIntValue(SHUTDOWN_DELAY_PROPERTY_NAME, 15000, false); 
+      restartJboss();
+   }
+   
+   protected void restartJboss() throws IOException
+   {
+      if (forceRestart)
+      {
+         if (isJBossUp())
+         {
+            log.info("Shutting down JBoss instance as in force-restart mode");
+            shutDownJBoss();
+            try
+            {
+               Thread.sleep(jbossShutdownDelay);
+            }
+            catch (InterruptedException e)
+            {
+               Thread.currentThread().interrupt();
+            }
+         }
+      }
+      if (!isJBossUp())
+      {
+         jbossWasStarted = true;
+         launch("run", "--host=" + jbossBindAddress);
+         log.info("Starting JBoss instance");
+         // Wait for JBoss to come up
+         long timeoutTime = System.currentTimeMillis() + bootTimeout;
+         boolean interrupted = false;
+         while (timeoutTime > System.currentTimeMillis())
+         {
+            if (isJBossUp())
+            {
+               log.info("Started JBoss instance");
+               return;
+            }
+            try
+            {
+               Thread.sleep(200);
+            }
+            catch (InterruptedException e)
+            {
+               interrupted = true;
+            }
+         }
+         if (interrupted)
+         {
+            Thread.currentThread().interrupt();
+         }
+         // If we got this far something went wrong
+         log.warn("Unable to connect to JBoss instance after " + bootTimeout + "ms, giving up!");
+         launch("shutdown", "-S");
+         throw new IllegalStateException("Error connecting to JBoss instance");
+      }
+   }
+
+   protected void loadProperties(File file) throws IOException
+   {
+	   InputStream is = new FileInputStream(file);
+	   try
+	   {
+			System.getProperties().load(is);
+	   }
+	   finally
+	   {
+		   is.close();
+	   }
+   }
+
+   public String getJbossHome()
+   {
+      return jbossHome;
+   }
+
+   public void cleanup() throws IOException
+   {
+      if (jbossWasStarted)
+      {
+         log.info("Shutting down JBoss instance");
+         shutDownJBoss();
+      }
+   }
+
+   private void shutDownJBoss() throws IOException
+   {
+      launch("shutdown", "-S");
+      log.info("Shut down JBoss AS");
+   }
+
+   private void launch(String scriptFileName, String params) throws IOException
+   {
+      String osName = System.getProperty("os.name");
+      Runtime runtime = Runtime.getRuntime();
+
+      Process p = null;
+      if (osName.startsWith("Windows"))
+      {
+          String command[] = {
+                "cmd.exe",
+                "/C",
+                "set JAVA_OPTS=" + javaOpts + " & cd /D " + jbossHome + "\\bin & " + scriptFileName + ".bat " + params
+          };
+          p = runtime.exec(command);
+      }
+      else
+      {
+          String command[] = {
+                "sh",
+                "-c",
+                "cd " + jbossHome + "/bin;JAVA_OPTS=\"" + javaOpts + "\" ./" + scriptFileName + ".sh " + params
+                };
+          p = runtime.exec(command);
+      }
+      dump(p.getErrorStream());
+      dump(p.getInputStream());
+   }
+
+   protected void dump(final InputStream is)
+   {
+      new Thread(new Runnable()
+      {
+          public void run()
+          {
+             try
+             {
+                DataOutputStream out = new DataOutputStream(new FileOutputStream(configuration.getOutputDirectory() + File.separator + "jboss.log"));
+                int c;
+                while((c = is.read()) != -1)
+                {
+                   out.writeByte(c);
+                }
+                is.close();
+                out.close();
+             }
+             catch(IOException e)
+             {
+                System.err.println("Error Writing/Reading Streams.");
+             }
+          }
+      }).start();
+   }
+
+
+}
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/ProfileServiceContainersImpl.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/ProfileServiceContainersImpl.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/ProfileServiceContainersImpl.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,219 @@
+package org.jboss.testharness.integration.jbossas;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+
+import javax.naming.InitialContext;
+
+import org.apache.log4j.Logger;
+import org.jboss.deployers.client.spi.IncompleteDeploymentException;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
+import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
+import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.testharness.api.DeploymentException;
+import org.jboss.virtual.VFS;
+
+public class ProfileServiceContainersImpl extends AbstractContainersImpl
+{
+
+   private Logger log = Logger.getLogger(ProfileServiceContainersImpl.class);
+
+   private final List<String> failedUndeployments;
+
+   private DeploymentManager deploymentManager;
+   private final File tmpdir;
+   private int deploymentCounter = 0;
+
+
+   public ProfileServiceContainersImpl() throws Exception
+   {
+      tmpdir = new File(System.getProperty("java.io.tmpdir"), "org.jboss.webbeans.tck.integration.jbossas");
+      tmpdir.mkdir();
+      tmpdir.deleteOnExit();
+      this.failedUndeployments = new ArrayList<String>();
+   }
+
+
+   @Override
+   public void setup() throws IOException
+   {
+      super.setup();
+      try
+      {
+		 initDeploymentManager();
+	  }
+      catch (Exception e)
+	  {
+		 IOException ioe = new IOException();
+		 ioe.initCause(e);
+	     throw ioe;
+	  }
+   }
+
+   public void deploy(InputStream archiveStream, String name) throws DeploymentException, IOException
+   {
+      if (deploymentManager == null)
+      {
+         throw new IllegalStateException("setup() has not been called!");
+      }
+      Exception failure = null;
+      try
+      {
+         File archive = new File(tmpdir, name);
+         archive.deleteOnExit();
+         copy(archiveStream, archive);
+         DeploymentProgress distribute = deploymentManager.distribute(name, DeploymentPhase.APPLICATION, archive.toURI().toURL(), true);
+         distribute.run();
+         DeploymentProgress progress = deploymentManager.start(DeploymentPhase.APPLICATION, name);
+         progress.run();
+         DeploymentStatus status = progress.getDeploymentStatus();
+         if (status.isFailed())
+         {
+            failure = status.getFailure();
+            doUndeploy(name);
+         }
+      }
+      catch (Exception e)
+      {
+		   IOException ioe = new IOException();
+		   ioe.initCause(e);
+	      throw ioe;
+      }
+      if (failure != null)
+      {
+         if (failure.getCause() instanceof IncompleteDeploymentException)
+         {
+            IncompleteDeploymentException incompleteDeploymentException = (IncompleteDeploymentException) failure.getCause();
+            for (Entry<String, Throwable> entry : incompleteDeploymentException.getIncompleteDeployments().getContextsInError().entrySet())
+            {
+               if (entry.getKey().endsWith(name + "/_WebBeansBootstrap"))
+               {
+                  throw new DeploymentException(entry.getValue());
+               }
+            }
+         }
+         throw new DeploymentException(failure);
+      }
+   }
+
+   private void doUndeploy(String name) throws IOException
+   {
+      try
+      {
+         DeploymentProgress stopProgress = deploymentManager.stop(DeploymentPhase.APPLICATION, name);
+         stopProgress.run();
+
+         DeploymentProgress undeployProgress = deploymentManager.undeploy(DeploymentPhase.APPLICATION, name);
+         undeployProgress.run();
+         if (undeployProgress.getDeploymentStatus().isFailed())
+         {
+          failedUndeployments.add(name);
+         }
+         else
+         {
+            deploymentCounter++;
+         }
+      }
+      catch (Exception e)
+      {
+         IOException ioe = new IOException();
+         ioe.initCause(e);
+         throw ioe;
+      }
+   }
+   
+   public void undeploy(String name) throws IOException
+   {
+      try
+      {
+         doUndeploy(name);         
+      }
+      finally
+      {
+         if (deploymentCounter >= maxDeployments)
+         {
+            deploymentCounter = 0;
+            // Let everything stablise
+            removeFailedUnDeployments();
+            try
+            {
+               Thread.sleep(5000);
+            }
+            catch (InterruptedException e)
+            {
+               Thread.currentThread().interrupt();
+            }
+            restartJboss();
+            try
+            {
+               initDeploymentManager();
+            }
+            catch (Exception e) 
+            {
+               IOException ioe = new IOException();
+               ioe.initCause(e);
+               throw ioe;
+            }
+         }
+      }
+   }
+
+   /**
+    * Obtain the Deployment Manager
+    * @throws Exception
+    */
+   protected void initDeploymentManager() throws Exception
+   {
+      String profileName = "default";
+      InitialContext ctx = new InitialContext();
+      ProfileService ps = (ProfileService) ctx.lookup("ProfileService");
+      deploymentManager = ps.getDeploymentManager();
+      ProfileKey defaultKey = new ProfileKey(profileName);
+      deploymentManager.loadProfile(defaultKey, false);
+      // Init the VFS to setup the vfs* protocol handlers
+      VFS.init();
+   }
+
+   @Override
+   public void cleanup() throws IOException
+   {
+     removeFailedUnDeployments();
+	  super.cleanup();
+   }
+   
+   private void removeFailedUnDeployments() throws IOException
+   {
+      List<String> remainingDeployments = new ArrayList<String>();
+      for (String name : failedUndeployments)
+      {
+         try
+         {
+            DeploymentProgress undeployProgress = deploymentManager.undeploy(DeploymentPhase.APPLICATION, name);
+             undeployProgress.run();
+             if (undeployProgress.getDeploymentStatus().isFailed())
+             {
+               remainingDeployments.add(name);
+             }
+         }
+         catch (Exception e)
+         {
+           IOException ioe = new IOException();
+           ioe.initCause(e);
+            throw ioe;
+         }
+       }
+      if (remainingDeployments.size() > 0)
+      {
+         //log.error("Failed to undeploy these artifacts: " + remainingDeployments);
+      }
+      failedUndeployments.clear();
+   }
+
+}

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/DeploymentProperties.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/DeploymentProperties.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/DeploymentProperties.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,233 @@
+package org.jboss.testharness.integration.jbossas.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Utility class to load deployment properties
+ * 
+ * @author Pete Muir
+ */
+public class DeploymentProperties
+{
+   // The resource bundle used to control Web Beans RI deployment
+   public static final String RESOURCE_BUNDLE = "META-INF/web-beans-tck.properties";
+   
+   private static final Logger log = Logger.getLogger(DeploymentProperties.class);
+   
+   // The class to work from
+   private SimpleResourceLoader resourceLoader;
+
+   /**
+    * Constructor
+    * 
+    * @param classLoader The classloader to work on
+    */
+   public DeploymentProperties()
+   {
+      this.resourceLoader = new SimpleResourceLoader();
+   }
+
+   /**
+    * Get a list of possible values for a given key.
+    * 
+    * First, System properties are tried, followed by the specified resource
+    * bundle (first in classpath only).
+    * 
+    * @param key The key to search for
+    * @return A list of possible values. An empty list is returned if there are
+    *         no matches.
+    */
+   public List<String> getPropertyValues(String key)
+   {
+      List<String> values = new ArrayList<String>();
+      addPropertiesFromSystem(key, values);
+      addPropertiesFromResourceBundle(key, values);
+      return values;
+   }
+
+   /**
+    * Adds matches from system properties
+    * 
+    * @param key The key to match
+    * @param values The currently found values
+    */
+   private void addPropertiesFromSystem(String key, List<String> values)
+   {
+      addProperty(key, System.getProperty(key), values);
+   }
+
+   /**
+    * Adds matches from detected resource bundles
+    * 
+    * @param key The key to match
+    * @param values The currently found values
+    */
+   private void addPropertiesFromResourceBundle(String key, List<String> values)
+   {
+      try
+      {
+         for (URL url : resourceLoader.getResources(RESOURCE_BUNDLE))
+         {
+            Properties properties = new Properties();
+            InputStream propertyStream = url.openStream();
+            try
+            {
+               properties.load(propertyStream);
+               addProperty(key, properties.getProperty(key), values);
+            }
+            finally
+            {
+               if (propertyStream != null)
+               {
+                  propertyStream.close();
+               }
+            }
+         }
+      }
+      catch (IOException e)
+      {
+         // No - op, file is optional
+      }
+   }
+
+   /**
+    * Add the property to the set of properties only if it hasn't already been
+    * added
+    * 
+    * @param key The key searched for
+    * @param value The value of the property
+    * @param values The currently found values
+    */
+   private void addProperty(String key, String value, List<String> values)
+   {
+      if (value != null)
+      {
+         values.add(value);
+      }
+
+   }
+   
+   /**
+    * Gets the possible implementation class for a given property for which the
+    * values are classanames
+    * 
+    * @param deploymentProperties The deployment properties object to use
+    * @param resourceLoader The resource laoder to use to attempt
+    * @param propertyName The name of the property to load
+    * @return A set of classes specified
+    */
+   @SuppressWarnings("unchecked")
+   public <T> Set<Class<T>> getClasses(String propertyName, Class<T> expectedType)
+   {
+      Set<Class<T>> classes = new HashSet<Class<T>>();
+      for (String className : getPropertyValues(propertyName))
+      {
+         try
+         {
+            classes.add((Class<T>) resourceLoader.classForName(className));
+         }
+         catch (ResourceLoadingException e)
+         {
+            //log.debug("Unable to load class " + className + " for property " + propertyName, e);
+         }
+      }
+      return classes;
+   }
+   
+   public <T> Class<T> getClassValue(String propertyName, Class<T> expectedType, boolean required)
+   {
+      Set<Class<T>> classes = getClasses(propertyName, expectedType);
+      if (classes.size() == 0)
+      {
+         if (required)
+         {
+            throw new IllegalArgumentException("Cannot find any implementations of " + expectedType.getSimpleName() + ", check that " + propertyName + " is specified");
+         }
+         else
+         {
+            return null;
+         }
+      }
+      else if (classes.size() > 1)
+      {
+         throw new IllegalArgumentException("More than one implementation of " + expectedType.getSimpleName() + " specified by " + propertyName + ", not sure which one to use!");
+      }
+      else
+      {
+         return classes.iterator().next(); 
+      }
+   }
+   
+   public <T> T getInstanceValue(String propertyName, Class<T> expectedType, boolean required)
+   {
+      Class<T> clazz = getClassValue(propertyName, expectedType, required);
+      if (clazz != null)
+      {
+         try
+         {
+            return clazz.newInstance();
+         }
+         catch (InstantiationException e)
+         {
+            throw new IllegalStateException("Error instantiating " + clazz + " specified by " + propertyName, e);
+         }
+         catch (IllegalAccessException e)
+         {
+            throw new IllegalStateException("Error instantiating " + clazz + " specified by " + propertyName, e);
+         }
+      }
+      else
+      {
+         return null;
+      }
+   }
+   
+   public boolean getBooleanValue(String propertyName, boolean _default, boolean required)
+   {
+      return Boolean.valueOf(getStringValue(propertyName, _default ? "true" : "false", required));
+   }
+   
+   public int getIntValue(String propertyName, int _default, boolean required)
+   {
+      return Integer.valueOf(getStringValue(propertyName, Integer.toString(_default), required)).intValue();
+   }
+   
+   public long getLongValue(String propertyName, long _default, boolean required)
+   {
+      return Long.valueOf(getStringValue(propertyName, Long.toString(_default), required)).longValue();
+   }
+   
+   public String getStringValue(String propertyName, String _default, boolean required)
+   {
+      List<String> values = getPropertyValues(propertyName);
+      if (values.size() == 0)
+      {
+         if (required)
+         {
+            throw new IllegalArgumentException("Cannot find required property " + propertyName + ", check that it is specified");
+         }
+         else
+         {
+            return _default;
+         }
+      }
+      else if (values.size() > 1)
+      {
+         throw new IllegalArgumentException("More than one value given for " + propertyName + ", not sure which one to use!");
+      }
+      else
+      {
+         return values.iterator().next();
+      }
+   }
+
+}
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterable.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterable.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterable.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,37 @@
+package org.jboss.testharness.integration.jbossas.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An Enumeration -> Iteratble adaptor
+ *  
+ * @author Pete Muir
+ * @see org.jboss.webbeans.util.EnumerationIterator
+ */
+class EnumerationIterable<T> implements Iterable<T>
+{
+   // The enumeration-iteartor
+   private EnumerationIterator<T> iterator;
+   
+   /**
+    * Constructor
+    * 
+    * @param enumeration The enumeration
+    */
+   public EnumerationIterable(Enumeration<T> enumeration)
+   {
+      this.iterator = new EnumerationIterator<T>(enumeration);
+   }
+   
+   /**
+    * Gets an iterator
+    * 
+    * @return The iterator
+    */
+   public Iterator<T> iterator()
+   {
+      return iterator;
+   }
+   
+}
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterator.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterator.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/EnumerationIterator.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,55 @@
+package org.jboss.testharness.integration.jbossas.util;
+
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * An enumeration -> iterator adapter
+ *  
+ * @author Pete Muir
+ */
+ at SuppressWarnings("unchecked")
+class EnumerationIterator<T> implements Iterator<T>
+{
+   // The enumeration
+   private Enumeration e;
+
+   /**
+    * Constructor
+    * 
+    * @param e The enumeration
+    */
+   public EnumerationIterator(Enumeration e)
+   {
+      this.e = e;
+   }
+
+   /**
+    * Indicates if there are more items to iterate
+    * 
+    * @return True if more, false otherwise
+    */
+   public boolean hasNext()
+   {
+      return e.hasMoreElements();
+   }
+
+   /**
+    * Gets the next item
+    * 
+    * @return The next items
+    */
+   public T next()
+   {
+      return (T) e.nextElement();
+   }
+
+   /**
+    * Removes an item. Not supported
+    */
+   public void remove()
+   {
+      throw new UnsupportedOperationException();
+   }
+   
+}
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/ResourceLoadingException.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/ResourceLoadingException.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/ResourceLoadingException.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,53 @@
+package org.jboss.testharness.integration.jbossas.util;
+
+
+/**
+ * Exception thrown when errors occur while loading resource
+ * 
+ * @author Pete Muir
+ *
+ */
+class ResourceLoadingException extends RuntimeException
+{
+   private static final long serialVersionUID = 1L;
+
+   /**
+    * Constructor
+    */
+   public ResourceLoadingException()
+   {
+      super();
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param message The message
+    * @param throwable The exception
+    */
+   public ResourceLoadingException(String message, Throwable throwable)
+   {
+      super(message, throwable);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param message The message
+    */
+   public ResourceLoadingException(String message)
+   {
+      super(message);
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param throwable The exception
+    */
+   public ResourceLoadingException(Throwable throwable)
+   {
+      super(throwable);
+   }
+   
+}
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/SimpleResourceLoader.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/SimpleResourceLoader.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/SimpleResourceLoader.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,43 @@
+package org.jboss.testharness.integration.jbossas.util;
+
+import java.io.IOException;
+import java.net.URL;
+
+class SimpleResourceLoader
+{
+   
+   public Class<?> classForName(String name)
+   {
+      
+      try
+      {
+         return Class.forName(name);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new ResourceLoadingException(e);
+      }
+      catch (NoClassDefFoundError e)
+      {
+         throw new ResourceLoadingException(e);
+      }
+   }
+   
+   public URL getResource(String name)
+   {
+      return getClass().getResource(name);
+   }
+   
+   public Iterable<URL> getResources(String name)
+   {
+      try
+      {
+         return new EnumerationIterable<URL>(getClass().getClassLoader().getResources(name));
+      }
+      catch (IOException e)
+      {
+         throw new ResourceLoadingException(e);
+      }
+   }
+   
+}
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/Strings.java
===================================================================
--- test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/Strings.java	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/java/org/jboss/testharness/integration/jbossas/util/Strings.java	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,30 @@
+package org.jboss.testharness.integration.jbossas.util;
+
+import java.util.StringTokenizer;
+
+public class Strings
+{
+   static String[] split(String strings, String delims)
+   {
+      if (strings == null)
+      {
+         return new String[0];
+      }
+      else
+      {
+         StringTokenizer tokens = new StringTokenizer(strings, delims);
+         String[] result = new String[tokens.countTokens()];
+         int i = 0;
+         while (tokens.hasMoreTokens())
+         {
+            result[i++] = tokens.nextToken();
+         }
+         return result;
+      }
+   }
+   
+   public static boolean isEmpty(String string)
+   {
+      return string == null || string.length() == 0;
+   }
+}

Added: test-harness/trunk/jboss/src/main/resources/META-INF/web-beans-tck.properties
===================================================================
--- test-harness/trunk/jboss/src/main/resources/META-INF/web-beans-tck.properties	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/resources/META-INF/web-beans-tck.properties	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,3 @@
+org.jboss.testharness.spi.Containers=org.jboss.testharness.integration.jbossas.ProfileServiceContainersImpl
+org.jboss.testharness.connectDelay=1500
+org.jboss.testharness.connectRetries=8
\ No newline at end of file

Added: test-harness/trunk/jboss/src/main/resources/log4j.xml
===================================================================
--- test-harness/trunk/jboss/src/main/resources/log4j.xml	                        (rev 0)
+++ test-harness/trunk/jboss/src/main/resources/log4j.xml	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+        <param name="Target" value="System.out"/>
+        <layout class="org.apache.log4j.PatternLayout">
+            <!-- The default pattern: Date Priority [Category] Message\n -->
+            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{6}] %m%n"/>
+        </layout>
+        <filter class="org.apache.log4j.varia.StringMatchFilter">
+        	<param name="AcceptOnMatch" value="false" />
+        	<param name="StringToMatch" value="Failure while notifying an observer of event [a]" />
+        </filter>
+    </appender>
+
+    <!-- ############### Embedded EJB3 #################  -->
+    <category name="org.jboss">
+        <priority value="ERROR"/>
+    </category>
+    
+    <category name="org.jboss.test">
+        <priority value="ERROR"/>
+    </category>
+    
+    <category name="com.arjuna">
+        <priority value="ERROR"/>
+    </category>
+
+    <!-- ############### Hibernate logging ################# -->
+
+    <category name="org.hibernate">
+        <priority value="ERROR"/>
+    </category>
+
+    <!--
+    <category name="org.hibernate.SQL">
+        <priority value="TRACE"/>
+    </category>
+
+    <category name="org.hibernate.type">
+        <priority value="TRACE"/>
+    </category>
+
+    <category name="org.hibernate.loader">
+        <priority value="TRACE"/>
+    </category>
+    <category name="org.hibernate.cache">
+        <priority value="TRACE"/>
+    </category>
+    -->
+
+    <!-- ############### Web Beans logging ################### -->
+
+    <category name="org.jboss.webbeans">
+        <priority value="WARN"/>
+    </category>
+    
+    <category name="org.jboss.webbeans.tck">
+        <priority value="INFO"/>
+    </category>
+    
+    <category name="org.jboss.jsr299">
+        <priority value="INFO"/>
+    </category>
+    
+    <root>
+        <priority value="INFO"/>
+        <appender-ref ref="CONSOLE"/>
+    </root>
+
+</log4j:configuration>

Added: test-harness/trunk/jboss/src/test/debug-resources/META-INF/web-beans-tck.properties
===================================================================
--- test-harness/trunk/jboss/src/test/debug-resources/META-INF/web-beans-tck.properties	                        (rev 0)
+++ test-harness/trunk/jboss/src/test/debug-resources/META-INF/web-beans-tck.properties	2009-03-13 15:59:36 UTC (rev 1975)
@@ -0,0 +1,7 @@
+# Configuration for running incontainer tests from your IDE
+# Alter the path webbeans accordingly (relative from the tck/impl dir)
+org.jboss.testharness.standalone=false
+jboss-as.dir=../../webbeans/jboss-as
+jboss.force.restart=false
+org.jboss.testharness.libraryDirectory=../../webbeans/jboss-tck-runner/target/dependency/lib
+org.jboss.testharness.runIntegrationTests=true
\ No newline at end of file

Modified: test-harness/trunk/pom.xml
===================================================================
--- test-harness/trunk/pom.xml	2009-03-13 15:22:05 UTC (rev 1974)
+++ test-harness/trunk/pom.xml	2009-03-13 15:59:36 UTC (rev 1975)
@@ -43,6 +43,7 @@
       <module>api</module>
       <module>impl</module>
       <module>tests</module>
+      <module>jboss</module>
    </modules>
 
    <dependencyManagement>
@@ -78,7 +79,45 @@
             <artifactId>servlet-api</artifactId>
             <version>2.5</version>
          </dependency>
+         
+<!--         <dependency>-->
+<!--            <groupId>org.jboss.naming</groupId>-->
+<!--            <artifactId>jnp-client</artifactId>-->
+<!--            <version>5.0.1.GA</version>-->
+<!--         </dependency>-->
+<!--         -->
+<!--         <dependency>-->
+<!--            <groupId>org.jboss.aspects</groupId>-->
+<!--            <artifactId>jboss-security-aspects</artifactId>-->
+<!--            <version>1.0.0.GA</version>-->
+<!--         </dependency>-->
+<!--         -->
+<!--         <dependency>-->
+<!--            <groupId>org.jboss.aspects</groupId>-->
+<!--            <artifactId>jboss-remoting-aspects</artifactId>-->
+<!--            <version>1.0.1.GA</version>-->
+<!--         </dependency>-->
+<!--   -->
+<!--         -->
+<!--         <dependency>-->
+<!--            <groupId>oswego-concurrent</groupId>-->
+<!--            <artifactId>concurrent</artifactId>-->
+<!--            <version>1.3.4-jboss-update1</version>-->
+<!--         </dependency>-->
 
+         <dependency>
+            <groupId>org.jboss.integration</groupId>
+            <artifactId>jboss-profileservice-spi</artifactId>
+            <version>5.0.3.GA</version>
+         </dependency>
+         
+         <dependency>
+            <groupId>org.jboss.jbossas</groupId>
+            <artifactId>jboss-as-client</artifactId>
+            <version>5.0.1.GA</version>
+            <type>pom</type>
+         </dependency>
+
       </dependencies>
    </dependencyManagement>
 




More information about the weld-commits mailing list