You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by fm...@apache.org on 2009/07/31 16:44:12 UTC

svn commit: r799625 - in /felix/trunk/scr/src/test: java/org/apache/felix/scr/integration/ComponentConfigurationTest.java resources/integration_test_simple_components.xml

Author: fmeschbe
Date: Fri Jul 31 14:44:12 2009
New Revision: 799625

URL: http://svn.apache.org/viewvc?rev=799625&view=rev
Log:
FELIX-1232 Add integration test ensuring private component
property is visible to the component but not to service
consumers

Modified:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
    felix/trunk/scr/src/test/resources/integration_test_simple_components.xml

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java?rev=799625&r1=799624&r2=799625&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentConfigurationTest.java Fri Jul 31 14:44:12 2009
@@ -52,6 +52,7 @@
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Constants;
 import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.util.tracker.ServiceTracker;
 
@@ -63,6 +64,8 @@
     @Inject
     private BundleContext bundleContext;
 
+    private Bundle bundle;
+
     private ServiceTracker scrTracker;
 
     private ServiceTracker configAdminTracker;
@@ -80,13 +83,10 @@
     @Configuration
     public static Option[] configuration()
     {
-        return options(
-            provision(
-                scanDir( "target" ).filter( "*.jar" )
-                , mavenBundle( "org.ops4j.pax.swissbox", "pax-swissbox-tinybundles", "1.0.0" )
-                , mavenBundle( "org.apache.felix", "org.apache.felix.configadmin", "1.0.10" )
-            )
-//            , PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
+        return options( provision( scanDir( "target" ).filter( "*.jar" ), mavenBundle( "org.ops4j.pax.swissbox",
+            "pax-swissbox-tinybundles", "1.0.0" ), mavenBundle( "org.apache.felix", "org.apache.felix.configadmin",
+            "1.0.10" ) )
+        //            , PaxRunnerOptions.vmOption( "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=30303" )
         //            PaxRunnerOptions.timeout( 0 )
 
         );
@@ -94,18 +94,32 @@
 
 
     @Before
-    public void setUp()
+    public void setUp() throws BundleException
     {
         scrTracker = new ServiceTracker( bundleContext, ScrService.class.getName(), null );
         scrTracker.open();
         configAdminTracker = new ServiceTracker( bundleContext, ConfigurationAdmin.class.getName(), null );
         configAdminTracker.open();
+
+        //        final InputStream bundleStream = newBundle()
+        final InputStream bundleStream = new MyTinyBundle().addResource( "OSGI-INF/components.xml",
+            getClass().getResource( "/integration_test_simple_components.xml" ) ).prepare(
+            withBnd().set( Constants.BUNDLE_SYMBOLICNAME, "simplecomponent" ).set( Constants.BUNDLE_VERSION, "0.0.11" )
+                .set( Constants.IMPORT_PACKAGE, "org.apache.felix.scr.integration.components" ).set(
+                    "Service-Component", "OSGI-INF/components.xml" ) ).build( TinyBundles.asStream() );
+
+        bundle = bundleContext.installBundle( "test:SimpleComponent", bundleStream );
+
+        bundle.start();
     }
 
 
     @After
-    public void tearDown()
+    public void tearDown() throws BundleException
     {
+        bundle.stop();
+        bundle.uninstall();
+
         configAdminTracker.close();
         configAdminTracker = null;
         scrTracker.close();
@@ -114,37 +128,44 @@
 
 
     @Test
-    public void test_SimpleComponent() throws BundleException
+    public void test_SimpleComponent_configuration_ignore()
     {
-        //        final InputStream bundleStream = newBundle()
-        final InputStream bundleStream = new MyTinyBundle()
-            .addResource( "OSGI-INF/components.xml", getClass().getResource( "/integration_test_simple_components.xml" ) )
-            .prepare(
-                withBnd()
-                .set( Constants.BUNDLE_SYMBOLICNAME, "simplecomponent" )
-                .set( Constants.BUNDLE_VERSION, "0.0.11" )
-                .set( Constants.IMPORT_PACKAGE, "org.apache.felix.scr.integration.components" )
-                .set( "Service-Component", "OSGI-INF/components.xml" ) ).build( TinyBundles.asStream() );
+        test_configuration_ignore( "SimpleComponent" );
+    }
 
-        final Bundle bundle = bundleContext.installBundle( "test:SimpleComponent", bundleStream );
 
-        bundle.start();
+    @Test
+    public void test_SimpleComponent_configuration_optional()
+    {
+        test_configuration_optional( "SimpleComponent" );
+    }
 
-        try
-        {
-            test_configuration_ignore( "SimpleComponent" );
-            test_configuration_optional( "SimpleComponent" );
-            test_configuration_require( "SimpleComponent" );
 
-            test_dynamic_configuration( "DynamicConfigurationComponent" );
+    @Test
+    public void test_SimpleComponent_configuration_require()
+    {
+        test_configuration_require( "SimpleComponent" );
+    }
 
-            test_factory_configuration( "FactoryConfigurationComponent" );
-        }
-        finally
-        {
-            bundle.stop();
-            bundle.uninstall();
-        }
+
+    @Test
+    public void test_SimpleComponent_dynamic_configuration()
+    {
+        test_dynamic_configuration( "DynamicConfigurationComponent" );
+    }
+
+
+    @Test
+    public void test_SimpleComponent_factory_configuration()
+    {
+        test_factory_configuration( "FactoryConfigurationComponent" );
+    }
+
+
+    @Test
+    public void test_SimpleComponent_service()
+    {
+        test_service( "ServiceComponent" );
     }
 
 
@@ -388,7 +409,7 @@
         delay();
 
         // expect a single unsatisifed component
-        final Component[] configsDeleted= findComponentsByName( factoryPid );
+        final Component[] configsDeleted = findComponentsByName( factoryPid );
         TestCase.assertNotNull( configsDeleted );
         TestCase.assertEquals( 1, configsDeleted.length );
         TestCase.assertEquals( Component.STATE_UNSATISFIED, configsDeleted[0].getState() );
@@ -399,6 +420,52 @@
     }
 
 
+    private void test_service( final String componentName )
+    {
+        final String pid = componentName;
+
+        // one single component exists without configuration
+        final Component component = findComponentByName( pid );
+        TestCase.assertNotNull( component );
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+        component.enable();
+        delay();
+
+        final SimpleComponent instance = SimpleComponent.INSTANCE;
+        TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+        TestCase.assertNotNull( instance );
+
+        // assert component properties (all !)
+        TestCase.assertEquals( "required", instance.getProperty( "prop.public" ) );
+        TestCase.assertEquals( "private", instance.getProperty( ".prop.private" ) );
+
+        // get the service
+        ServiceReference reference = bundleContext.getServiceReference( "java.lang.Object" );
+        TestCase.assertNotNull( reference );
+        try
+        {
+            TestCase.assertEquals( instance, bundleContext.getService( reference ) );
+        }
+        finally
+        {
+            bundleContext.ungetService( reference );
+        }
+
+        // check service properties
+        TestCase.assertEquals( "required", reference.getProperty( "prop.public" ) );
+        TestCase.assertNull( reference.getProperty( ".prop.private" ) );
+
+        // check property keys do not contain private keys
+        for ( String propKey : reference.getPropertyKeys() )
+        {
+            TestCase.assertTrue( "Property key [" + propKey
+                + "] must have at least one character and not start with a dot", propKey.length() > 0
+                && !propKey.startsWith( "." ) );
+        }
+    }
+
+
     private Component findComponentByName( String name )
     {
         ScrService scr = ( ScrService ) scrTracker.getService();

Modified: felix/trunk/scr/src/test/resources/integration_test_simple_components.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_simple_components.xml?rev=799625&r1=799624&r2=799625&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_simple_components.xml (original)
+++ felix/trunk/scr/src/test/resources/integration_test_simple_components.xml Fri Jul 31 14:44:12 2009
@@ -52,4 +52,17 @@
         configuration-policy="require" >
         <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
     </scr:component>
+
+    <!-- component is a stupid service to verify non-use of private props -->
+    <scr:component name="ServiceComponent"
+        enabled="false" immediate="true"
+        configuration-policy="ignore" >
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <property name="prop.public" value="required" />
+        <property name=".prop.private" value="private" />
+        <service>
+            <provide interface="java.lang.Object" />
+        </service>
+    </scr:component>
+
 </components>