Hello again,

Sorry for the big mess below, I tried to describe something that surely wasn't 
clear to me, first of all.

I'll try it again here:

I need to test that a component reacts properly according to a given 
configuration, and for that I think I need something like Pax ConfMan.
So after some attempts I came out with a test like this:

import static org.junit.Assert.assertNotNull;
import static org.ops4j.pax.exam.CoreOptions.*;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.service.cm.ConfigurationAdmin;

@RunWith( JUnit4TestRunner.class )
public class ConfigurationTest {

    @Configuration
    public static Option[] configuration() {
        return options(felix(),
                       mavenConfiguration(),
                       mavenBundle("org.ops4j.pax.confman", 
"pax-confman-propsloader", "0.2.2").startLevel(10));
    }

    @Test
    public void shouldHaveConfigAdminServiceRegistered( BundleContext 
bundleContext ) throws Exception {

        final String CONFIG_ADMIN_NAME = ConfigurationAdmin.class.getName();
        ServiceReference sr = 
bundleContext.getServiceReference(CONFIG_ADMIN_NAME);

        assertNotNull(sr);
    }
}


Now... the test fails; why? I can guess two (maybe more) not mutually exclusive 
points of failure:
1) The configuration is wrong
2) The assertion is wrong

Any hint?

Thanks again,
Ale


On Jan 18, 2011, at 4:57 PM, Alessandro Novarini wrote:

> Hello list,
> 
> I've spent all day trying to figure out how to test this portion of class; 
> without going too deep into details, I would like to know how you usually 
> test (if you test it) the method
> 
> protected void activate(ComponentContext componentContext)
> 
> I read from its JavaDoc that this method is called when a configuration for 
> the component is found.
> How do you create a configuration for the bundle? Is this the way to test it?
> 
> In our project, this method is in a base class, and it calls another 
> protected method in the actual class under test.
> Basically, I need to inject in some way parameters read using 
> componentContext.getProperties() and then do some operations.
> Do you set the componentContext (field of the base class) with reflection?
> 
> Thanks in advance
> Ale
> 

_______________________________________________
general mailing list
general@lists.ops4j.org
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to