incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mahrw...@apache.org
Subject svn commit: r992259 - in /incubator/aries/trunk/application: application-itests/src/test/java/org/apache/aries/application/runtime/itests/ application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/
Date Fri, 03 Sep 2010 10:48:00 GMT
Author: mahrwald
Date: Fri Sep  3 10:48:00 2010
New Revision: 992259

URL: http://svn.apache.org/viewvc?rev=992259&view=rev
Log:
Support application uninstall with subsequent reinstall

Modified:
    incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
    incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java

Modified: incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java?rev=992259&r1=992258&r2=992259&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
(original)
+++ incubator/aries/trunk/application/application-itests/src/test/java/org/apache/aries/application/runtime/itests/IsolatedRuntimeTest.java
Fri Sep  3 10:48:00 2010
@@ -97,118 +97,111 @@ public class IsolatedRuntimeTest extends
     try
     {
       ctx.start();
-      
-      BundleContext appContext = null;
-      for (Bundle sharedBundle : bundleContext.getBundles())
-      {
-        if (sharedBundle.getSymbolicName().equals("shared.bundle.framework"))
-        {
-          BundleContext sharedContext = ((CompositeBundle)sharedBundle).getCompositeFramework().getBundleContext();
-          for (Bundle appBundle : sharedContext.getBundles())
-          {
-            if (appBundle.getSymbolicName().equals("test.eba"))
-            {
-              appContext = ((CompositeBundle)appBundle).getCompositeFramework().getBundleContext();
-              break;
-            }
-          }
-          break;
-        }
-      }
-      
-      if (appContext != null) {  
-        // Dive into the context and pull out the composite bundle for the app
-        Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "="
+ HelloWorld.class.getName() + ")");
-        ServiceTracker tracker = new ServiceTracker(appContext, 
-            osgiFilter,
-            null);
-        tracker.open();
-        
-        Object hw = tracker.waitForService(DEFAULT_TIMEOUT);
-        
-        tracker.close();
+      assertHelloWorldService("test.eba");
+    } finally {
+      ctx.stop();
+      manager.uninstall(ctx);
+    }
+  }
+  
+  @Test
+  public void testAppWithApplicationManifest() throws Exception {
         
-        // We can cast to our version of HelloWorld as it is in a different classloader
-        // so reflect into it to get the single method
-        Class returnClass = hw.getClass();
-        Method method = returnClass.getDeclaredMethod("getMessage",null);
-        result = (String)method.invoke(hw);      
-       
-      }
-      else
-        fail("No service found inside application framework");
-      
-    } catch (Exception e)
+    AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
+    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
+    AriesApplicationContext ctx = manager.install(app);
+    
+    try
     {
-      System.out.println("MOOP");
+      ctx.start();
       
-      e.printStackTrace();
+      assertHelloWorldService("org.apache.aries.sample2");
       
     } finally {
       ctx.stop();
       manager.uninstall(ctx);
     }
-    
-    assertEquals (result, "hello world");
   }
-
+  
   @Test
-  public void testAppWithApplicationManifest() throws Exception {
-        
+  public void testUninstallReinstall() throws Exception {
     AriesApplicationManager manager = getOsgiService(AriesApplicationManager.class);
     AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
     AriesApplicationContext ctx = manager.install(app);
     
+    app = ctx.getApplication();
+    
     try
     {
       ctx.start();
       
-      BundleContext appContext = null;
-      for (Bundle sharedBundle : bundleContext.getBundles())
-      {
-        if (sharedBundle.getSymbolicName().equals("shared.bundle.framework"))
-        {
-          BundleContext sharedContext = ((CompositeBundle)sharedBundle).getCompositeFramework().getBundleContext();
-          for (Bundle appBundle : sharedContext.getBundles())
-          {
-            if (appBundle.getSymbolicName().equals("org.apache.aries.sample2"))
-            {
-              appContext = ((CompositeBundle)appBundle).getCompositeFramework().getBundleContext();
-              break;
-            }
-          }
-          break;
-        }
-      }
+      assertHelloWorldService("org.apache.aries.sample2");
       
-      if (appContext != null) {  
-        // Dive into the context and pull out the composite bundle for the app
-        Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "="
+ HelloWorld.class.getName() + ")");
-        ServiceTracker tracker = new ServiceTracker(appContext, 
-            osgiFilter,
-            null);
-        tracker.open();
-        
-        Object hw = tracker.waitForService(DEFAULT_TIMEOUT);
-        
-        tracker.close();
-        
-        // We can cast to our version of HelloWorld as it is in a different classloader
-        // so reflect into it to get the single method
-        Class returnClass = hw.getClass();
-        Method method = returnClass.getDeclaredMethod("getMessage",null);
-        String result = (String)method.invoke(hw);
-        assertEquals (result, "hello world");
-        
-        
-      }
-      else
-        fail("No service found inside application framework");
+      ctx.stop();
+      manager.uninstall(ctx);
+      
+      ctx = manager.install(app);
+      ctx.start();
+      
+      assertHelloWorldService("org.apache.aries.sample2");
       
     } finally {
       ctx.stop();
       manager.uninstall(ctx);
+    }    
+  }
+
+  
+  
+  private void assertHelloWorldService(String appName) throws Exception
+  {
+    BundleContext appContext = getAppIsolatedBundleContext(appName);
+    
+    if (appContext != null) {  
+      // Dive into the context and pull out the composite bundle for the app
+      Filter osgiFilter = FrameworkUtil.createFilter("(" + Constants.OBJECTCLASS + "=" +
HelloWorld.class.getName() + ")");
+      ServiceTracker tracker = new ServiceTracker(appContext, 
+          osgiFilter,
+          null);
+      tracker.open();
+      
+      Object hw = tracker.waitForService(DEFAULT_TIMEOUT);
+      
+      tracker.close();
+      
+      // We can cast to our version of HelloWorld as it is in a different classloader
+      // so reflect into it to get the single method
+      Class returnClass = hw.getClass();
+      Method method = returnClass.getDeclaredMethod("getMessage",null);
+      String result = (String)method.invoke(hw);      
+      
+      assertEquals("hello world", result);
     }
+    else {
+      fail("No service found inside application framework");
+    }
+    
+  }
+  
+  private BundleContext getAppIsolatedBundleContext(String appName)
+  {
+    for (Bundle sharedBundle : bundleContext.getBundles())
+    {
+      if (sharedBundle.getSymbolicName().equals("shared.bundle.framework"))
+      {
+        BundleContext sharedContext = ((CompositeBundle)sharedBundle).getCompositeFramework().getBundleContext();
+        for (Bundle appBundle : sharedContext.getBundles())
+        {
+          if (appBundle.getSymbolicName().equals(appName))
+          {
+            return ((CompositeBundle)appBundle).getCompositeFramework().getBundleContext();
+          }
+        }
+        break;
+      }
+    }    
+    
+    return null;
   }
 
   

Modified: incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java?rev=992259&r1=992258&r2=992259&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java
(original)
+++ incubator/aries/trunk/application/application-runtime-framework/src/main/java/org/apache/aries/application/runtime/framework/BundleFrameworkImpl.java
Fri Sep  3 10:48:00 2010
@@ -78,6 +78,7 @@ public class BundleFrameworkImpl impleme
     }
 
     _compositeBundle.stop();
+    _compositeBundle.uninstall();
   }
 
   public void start(Bundle b) throws BundleException



Mime
View raw message