Author: djencks
Date: Fri Oct 25 07:04:03 2013
New Revision: 1535647

URL: http://svn.apache.org/r1535647
Log:
FELIX-4290 Commit a slightly simpler fix than Pierre proposed and his test, 
moved into the existing ComponentFactory test class

Modified:
    felix/trunk/scr/changelog.txt
    
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
    
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
    
felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml

Modified: felix/trunk/scr/changelog.txt
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/changelog.txt?rev=1535647&r1=1535646&r2=1535647&view=diff
==============================================================================
--- felix/trunk/scr/changelog.txt (original)
+++ felix/trunk/scr/changelog.txt Fri Oct 25 07:04:03 2013
@@ -43,6 +43,7 @@ Changes from 1.6.2 to 1.8
     * [FELIX-4223] - [DS] DependencyManager filter should be set up in enable, 
not activate, to avoid race conditions
     * [FELIX-4224] - [DS] Dependency manager can be active but not have 
m_bindMethods set
     * [FELIX-4287] - [DS] NPE when calling ComponentInstance.dispose after 
bundle shut down
+    * [FELIX-4290] - [DS] Issue with factory components with required 
configuration
 
 ** Task
     * [FELIX-3584] - [DS] Handle new LOCATION_CHANGED event

Modified: 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java?rev=1535647&r1=1535646&r2=1535647&view=diff
==============================================================================
--- 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
 (original)
+++ 
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/manager/ComponentFactoryImpl.java
 Fri Oct 25 07:04:03 2013
@@ -374,7 +374,7 @@ public class ComponentFactoryImpl<S> ext
                 log( LogService.LOG_INFO, "Verifying if Active Component 
Factory is still satisfied", null );
 
                 // First update target filters.
-                super.updateTargets( getProperties() );
+                updateTargets( getProperties() );
 
                 // Next, verify dependencies
                 if ( !verifyDependencyManagers() )
@@ -392,6 +392,8 @@ public class ComponentFactoryImpl<S> ext
             {
                 // try to activate our component factory, if all dependnecies 
are satisfied
                 log( LogService.LOG_DEBUG, "Attempting to activate unsatisfied 
component", null );
+                // First update target filters.
+                updateTargets( getProperties() );
                 activateInternal( getTrackingCount().get() );
             }
         }

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=1535647&r1=1535646&r2=1535647&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
 Fri Oct 25 07:04:03 2013
@@ -39,6 +39,7 @@ import org.osgi.service.component.Compon
 import org.osgi.service.component.ComponentException;
 import org.osgi.service.component.ComponentFactory;
 import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.log.LogService;
 
 
 @RunWith(JUnit4TestRunner.class)
@@ -570,4 +571,58 @@ public class ComponentFactoryTest extend
         TestCase.assertEquals( Component.STATE_UNSATISFIED, 
referringComponent.getState() );
     }
 
+    @Test
+    public void test_component_factory_with_target_filters() throws 
InvalidSyntaxException
+    {
+        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");
+        SimpleServiceImpl s2 = SimpleServiceImpl.create(bundleContext, 
"service2");
+
+        // 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 );
+
+        Hashtable<String, String> props = new Hashtable<String, String>();
+        props.put( PROP_NAME_FACTORY, PROP_NAME_FACTORY );
+        props.put("ref.target", "(value=service2)");
+        final ComponentInstance instance = factory.newInstance( props );
+        TestCase.assertNotNull( instance );
+
+        TestCase.assertNotNull( instance.getInstance() );
+        TestCase.assertEquals( SimpleComponent.INSTANCE, 
instance.getInstance() );
+        TestCase.assertEquals( PROP_NAME_FACTORY, 
SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
+
+        log.log(LogService.LOG_WARNING, "Bound Services: " +  
SimpleComponent.INSTANCE.m_multiRef);
+        TestCase.assertFalse( SimpleComponent.INSTANCE.m_multiRef.contains( s1 
) );
+        TestCase.assertTrue( SimpleComponent.INSTANCE.m_multiRef.contains( s2 
) );
+
+        instance.dispose();
+        TestCase.assertNull( SimpleComponent.INSTANCE );
+        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
+        
+        s2.drop();
+        s1.drop();
+    }
+
 }

Modified: 
felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml
URL: 
http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml?rev=1535647&r1=1535646&r2=1535647&view=diff
==============================================================================
--- 
felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml
 (original)
+++ 
felix/trunk/scr/src/test/resources/integration_test_simple_factory_components.xml
 Fri Oct 25 07:04:03 2013
@@ -78,4 +78,20 @@
         />
     </scr:component>
 
+    <!-- Component Factory Instance, requiring configuration + 1 specific 
Reference -->
+    <scr:component name="factory.component.reference.targetfilter"
+        enabled="false"
+        configuration-policy="require"
+        factory="factory.component.reference.targetfilter" >
+        <implementation 
class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <reference
+            name="ref"
+            
interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="1..1"
+            policy="dynamic"
+            bind="bindSimpleService"
+            unbind="unbindSimpleService"
+        />
+    </scr:component>
+
 </components>


Reply via email to