Author: thomas.diesler(a)jboss.com
Date: 2009-06-03 14:51:13 -0400 (Wed, 03 Jun 2009)
New Revision: 89754
Modified:
projects/jboss-osgi/trunk/docbook/en/modules/ch060-husky-testing.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd
Log:
userguide - ok
Modified: projects/jboss-osgi/trunk/docbook/en/modules/ch060-husky-testing.xml
===================================================================
--- projects/jboss-osgi/trunk/docbook/en/modules/ch060-husky-testing.xml 2009-06-03
17:40:20 UTC (rev 89753)
+++ projects/jboss-osgi/trunk/docbook/en/modules/ch060-husky-testing.xml 2009-06-03
18:51:13 UTC (rev 89754)
@@ -64,7 +64,8 @@
<para>Here is how it works </para>
<orderedlist>
- <listitem>A Bridge intercepts a test and delegates the execution to the same
(or another) test in and isolated test environment.
+ <listitem>A Bridge intercepts a test and determines the FQN of the test case
and the test method from the call stack.
+ It then delegates the execution to the same (or another) test in and isolated test
environment.
An isolated test environment is one that does not have the same class loading space
as the test itself.</listitem>
<listitem>A Bridge is associated with an Invoker. Invokers may be arbitarily
complex. Local 'in proccess'
@@ -77,24 +78,115 @@
<listitem>A PackageListeners delegates the Request to a test Runner, typicaly
this would be a JUnit runner.</listitem>
- <listitem>The Runner returns a Result, which the Connector returns to the
Invoker.</listitem>
+ <listitem>The Runner injects the Context and returns a Result, which the
Connector returns to the Invoker.</listitem>
<listitem>The Bridge finally translates potential Failures that may be
contained in the Result, to test failures on the client side.</listitem>
</orderedlist>
+
+ <para>The JBoss OSGi <emphasis
role="bold">jboss-osgi-husky.jar</emphasis> bundle registers the
Connectors. The JMXConnector is always
+ registered. The SocketConnector is registered when the appropriate configuration
options are set. It then registers the Extender,
+ which is a <ulink
url="http://www.osgi.org/javadoc/r4v41/org/osgi/framework/BundleList...
that inspects every
+ incomming bundle for the <emphasis
role="bold">Test-Package</emphasis> manifest header. The Extender
creates a PackageListener
+ for every package in the 'Test-Package' manifest header and registers them
with the available Connectors.</para>
+
</sect1>
<sect1 xml:id="SecHuskyConfiguration">
<title>Configuration</title>
- <para>[TODO]</para>
+ <para>In the target OSGi Framework, which is the one that has the <emphasis
role="bold">jboss-osgi-husky.jar</emphasis> bundle installed,
+ you set these properties</para>
+ <table>
+
<tr><th>Key</th><th>Value</th><th>Description</th></tr>
+ <tr valign="top">
+ <td>org.jboss.osgi.husky.runtime.connector.host</td>
+ <td>localhost</td>
+ <td>The Husky socket connector host poperty</td>
+ </tr>
+ <tr valign="top">
+ <td>org.jboss.osgi.husky.runtime.connector.port</td>
+ <td>5401</td>
+ <td>The Husky socket connector port poperty</td>
+ </tr>
+ </table>
+
+ <para>Both properties must be set for the SocketConnector to be
available.</para>
+
+ <para>On the client side, you must configure the Invoker you want to
use.</para>
+
+ <table>
+
<tr><th>Key</th><th>Value</th><th>Description</th></tr>
+ <tr valign="top">
+ <td>org.jboss.osgi.husky.Invoker</td>
+ <td>org.jboss.osgi.husky.internal.OSGiInvoker</td>
+ <td>The client side Husky Invoker</td>
+ </tr>
+ </table>
+
+ <para>This particular invoker will also look for the
'org.jboss.osgi.husky.runtime.connector.host' and
+ 'org.jboss.osgi.husky.runtime.connector.port' properties and if available
will use a socket invocation.</para>
</sect1>
<sect1 xml:id="SecHuskyWritingTests">
<title>Writing Husky Tests</title>
- <para>[TODO]</para>
+ <para>In a typical Husky test you have</para>
+ <itemizedlist>
+ <listitem>A <emphasis
role="bold">descriminator</emphasis> to distinguish between client and
'in container' execution</listitem>
+ <listitem>An <emphasis
role="bold">interceptor</emphasis> that delegates the call to an
Invoker (i.e. Bridge.run())</listitem>
+ </itemizedlist>
+
+ <para>For OSGi, the descriminator would be the <ulink
url="http://www.osgi.org/javadoc/r4v41/org/osgi/framework/BundleCont...
+ BundleContext</ulink> that gets injected by the 'in container' test
Runner</para>
+
+ <para>The interceptor would be a call to one of the Bridge.run()
variants.</para>
+
+ <programlisting role="JAVA">
+ public class SimpleHuskyTestCase
+ {
+ @ProvideContext
+ public BundleContext context;
+ ...
+ @Test
+ public void testSimpleBundle() throws Exception
+ {
+ // Tell Husky to run this test method within the OSGi Runtime
+ if (context == null)
+ BridgeFactory.getBridge().run();
+
+ // Stop here if the context is not injected
+ assumeNotNull(context);
+
+ // Get the SimpleService reference
+ ServiceReference sref =
context.getServiceReference(SimpleService.class.getName());
+ assertNotNull("SimpleService Not Null", sref);
+
+ // Access the SimpleService
+ SimpleService service = (SimpleService)context.getService(sref);
+ assertEquals("hello", service.echo("hello"));
+ }
+ }
+ </programlisting>
+
+ <para>The bundle that contains the test case must have the <emphasis
role="bold">Test-Package</emphasis> manifest header
+ configured. Here is the <ulink
url="http://www.aqute.biz/Code/Bnd">aQute Bnd Tool</ulink>
configuration for doing so.</para>
+
+ <programlisting>
+ Bundle-SymbolicName: example-simple-husky
+
+ Bundle-Activator: org.jboss.test.osgi.example.simple.bundle.SimpleActivator
+
+ Private-Package: org.jboss.test.osgi.example.simple.bundle
+
+ # Export the package that contains tthe test case
+ Export-Package: org.jboss.test.osgi.example.simple
+
+ # Tell Husky that there are test cases in this package
+ Test-Package: org.jboss.test.osgi.example.simple
+ </programlisting>
+
</sect1>
</chapter>
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd
===================================================================
---
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd 2009-06-03
17:40:20 UTC (rev 89753)
+++
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/simple/example-simple-husky.bnd 2009-06-03
18:51:13 UTC (rev 89754)
@@ -4,10 +4,10 @@
Bundle-Activator: org.jboss.test.osgi.example.simple.bundle.SimpleActivator
+Private-Package: org.jboss.test.osgi.example.simple.bundle
+
# Export the package that contains tthe test case
Export-Package: org.jboss.test.osgi.example.simple
-Private-Package: org.jboss.test.osgi.example.simple.bundle
-
# Tell Husky that there are test cases in this package
-Test-Package: org.jboss.test.osgi.example.simple
\ No newline at end of file
+Test-Package: org.jboss.test.osgi.example.simple