Author: thomas.diesler(a)jboss.com
Date: 2009-11-11 02:05:34 -0500 (Wed, 11 Nov 2009)
New Revision: 96250
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTest.java
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
Log:
Add VFS bundle creation
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTest.java
===================================================================
---
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2009-11-11
07:03:43 UTC (rev 96249)
+++
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2009-11-11
07:05:34 UTC (rev 96250)
@@ -28,6 +28,7 @@
import javax.naming.NamingException;
import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
import org.junit.After;
import org.junit.Before;
import org.slf4j.Logger;
@@ -178,14 +179,6 @@
}
/**
- * Delegates to {@link OSGiTestHelper#getJndiPort()}
- */
- public Integer getJndiPort()
- {
- return getTestHelper().getJndiPort();
- }
-
- /**
* Delegates to {@link OSGiTestHelper#getServerHost()}
*/
public String getServerHost()
@@ -208,28 +201,14 @@
{
return getTestHelper().getFramework();
}
-
- /**
- * Delegates to {@link OSGiTestHelper#isFrameworkEquinox()}
- */
- public boolean isFrameworkEquinox()
+
+ public VirtualFile assembleBundle(String name, String resource, Class<?>...
packages) throws Exception
{
- return getTestHelper().isFrameworkEquinox();
+ return getTestHelper().assembleBundle(name, resource, packages);
}
-
- /**
- * Delegates to {@link OSGiTestHelper#isFrameworkFelix()}
- */
- public boolean isFrameworkFelix()
+
+ public VirtualFile assembleBundle(String name, String[] resources, Class<?>...
packages) throws Exception
{
- return getTestHelper().isFrameworkFelix();
+ return getTestHelper().assembleBundle(name, resources, packages);
}
-
- /**
- * Delegates to {@link OSGiTestHelper#isFrameworkJBossMC()}
- */
- public boolean isFrameworkJBossMC()
- {
- return getTestHelper().isFrameworkJBossMC();
- }
}
Modified:
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
---
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2009-11-11
07:03:43 UTC (rev 96249)
+++
projects/jboss-osgi/projects/bundles/husky/trunk/harness/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2009-11-11
07:05:34 UTC (rev 96250)
@@ -29,10 +29,15 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import junit.framework.AssertionFailedError;
+
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
import org.jboss.osgi.testing.internal.EmbeddedRuntime;
import org.jboss.osgi.testing.internal.RemoteRuntime;
+import org.jboss.virtual.AssembledDirectory;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
/**
* An OSGi Test Helper
@@ -172,49 +177,73 @@
@SuppressWarnings("unchecked")
public InitialContext getInitialContext() throws NamingException
{
+ String port = System.getProperty("jndi.server.port", "1099");
+ Integer jndiPort = new Integer(port);
+
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
- env.put("java.naming.provider.url", "jnp://" + getServerHost()
+ ":" + getJndiPort());
+ env.put("java.naming.provider.url", "jnp://" + getServerHost()
+ ":" + jndiPort);
return new InitialContext(env);
}
- public Integer getJndiPort()
- {
- String port = System.getProperty("jndi.server.port", "1099");
- return new Integer(port);
- }
-
public String getServerHost()
{
String bindAddress = System.getProperty("jboss.bind.address",
"localhost");
return bindAddress;
}
-
+
public String getTargetContainer()
{
String targetContainer = System.getProperty("target.container");
return targetContainer;
}
-
+
public String getFramework()
{
String framework = System.getProperty("framework", "jbossmc");
return framework;
}
-
- public boolean isFrameworkEquinox()
+
+ public VirtualFile assembleBundle(String name, String resource, Class<?>...
packages) throws Exception
{
- return "equinox".equals(getFramework());
+ return assembleBundle(name, new String[] { resource }, packages);
}
-
- public boolean isFrameworkFelix()
+
+ public VirtualFile assembleBundle(String name, String[] resources, Class<?>...
packages) throws Exception
{
- return "felix".equals(getFramework());
+ AssembledDirectory assembledDirectory =
AssembledDirectory.createAssembledDirectory(name, "");
+ for (String path : resources)
+ addPath(assembledDirectory, path, "");
+ for (Class<?> reference : packages)
+ addPackage(assembledDirectory, reference);
+ return assembledDirectory;
}
-
- public boolean isFrameworkJBossMC()
+
+ private void addPath(AssembledDirectory dir, String path, String name) throws
Exception
{
- return "jbossmc".equals(getFramework());
+ URL url = getClass().getResource(path);
+ if (url == null)
+ throw new AssertionFailedError(path + " not found");
+
+ VirtualFile file = VFS.getVirtualFile(url, name);
+ dir.addPath(file);
}
+
+ private void addPackage(AssembledDirectory dir, Class<?> reference) throws
Exception
+ {
+ String packagePath = packageNameToPath(reference.getName());
+ dir.addResources(reference, new String[] { packagePath + "/*.class" },
new String[0]);
+ }
+
+ // Convert a class's package name into a path
+ private String packageNameToPath(final String className)
+ {
+ int end = className.lastIndexOf('.');
+ if (end == -1)
+ return "";
+
+ String packageName = className.substring(0, end);
+ return packageName.replace('.', '/');
+ }
}