[jboss-cvs] JBossAS SVN: r102112 - in projects/jboss-osgi/projects/testing/trunk: src/main/java/org/jboss/osgi/testing and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 9 01:40:51 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-03-09 01:40:50 -0500 (Tue, 09 Mar 2010)
New Revision: 102112

Added:
   projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
Modified:
   projects/jboss-osgi/projects/testing/trunk/pom.xml
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
   projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
   projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
Log:
wip

Modified: projects/jboss-osgi/projects/testing/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/pom.xml	2010-03-09 06:40:07 UTC (rev 102111)
+++ projects/jboss-osgi/projects/testing/trunk/pom.xml	2010-03-09 06:40:50 UTC (rev 102112)
@@ -42,6 +42,7 @@
   <properties>
     <version.apache.aries.jmx>1.0.0-incubating-SNAPSHOT</version.apache.aries.jmx>
     <version.apache.felix.log>1.0.0</version.apache.felix.log>
+    <version.jboss.shrinkwrap>1.0.0-alpha-6</version.jboss.shrinkwrap>
     <version.jboss.osgi.common>1.0.4-SNAPSHOT</version.jboss.osgi.common>
     <version.jboss.osgi.felix>2.0.2.SP1-SNAPSHOT</version.jboss.osgi.felix>
     <version.jboss.osgi.jmx>1.0.4-SNAPSHOT</version.jboss.osgi.jmx>
@@ -72,6 +73,11 @@
       <version>${version.jboss.osgi.vfs}</version>
     </dependency>
     <dependency>
+      <groupId>org.jboss.shrinkwrap</groupId>
+      <artifactId>shrinkwrap-api</artifactId>
+    <version>${version.jboss.shrinkwrap}</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java	2010-03-09 06:40:07 UTC (rev 102111)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java	2010-03-09 06:40:50 UTC (rev 102112)
@@ -28,6 +28,7 @@
 import javax.naming.NamingException;
 
 import org.jboss.osgi.spi.capability.Capability;
+import org.jboss.osgi.vfs.VirtualFile;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
 import org.osgi.jmx.framework.BundleStateMBean;
@@ -59,6 +60,11 @@
    void removeCapability(Capability capability);
 
    /**
+    * Install an {@link OSGiBundle} from the given virtual file.
+    */
+   OSGiBundle installBundle(VirtualFile vfsfile) throws BundleException, IOException;
+
+   /**
     * Install an {@link OSGiBundle} from the given location.
     */
    OSGiBundle installBundle(String location) throws BundleException;

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java	2010-03-09 06:40:07 UTC (rev 102111)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java	2010-03-09 06:40:50 UTC (rev 102112)
@@ -23,6 +23,7 @@
 
 // $Id$
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
@@ -40,6 +41,7 @@
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiServiceReference;
 import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.osgi.vfs.VirtualFile;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
@@ -65,6 +67,17 @@
       super(helper);
    }
 
+   public OSGiBundle installBundle(VirtualFile file) throws BundleException, IOException
+   {
+      BundleInfo info = BundleInfo.createBundleInfo(file);
+
+      BundleContext context = getSystemContext();
+      Bundle auxBundle = context.installBundle(info.getLocation(), file.openStream());
+      OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
+      
+      return registerBundle(bundle.getLocation(), bundle);
+   }
+
    public OSGiBundle installBundle(String location) throws BundleException
    {
       BundleInfo info = BundleInfo.createBundleInfo(location);

Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2010-03-09 06:40:07 UTC (rev 102111)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java	2010-03-09 06:40:50 UTC (rev 102112)
@@ -43,11 +43,13 @@
 import org.jboss.osgi.jmx.MBeanProxy;
 import org.jboss.osgi.jmx.ObjectNameFactory;
 import org.jboss.osgi.jmx.ServiceStateMBeanExt;
+import org.jboss.osgi.spi.NotImplementedException;
 import org.jboss.osgi.spi.util.BundleInfo;
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
 import org.jboss.osgi.testing.OSGiServiceReference;
 import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.osgi.vfs.VirtualFile;
 import org.osgi.framework.BundleException;
 import org.osgi.jmx.framework.BundleStateMBean;
 import org.osgi.jmx.framework.ServiceStateMBean;
@@ -70,6 +72,11 @@
       super(helper);
    }
 
+   public OSGiBundle installBundle(VirtualFile file) throws BundleException, IOException
+   {
+      throw new NotImplementedException();
+   }
+   
    public OSGiBundle installBundle(String location) throws BundleException
    {
       try

Added: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java	2010-03-09 06:40:50 UTC (rev 102112)
@@ -0,0 +1,82 @@
+/*
+ * 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.testing;
+
+//$Id: SimpleTestCase.java 101150 2010-02-19 10:50:46Z thomas.diesler at jboss.com $
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.Closeable;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.ManifestBuilder;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.osgi.vfs.VirtualFileAssembly;
+import org.jboss.test.osgi.testing.bundle.SimpleActivator;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * A test that deployes a bundle and verifies its state
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 12-Feb-2009
+ */
+public class SimpleAssemblyTestCase extends OSGiTest
+{
+   @Test
+   public void testSimpleAssembly() throws Exception
+   {
+      OSGiRuntime runtime = getDefaultRuntime();
+      try
+      {
+         VirtualFileAssembly assembly = AbstractVFS.createVirtualFileAssembly("example-simple.jar");
+         assembly.addClass(SimpleActivator.class);
+
+         ManifestBuilder mb = ManifestBuilder.newInstance();
+         mb.addBundleManifestVersion(2);
+         mb.addBundleSymbolicName("example-simple");
+         mb.addBundleActivator(SimpleActivator.class.getName());
+         mb.addImportPackages("org.jboss.osgi.common.log", "org.osgi.framework", "org.osgi.service.log");
+         
+         Manifest manifest = mb.getManifest();
+         assembly.addManifest(manifest);
+
+         OSGiBundle bundle = runtime.installBundle(assembly);
+         assertBundleState(Bundle.INSTALLED, bundle.getState());
+      }
+      finally
+      {
+         runtime.shutdown();
+      }
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java	2010-03-09 06:40:07 UTC (rev 102111)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java	2010-03-09 06:40:50 UTC (rev 102112)
@@ -23,9 +23,13 @@
 
 //$Id$
 
+import static org.junit.Assert.*;
+
 import org.jboss.osgi.testing.OSGiBundle;
 import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
 import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.testing.bundle.SimpleService;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 
@@ -51,7 +55,19 @@
          // Start the bundle
          bundle.start();
          assertBundleState(Bundle.ACTIVE, bundle.getState());
+         
+         // Check service is registered
+         OSGiServiceReference sref = runtime.getServiceReference(SimpleService.class.getName());
+         assertNotNull("Service registered", sref);
 
+         // Stop the bundle
+         bundle.stop();
+         assertBundleState(Bundle.RESOLVED, bundle.getState());
+         
+         // Check service is registered
+         sref = runtime.getServiceReference(SimpleService.class.getName());
+         assertNull("Service not registered", sref);
+
          // Uninstall the bundle
          bundle.uninstall();
          assertBundleState(Bundle.UNINSTALLED, bundle.getState());




More information about the jboss-cvs-commits mailing list