Marcel Offermans wrote:
Hi Alex,

The class cast exception indicates there are two different copies on the class path. Since you did not post exactly how you started up, I'd have to guess what's going on...

...but, I would like to ask you why you are extending Felix like this?

Basically I want to do a mvn osgi:run to install and run the bundle in Felix. Combined with a archetype I can generate test bundles used to test other bundles. This way I can integration test (in situ) the bundle.

Perhaps I may make an abstract unit test as well that does something similar.

I
see at least two other approaches that I would favor:

1) Keeping this as a bundle. What you're doing is essentially (in OSGi speak) installing a (simple) management agent. This agent is then responsible for installing and starting bundles.

Right but I want maven to run tests and not to have to do it manually.

2) Keeping it as a "bundle" that loads as part of the system bundle. Felix has a nice mechanism to provide zero or more extensions to the system bundle by means of providing classes that implement BundleActivator. Package your stuff like that and my guess is it runs without any modifications (compared to running it as 1) which is something you've already tried.

Furthermore, if you're concerned about having to specify all kinds of startup options to fire up this management bundle, it's fairly easy to create a wrapper startup class that sets all options (as system properties) and subsequently starts Felix (which will then pick those up and auto start your "management agent" bundle that will then start the rest).

Yeah this is exactly what I want to do.

I'm guessing you're doing this to create some kind of automated test framework?

Exactly!

I would very much prefer option 1) because that is the one that is the easiest to "port" to other frameworks.

So tests will not run with the build though. I want the tests to run as part of the build process as they do with regular test cases for things I unit test without a container.

But, this is a lot of guesswork and brainstorming, so I might not understand the problem you're trying to solve at all. :)

I think you got what I am trying to do.  In a couple sentences:

I want to unit test bundles. I want those unit tests to run the same way normal unit tests of simple methods and classes are run as perceived by the user when issuing a 'mvn install' for example.

Greetings, Marcel

Thanks much!
Alex


On Aug 13, 2006, at 7:01 , Alex Karasulu wrote:

I've been trying to figure out a way to tell Felix how to programmatically install and start bundles. My goal is to build a simple mojo for our maven 2 plugin that will allow us to install and start a bundle produced by a project using Felix. This idea is to use a command like so:

mvn osgi:run

This will trigger the mojo to startup Felix, install and start the target bundle generated by the project including any dependent bundles.

My problem is in navigating the Felix API. I would like to avoid using the configuration file all together and just use the API. What I've done is extended Felix and exposed the protected installBundle method. Next I called it to get a handle on a Bundle and called start() on it. Here's how that code looks ...

in = new FileInputStream( "/home/akarasulu/test-bundle-1.0.0-SNAPSHOT.jar" ); b = instance.installBundle( "file:///home/akarasulu/test-bundle-1.0.0-SNAPSHOT.jar", in );
    b.start();

Instance is the instance of the Felix subclass. When I do this I get a ClassCastException on the BundleActivator in this simple bundle which just prints Hello World. The bundle starts just fine in Felix running in standard command line mode. I'm just wondering what I'm doing wrong. Any hints or suggestions on what I'm botching up would be great.

Here's the stack trace that I get:

Exception in thread "main" org.osgi.framework.BundleException: Activator start error.
        at org.apache.felix.framework.Felix._startBundle(Felix.java:1261)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1149)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:326)
        at FelixTestDriver.main(FelixTestDriver.java:65)
Caused by: java.lang.ClassCastException: test.Activator
at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:2702)
        at org.apache.felix.framework.Felix._startBundle(Felix.java:1203)
        ... 3 more


Thanks,
Alex



Reply via email to