Hi all,
I really feel confused about how a bundle get a service in the pax_exam??

I have two bundles, one publish a service or registry a service into Service
Registration and the other bundle want to get the service using the
following code:

        MbeanInfoManager tracker = new ServiceTracker(context,
MbeanInfoManager.class.getName(), null);
        tracker.open();
      // grab the service
        manager = (MbeanInfoManager) tracker.getService();

where MbeanInfoManager is the service.I put the two bundles into the OSGi
,and the service can be tracked.

Now I want to make some integration test using pax_exam, so my integration
test code will be like this:
import static org.ops4j.pax.exam.CoreOptions.bundle;
import static org.ops4j.pax.exam.CoreOptions.equinox;
import static org.ops4j.pax.exam.CoreOptions.frameworks;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.options;
import static org.ops4j.pax.exam.CoreOptions.provision;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Inject;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.Configuration;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@RunWith( JUnit4TestRunner.class )
public class TestSth {
    @Inject
    private BundleContext bundleContext;
    @Configuration
    public static Option[] configuration()
    {
        return options(
            frameworks(
                equinox()
            ),
            provision(

                bundle(
"file:E:/tmp/plugins/MbeanInfoManagerNew_1.0.0.200911061110.jar" ),
                bundle( "file:E:/tmp/plugins/MbeanInfoManagerTest.jar" )
              )

        );
    }

    @Test
    public void test()throws Exception{

        Bundle testBundle=getInstalledBundle("MbeanInfoManagerTest");
        if(testBundle!=null){
            System.out.println("Starting....");
            testBundle.start();
        }


    }
    public Bundle getInstalledBundle(String name){
        Bundle[] bundles=bundleContext.getBundles();
        for(Bundle bundle:bundles){
            if(bundle.getSymbolicName().equals(name)){
                return bundle;
            }
        }
        return null;
    }
}

now i can not get the service which has been registry int the service
registration.

why?
pls help me figure it out

Thank you very much


-- 
Best Regards
Ben Liang
_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to