[jboss-osgi-commits] JBoss-OSGI SVN: r90195 - in projects/jboss-osgi/trunk/husky: harness/src/main/java/org/jboss/osgi/husky/internal and 1 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Mon Jun 15 09:10:49 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-06-15 09:10:49 -0400 (Mon, 15 Jun 2009)
New Revision: 90195

Added:
   projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/MultipleMethodsTestCase.java
Modified:
   projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/BridgeFactory.java
   projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/Response.java
   projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java
   projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/ContextTestCase.java
Log:
Add support for multiple test methods

Modified: projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/BridgeFactory.java
===================================================================
--- projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/BridgeFactory.java	2009-06-15 12:10:16 UTC (rev 90194)
+++ projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/BridgeFactory.java	2009-06-15 13:10:49 UTC (rev 90195)
@@ -23,19 +23,23 @@
 
 // $Id$
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Properties;
 
 import org.jboss.osgi.husky.internal.BasicBridge;
 import org.jboss.osgi.husky.internal.Util;
 
 /**
- * Loads the configured test {@link Bridge} instance.
+ * Loads the configured {@link Bridge} instance.
  * 
  * @author Thomas.Diesler at jboss.com
  * @since 16-May-2009
  */
 public abstract class BridgeFactory
 {
+   private static Map<Object, Bridge> bridgeCache = new HashMap<Object, Bridge>(); 
+      
    /**
     * Loads the bridge class that is configed through the system property {@link Bridge}.
     * If there is no such property, it returns an instance of {@link BasicBridge}.
@@ -43,11 +47,20 @@
    public static Bridge getBridge()
    {
       Properties props = System.getProperties();
-      String className = props.getProperty(Bridge.class.getName());
-      return (className != null ? getBridge(props) : new BasicBridge(props));
+      return getBridgeInternal(null, props);
    }
 
    /**
+    * Get the cached instance of the bridge class that is configed through the system property {@link Bridge}.
+    * If there is no cached instance it creates a new instance.
+    */
+   public static Bridge getBridge(Object key)
+   {
+      Properties props = System.getProperties();
+      return getBridgeInternal(key, props);
+   }
+
+   /**
     * Loads the bridge class that is configed through the property {@link Bridge}. 
     * 
     * If the loaded bridge has a constructor that takes a {@link Properties} parameter,
@@ -55,12 +68,26 @@
     * 
     * @param props bridge properties
     */
-   public static Bridge getBridge(Properties props)
+   public static Bridge getBridge(Object key, Properties props)
    {
-      String className = props.getProperty(Bridge.class.getName());
-      if (className == null)
-         throw new IllegalStateException("Cannot find property: " + Bridge.class.getName());
+         String className = props.getProperty(Bridge.class.getName());
+         if (className == null)
+            throw new IllegalStateException("Cannot find property: " + Bridge.class.getName());
 
-      return (Bridge)Util.loadInstance(className, props);
+      return getBridgeInternal(key, props);
    }
+   
+   private static Bridge getBridgeInternal(Object key, Properties props)
+   {
+      Bridge bridge = bridgeCache.get(key);
+      if (bridge == null)
+      {
+         String className = props.getProperty(Bridge.class.getName(), BasicBridge.class.getName());
+         bridge = (Bridge)Util.loadInstance(className, props);
+         
+         if (key != null)
+            bridgeCache.put(key, bridge);
+      }
+      return bridge;
+   }
 }

Modified: projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/Response.java
===================================================================
--- projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/Response.java	2009-06-15 12:10:16 UTC (rev 90194)
+++ projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/Response.java	2009-06-15 13:10:49 UTC (rev 90195)
@@ -43,11 +43,6 @@
    List<Failure> getFailures();
    
    /**
-    * Add a list of failures to the response
-    */
-   void addAllFailures(List<Failure> failures);
-   
-   /**
     * Add a failure to the response
     */
    void addFailure(Failure failure);

Modified: projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java
===================================================================
--- projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java	2009-06-15 12:10:16 UTC (rev 90194)
+++ projects/jboss-osgi/trunk/husky/harness/src/main/java/org/jboss/osgi/husky/internal/BasicResponse.java	2009-06-15 13:10:49 UTC (rev 90195)
@@ -51,12 +51,4 @@
    {
       failures.add(failure);
    }
-
-   public void addAllFailures(List<Failure> fails)
-   {
-      for (Failure failure : fails)
-      {
-         failures.add(failure);
-      }
-   }
 }

Modified: projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/ContextTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/ContextTestCase.java	2009-06-15 12:10:16 UTC (rev 90194)
+++ projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/ContextTestCase.java	2009-06-15 13:10:49 UTC (rev 90195)
@@ -24,6 +24,7 @@
 //$Id$
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assume.assumeNotNull;
 
 import org.jboss.osgi.husky.BridgeFactory;
 import org.jboss.osgi.husky.annotation.ProvideContext;
@@ -77,11 +78,10 @@
    public void testBundleContext() throws Exception
    {
       if (context == null)
-      {
          BridgeFactory.getBridge().run();
-         return;
-      }
       
+      assumeNotNull(context);
+      
       Bundle bundle = context.getBundle();
       assertEquals("context-basic", bundle.getSymbolicName());
    }

Added: projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/MultipleMethodsTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/MultipleMethodsTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/MultipleMethodsTestCase.java	2009-06-15 13:10:49 UTC (rev 90195)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt 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.
+ */
+package org.jboss.test.osgi.husky.context;
+
+//$Id$
+
+import static org.junit.Assert.*;
+import static org.junit.Assume.assumeNotNull;
+
+import org.jboss.osgi.husky.BridgeFactory;
+import org.jboss.osgi.husky.annotation.ProvideContext;
+import org.jboss.osgi.spi.capability.HuskyCapability;
+import org.jboss.osgi.spi.capability.JMXCapability;
+import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+
+/**
+ * Test BundleContext injection
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 13-May-2009
+ */
+public class MultipleMethodsTestCase
+{
+   @ProvideContext
+   public static BundleContext context;
+   private static OSGiRuntime runtime;
+
+   private static int testCount;
+   
+   @BeforeClass
+   public static void beforeClass() throws BundleException
+   {
+      if (context == null)
+      {
+         runtime = new OSGiTestHelper().getDefaultRuntime();
+         runtime.addCapability(new JMXCapability());
+         runtime.addCapability(new HuskyCapability());
+         
+         OSGiBundle bundle = runtime.installBundle("context-basic.jar");
+         bundle.start();
+      }
+   }
+
+   @AfterClass
+   public static void afterClass() throws BundleException
+   {
+      if (context == null)
+         runtime.shutdown();
+   }
+
+   @Test
+   public void testA() throws Exception
+   {
+      if (context == null)
+         BridgeFactory.getBridge(MultipleMethodsTestCase.class).run();
+      
+      assumeNotNull(context);
+
+      testCount++;
+      assertEquals("testA", 1, testCount);
+   }
+
+   @Test
+   public void testB() throws Exception
+   {
+      if (context == null)
+         BridgeFactory.getBridge(MultipleMethodsTestCase.class).run();
+      
+      assumeNotNull(context);
+
+      testCount++;
+      assertEquals("testB", 2, testCount);
+   }
+
+   @Test
+   public void testC() throws Exception
+   {
+      if (context == null)
+         BridgeFactory.getBridge(MultipleMethodsTestCase.class).run();
+      
+      assumeNotNull(context);
+
+      testCount++;
+      assertEquals("testC", 3, testCount);
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/husky/testsuite/src/test/java/org/jboss/test/osgi/husky/context/MultipleMethodsTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-osgi-commits mailing list