Question

Its been a while since im struggling with this, so i decided to post the question here.

What I wanna do its just create some unit tests for my rest services. Im not having a specific error, given i changed my implementations thousands of times, thats why im not showing any code here.

Im using Apache Felix as OSGI implementation so I would like to load the beans definitions in my unit test and mock some of them. Im not sure which should be the service container, so any example is welcome.

Thanks in advance

Was it helpful?

Solution

Here is one: https://github.com/everit-org/osgi-remote-jersey

See the readme for details, how the extender works.

Tests are placed into the tests module. If we run "mvn install", first an equinox than a felix environment is started with a random jetty port. The tests run on these OSGi containers.

If you want to check the content of the container, you can

  • Go to tests/target/eosgi-dist/felixtest/bin directory
  • start runConsole.sh (or runConsole.bat on windows)
  • Check the log where the Jetty server is started (or write a fix port in the pom.xml)
  • Open the webconsole at localhost:port/system/console while the container is running

If you opened the modules in eclipse as a maven project, you can Drag&Drop your projects from Eclipse project explorer to the always-on-top deployer window that appears after the container is started.

If you add/remove dependencies in the tests, you can

  • Check the number that appears on the deployer window (the port where the deployer listens). This will be the port
  • Run "mvn eosgi:dist -Deosgi.servicePort=port"

OTHER TIPS

Here's another example: https://bitbucket.org/amdatu/amdatu-web/src

It is the source code for the web components, one of which is a REST implementation. The source includes tests that run in an OSGi framework and test REST endpoints. The whole project should be run in Eclipse with the Bndtools plugin.

If you want to learn more about the components themselves:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top