I have a component that has a plugin style array of optionally required 
services:

        @Requires(optional=true)
        Plugin plugins[];

I'm trying to write a unit test for the component and I'm having problems 
understanding how to implement the dependencies so that iPojo is happy during a 
maven build. Because I want iPojo to handle the "dynamisism" I did not 
implement bind/unbind methods to populate the array which leads to a problem 
when unit testing as there is no way to populate plugin dependencies.

I then created a constructor for initializing the array in tests:

        public TheComponent() { }

        public TheComponent(Plugin... plugins) {
                this.plugins = plugins;
        }

and in my test code call something like:

        TheComponent theComponent = new TheComponent(plugin1, plugin2);

but now iPojo complains that there is no iPojoInstanceManager for that 
constructor. Is there a way I can use that constructor for injecting 
dependencies during the tests?

I have also tried to Mock the component using Mockito and receive the following 
when building:
Caused by: java.lang.ClassNotFoundException: org.apache.felix.ipojo.Pojo
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:315)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:330)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

Both the constructor and mocking work fine when I run the tests manually, it is 
only when building with the maven ipojo plugin that I get these failures.

Thanks,
David Allen
CTO & Co-Founder
veloGraf Systems
d...@velograf.com




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to