felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1536059 - in /felix/trunk/scr/src/test/java/org/apache/felix/scr/integration: ComponentFactoryTest.java ComponentTestBase.java
Date Sun, 27 Oct 2013 06:59:31 GMT
Author: djencks
Date: Sun Oct 27 06:59:30 2013
New Revision: 1536059

URL: http://svn.apache.org/r1536059
Log:
FELIX-4293 test for location changed event with null properties.  Be sure to run with -PcaR5,felix

Modified:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java?rev=1536059&r1=1536058&r2=1536059&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
Sun Oct 27 06:59:30 2013
@@ -35,6 +35,7 @@ import org.ops4j.pax.exam.junit.JUnit4Te
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentConstants;
 import org.osgi.service.component.ComponentException;
 import org.osgi.service.component.ComponentFactory;
@@ -55,7 +56,6 @@ public class ComponentFactoryTest extend
 //        paxRunnerVmOption = DEBUG_VM_OPTION;
     }
 
-
     @Test
     public void test_component_factory() throws InvalidSyntaxException
     {
@@ -624,5 +624,48 @@ public class ComponentFactoryTest extend
         s2.drop();
         s1.drop();
     }
+    
+    @Test
+    public void test_component_factory_set_bundle_location_null() throws Exception
+    {
+        final String componentfactory = "factory.component.reference.targetfilter";
+        final Component component = findComponentByName( componentfactory );
+
+        TestCase.assertNotNull( component );
+        TestCase.assertFalse( component.isDefaultEnabled() );
+
+        TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+        TestCase.assertNull( SimpleComponent.INSTANCE );
+
+        component.enable();
+        delay();
+
+        SimpleServiceImpl s1 = SimpleServiceImpl.create(bundleContext, "service1");
+
+        ConfigurationAdmin ca = getConfigurationAdmin();
+        org.osgi.service.cm.Configuration config = ca.getConfiguration( componentfactory,
null );
+        config.setBundleLocation( null );
+        delay();
+        if ( isAtLeastR5() )
+        {
+            //check that ConfigurationSupport got a Location changed event and set the bundle
location
+            TestCase.assertNotNull( config.getBundleLocation() );
+        } 
+        // supply configuration now and ensure active
+        configure( componentfactory );
+        delay();        
+
+        TestCase.assertEquals( Component.STATE_FACTORY, component.getState() );
+        TestCase.assertNull( SimpleComponent.INSTANCE );
+        
+        final ServiceReference[] refs = bundleContext.getServiceReferences( ComponentFactory.class.getName(),
"("
+            + ComponentConstants.COMPONENT_FACTORY + "=" + componentfactory + ")" );
+        TestCase.assertNotNull( refs );
+        TestCase.assertEquals( 1, refs.length );
+        final ComponentFactory factory = ( ComponentFactory ) bundleContext.getService( refs[0]
);
+        TestCase.assertNotNull( factory );
+        
+        s1.drop();
+    }
 
 }

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=1536059&r1=1536058&r2=1536059&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
(original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
Sun Oct 27 06:59:30 2013
@@ -39,6 +39,7 @@ import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -583,6 +584,23 @@ public abstract class ComponentTestBase
             }
         }
     }
+    
+    protected boolean isAtLeastR5() 
+    {
+        try
+        {
+            Method m = org.osgi.service.cm.Configuration.class.getDeclaredMethod( "getChangeCount");
+            return true;
+        }
+        catch ( SecurityException e )
+        {
+            throw new RuntimeException(e);
+        }
+        catch ( NoSuchMethodException e )
+        {
+            return false;
+        }
+    }
 
     private String toStateString( int state )
     {



Mime
View raw message