You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Raymond Feng <en...@gmail.com> on 2009/01/16 22:23:57 UTC
Run junit test cases in maven with OSGi
Hi,
I have prototyped a maven plugin that can run junit test cases with the
Equinox OSGi runtime. It works as follows:
1) Generate a bundle for the current project with the target/classes
2) Generate a bundle fragment that attaches to the bundle from step 1
3) Find all the maven dependencies and use them as the set of initial
bundles (the plain jars are converted into a bundle on the fly too)
4) Bootstrap the Equinox runtime
5) Find all test cases and run them with the JUNIT runner
6) Report the results of the test case
To configure a maven project, use the following XML in the pom.xml (See an
example at [2]):
<plugin>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-maven-osgi-junit</artifactId>
<version>2.0-SNAPSHOT</version>
<executions>
<execution>
<id>osgi-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
<configuration></configuration>
</executions>
</plugin>
The ideal approach is to plug in the same logic into the existing
maven-surefire-plugin. But it doesn't seem that the surefire plugin has such
plug points.
Please let me know if you have better ideas.
Thanks,
Raymond
[1]
https://svn.apache.org/repos/asf/tuscany/java/sca/tools/maven/maven-osgi-junit
[2]
https://svn.apache.org/repos/asf/tuscany/java/sca/samples/calculator-osgi/pom.xml
Re: Run junit test cases in maven with OSGi
Posted by Raymond Feng <en...@gmail.com>.
Most of the comments are agreed here. In fact, the maven plugin mostly delegates to the EquinoxHost in the tuscany-node-launcher-equinox module. As a summary, the launcher provides the following functions:
1) Locate the Tuscany runtime jars/bundles (from a ditro, from classpath, from maven dependencies, from osgi bundles etc)
2) Bootstrap the runtime
3) Locate the runnables (such as the main class or JUNIT test cases) and execute them
Thanks,
Raymond
From: Simon Laws
Sent: Tuesday, January 20, 2009 4:11 AM
To: dev@tuscany.apache.org
Subject: Re: Run junit test cases in maven with OSGi
Thanks for the info Raymond
snip...
1) The maven plug finds the dependencies and use them as the list of jars (bundles) to be installed to the Equinox runtime. We also package the main and test code into a bundle so that all the classes (main/test and tuscany/3rd-party) are loaded by OSGi. Typically the current project will have dependencies on the SCA API/annotations or Tuscany API, the maven surefire plugin will create a URL classloader and it makes the main/test classes get the SCA/Tuscany API classes from JSE instead of OSGi.
2) I assume most of our Junit test cases start/stop Node using the Tuscany Node APIs. The plugin approach makes it possible to run the test cases under both JSE and OSGi without changing the code.
What I was getting at in my initial question is that this sounds a lot like the launcher code we have + the code that wraps up the module and the test and + the code that fires up junit. So it sounds like we are describing a set of launcher functions. The current base function being
Launcher (for command line)
Get dependencies and create OSGi runtime
Get contributions and start node
And extending this you are creating another launcher to handle a specific environment
Launcher (for junit)
Bundle up module and tests
Fire up JUnit
It just so happens you have wrapped all this up in a maven plugin. The Junit launcher function could be useful from the command line or from Eclipse. So I think this is good input to our launcher discussion
I'm not particularly proposing to change anything immediately but lets see what happens on the other discussion. I'd rather have a coherent launcher story and a maven plugin that exploits it rather thant some specific function buried in the maven plugin mojo. That's all I was getting at.
Regards
Simon
Re: Run junit test cases in maven with OSGi
Posted by Simon Laws <si...@googlemail.com>.
Thanks for the info Raymond
snip...
> 1) The maven plug finds the dependencies and use them as the list of jars
> (bundles) to be installed to the Equinox runtime. We also package the main
> and test code into a bundle so that all the classes (main/test and
> tuscany/3rd-party) are loaded by OSGi. Typically the current project will
> have dependencies on the SCA API/annotations or Tuscany API, the maven
> surefire plugin will create a URL classloader and it makes the main/test
> classes get the SCA/Tuscany API classes from JSE instead of OSGi.
>
> 2) I assume most of our Junit test cases start/stop Node using the
> Tuscany Node APIs. The plugin approach makes it possible to run the test
> cases under both JSE and OSGi without changing the code.
>
What I was getting at in my initial question is that this sounds a lot like
the launcher code we have + the code that wraps up the module and the test
and + the code that fires up junit. So it sounds like we are describing a
set of launcher functions. The current base function being
Launcher (for command line)
Get dependencies and create OSGi runtime
Get contributions and start node
And extending this you are creating another launcher to handle a specific
environment
Launcher (for junit)
Bundle up module and tests
Fire up JUnit
It just so happens you have wrapped all this up in a maven plugin. The
Junit launcher function could be useful from the command line or from
Eclipse. So I think this is good input to our launcher discussion
I'm not particularly proposing to change anything immediately but lets see
what happens on the other discussion. I'd rather have a coherent launcher
story and a maven plugin that exploits it rather thant some specific
function buried in the maven plugin mojo. That's all I was getting at.
Regards
Simon
Re: Run junit test cases in maven with OSGi
Posted by Raymond Feng <en...@gmail.com>.
Hi,
The logic is similar with the following differences:
1) The maven plug finds the dependencies and use them as the list of jars (bundles) to be installed to the Equinox runtime. We also package the main and test code into a bundle so that all the classes (main/test and tuscany/3rd-party) are loaded by OSGi. Typically the current project will have dependencies on the SCA API/annotations or Tuscany API, the maven surefire plugin will create a URL classloader and it makes the main/test classes get the SCA/Tuscany API classes from JSE instead of OSGi.
2) I assume most of our Junit test cases start/stop Node using the Tuscany Node APIs. The plugin approach makes it possible to run the test cases under both JSE and OSGi without changing the code.
Thanks,
Raymond
From: Simon Laws
Sent: Monday, January 19, 2009 7:59 AM
To: dev@tuscany.apache.org
Subject: Re: Run junit test cases in maven with OSGi
Hi Raymond
Some questions inline.
Why can't we use the launcher in the Junit test to fire up the runtime rather that turning the test itself into a bundle. Are you tring to ensure that the junit test doesn't have to reach from the JSE world into the OSGi world?
The launcher would be able to get the dependencies from the classpath but wouldn't be able to get at the bundelized 3rd party jars currently in PDE target. You seem to have some code for doing this on the fly so could this also be incorporated into the launcher.
Simon
On Fri, Jan 16, 2009 at 9:23 PM, Raymond Feng <en...@gmail.com> wrote:
Hi,
I have prototyped a maven plugin that can run junit test cases with the Equinox OSGi runtime. It works as follows:
1) Generate a bundle for the current project with the target/classes
Does this create an activator in the bundle to run the test?
2) Generate a bundle fragment that attaches to the bundle from step 1
What is this fragment for?
3) Find all the maven dependencies and use them as the set of initial bundles (the plain jars are converted into a bundle on the fly too)
4) Bootstrap the Equinox runtime
5) Find all test cases and run them with the JUNIT runner
How are the test cases identified?
6) Report the results of the test case
To configure a maven project, use the following XML in the pom.xml (See an example at [2]):
<plugin>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-maven-osgi-junit</artifactId>
<version>2.0-SNAPSHOT</version>
<executions>
<execution>
<id>osgi-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
<configuration></configuration>
</executions>
</plugin>
The ideal approach is to plug in the same logic into the existing maven-surefire-plugin. But it doesn't seem that the surefire plugin has such plug points.
Please let me know if you have better ideas.
Thanks,
Raymond
[1] https://svn.apache.org/repos/asf/tuscany/java/sca/tools/maven/maven-osgi-junit
[2] https://svn.apache.org/repos/asf/tuscany/java/sca/samples/calculator-osgi/pom.xml
Re: Run junit test cases in maven with OSGi
Posted by Simon Laws <si...@googlemail.com>.
Hi Raymond
Some questions inline.
Why can't we use the launcher in the Junit test to fire up the runtime
rather that turning the test itself into a bundle. Are you tring to ensure
that the junit test doesn't have to reach from the JSE world into the OSGi
world?
The launcher would be able to get the dependencies from the classpath but
wouldn't be able to get at the bundelized 3rd party jars currently in PDE
target. You seem to have some code for doing this on the fly so could this
also be incorporated into the launcher.
Simon
On Fri, Jan 16, 2009 at 9:23 PM, Raymond Feng <en...@gmail.com> wrote:
> Hi,
>
> I have prototyped a maven plugin that can run junit test cases with the
> Equinox OSGi runtime. It works as follows:
>
> 1) Generate a bundle for the current project with the target/classes
Does this create an activator in the bundle to run the test?
>
> 2) Generate a bundle fragment that attaches to the bundle from step 1
What is this fragment for?
>
> 3) Find all the maven dependencies and use them as the set of initial
> bundles (the plain jars are converted into a bundle on the fly too)
> 4) Bootstrap the Equinox runtime
> 5) Find all test cases and run them with the JUNIT runner
How are the test cases identified?
>
> 6) Report the results of the test case
>
> To configure a maven project, use the following XML in the pom.xml (See an
> example at [2]):
> <plugin>
> <groupId>org.apache.tuscany.sca</groupId>
> <artifactId>tuscany-maven-osgi-junit</artifactId>
> <version>2.0-SNAPSHOT</version>
> <executions>
> <execution>
> <id>osgi-test</id>
> <phase>test</phase>
> <goals>
> <goal>test</goal>
> </goals>
> </execution>
> <configuration></configuration>
> </executions>
> </plugin>
>
> The ideal approach is to plug in the same logic into the existing
> maven-surefire-plugin. But it doesn't seem that the surefire plugin has such
> plug points.
>
> Please let me know if you have better ideas.
>
> Thanks,
> Raymond
>
> [1]
> https://svn.apache.org/repos/asf/tuscany/java/sca/tools/maven/maven-osgi-junit
> [2]
> https://svn.apache.org/repos/asf/tuscany/java/sca/samples/calculator-osgi/pom.xml
>
>
>
>
Re: Run junit test cases in maven with OSGi
Posted by Raymond Feng <en...@gmail.com>.
Hi,
A quick update: I have greatly enhanced the maven-osgi-junit plugin based on
the maven-surefire-plugin. Now it works pretty much like the
maven-surefire-plugin (the same set of configurations) except that it runs
the test cases with the main/test classes and all the dependencies loaded as
Equinox bunldes.
Thanks,
Raymond
--------------------------------------------------
From: "Dan Becker" <da...@gmail.com>
Sent: Friday, January 16, 2009 1:44 PM
To: <de...@tuscany.apache.org>
Subject: Re: Run junit test cases in maven with OSGi
> Raymond Feng wrote:
>> I have prototyped a maven plugin that can run junit test cases with the
>> Equinox OSGi runtime. It works as follows:
>>
>> 1) Generate a bundle for the current project with the target/classes
>> 2) Generate a bundle fragment that attaches to the bundle from step 1
>> 3) Find all the maven dependencies and use them as the set of initial
>> bundles (the plain jars are converted into a bundle on the fly too)
>> 4) Bootstrap the Equinox runtime
>> 5) Find all test cases and run them with the JUNIT runner
>> 6) Report the results of the test case
>>
>> To configure a maven project, use the following XML in the pom.xml (See
>> an example at [2]):
>> <plugin>
>> <groupId>org.apache.tuscany.sca</groupId>
>> <artifactId>tuscany-maven-osgi-junit</artifactId>
>> <version>2.0-SNAPSHOT</version>
>> <executions>
>> <execution>
>> <id>osgi-test</id>
>> <phase>test</phase>
>> <goals>
>> <goal>test</goal>
>> </goals>
>> </execution>
>> <configuration></configuration>
>> </executions>
>> </plugin>
>>
>> The ideal approach is to plug in the same logic into the existing
>> maven-surefire-plugin. But it doesn't seem that the surefire plugin has
>> such plug points.
>>
>> Please let me know if you have better ideas.
>>
>> Thanks,
>> Raymond
>>
>> [1]
>> https://svn.apache.org/repos/asf/tuscany/java/sca/tools/maven/maven-osgi-junit
>> [2]
>> https://svn.apache.org/repos/asf/tuscany/java/sca/samples/calculator-osgi/pom.xml
>
> +1. This would be quite useful in 2.0.
>
> --
> Thanks, Dan Becker
Re: Run junit test cases in maven with OSGi
Posted by Dan Becker <da...@gmail.com>.
Raymond Feng wrote:
> I have prototyped a maven plugin that can run junit test cases with the
> Equinox OSGi runtime. It works as follows:
>
> 1) Generate a bundle for the current project with the target/classes
> 2) Generate a bundle fragment that attaches to the bundle from step 1
> 3) Find all the maven dependencies and use them as the set of initial
> bundles (the plain jars are converted into a bundle on the fly too)
> 4) Bootstrap the Equinox runtime
> 5) Find all test cases and run them with the JUNIT runner
> 6) Report the results of the test case
>
> To configure a maven project, use the following XML in the pom.xml (See
> an example at [2]):
> <plugin>
> <groupId>org.apache.tuscany.sca</groupId>
> <artifactId>tuscany-maven-osgi-junit</artifactId>
> <version>2.0-SNAPSHOT</version>
> <executions>
> <execution>
> <id>osgi-test</id>
> <phase>test</phase>
> <goals>
> <goal>test</goal>
> </goals>
> </execution>
> <configuration></configuration>
> </executions>
> </plugin>
>
> The ideal approach is to plug in the same logic into the existing
> maven-surefire-plugin. But it doesn't seem that the surefire plugin has
> such plug points.
>
> Please let me know if you have better ideas.
>
> Thanks,
> Raymond
>
> [1]
> https://svn.apache.org/repos/asf/tuscany/java/sca/tools/maven/maven-osgi-junit
>
> [2]
> https://svn.apache.org/repos/asf/tuscany/java/sca/samples/calculator-osgi/pom.xml
>
+1. This would be quite useful in 2.0.
--
Thanks, Dan Becker