Another option for running tests in an OSGi framework is to use bnd and/or bndtools. You can set up the test easily using the bnd file, the tool will then launch the framework and install all the bundles for you. Bndtools is used extensively for OSGi development, and a guide to using bndtools is here:
http://bndtools.org/tutorial.html Regards, Tim On 7 Mar 2014, at 14:17, Thomas Joseph <[email protected]> wrote: > Hi Christine > > You are not able to get bundle reference, because JUnit does not run on a > OSGi container natively. You can look at PAX Exam > https://ops4j1.jira.com/wiki/display/PAXEXAM3/Pax+Exam which will help you > write integration (JUnit) tests for OSGi framework. > > > > On Thu, Feb 27, 2014 at 7:54 AM, <[email protected]> wrote: > Hi there, > > > > Don’t know if user’s question can be asked in this mailing list. If not, > would you let me know the correct mailing list, thanks! > > > > > > I have the following problem, anyone can help…? > > > > In TestA.java: > > > > @Before > > Public void before() throws Exception > > ModuleB objB = new ModuleB(); > > objB.init(); > > } > > > > > > In ModuleB.java: > > > > import org.osgi.framework.FrameworkUtil; > > public void init() { > > registerWithOSGIConsole() > > } > > > > private void registerWithOSGIConsole() { > > BundleContext bundleContext = > > FrameworkUtil.getBundle(this.getClass()).getBundleContext(); > > } > > > > I proceed the JUnit test by executing “mvn clean install”, then in the output > we know that: > > “FrameworkUtil.getBundle(this.getClass())” returns Null so that an error > occurs here. > > > > TestA.java is just used for testing, I write many test functions in it. > > ModuleB.java is one of the modules of an OSGi bundle I wrote (say, > BundleC.jar). > > > > In OGSi, the BundleC.jar can be installed and activated successfully and > ModuleB’s init() would be automatically called. > > That is, FrameworkUtil.getBundle(this.getClass())’s return value is not Null. > > > > So, what should I do to make FrameworkUtil.getBundle() successful when JUnit > testing? > > Or did I do anything wrong? > > > > Thanks! > > Christine > > > > > > 本信件可能包含工研院機密資訊,非指定之收件者,請勿使用或揭露本信件內容,並請銷毀此信件。 > This email may contain confidential information. Please do not use or > disclose it in any way and delete it if you are not the intended recipient. > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev > > > > -- > Thanks and Regards, > /Thomas Joseph > > LinkedIn: http://www.linkedin.com/in/ethomasjoseph > Twitter: http://twitter.com/ethomasjoseph > > ------------------------------------------------------------ > Promote Open Source - Promote Liberty of Ideas and Software. > ------------------------------------------------------------ > _______________________________________________ > OSGi Developer Mail List > [email protected] > https://mail.osgi.org/mailman/listinfo/osgi-dev
_______________________________________________ OSGi Developer Mail List [email protected] https://mail.osgi.org/mailman/listinfo/osgi-dev
