FELIX-4585 fix component factory disable

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1615283 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java b/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java
index 4215670..f3ab4bf 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java
@@ -182,7 +182,7 @@
 
     private static List<SingleComponentManager> getComponentManagers( ConfigurableComponentHolder holder )
     {
-    	return holder.getComponentManagers(false);
+    	return holder.getComponentManagers();
     }
 
     private static class TestingConfiguredComponentHolder extends ConfigurableComponentHolder
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentEnableTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentEnableTest.java
new file mode 100644
index 0000000..00b6304
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentEnableTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.integration;
+
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.Map;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.felix.scr.integration.components.EnableComponent;
+import org.apache.felix.scr.integration.components.SimpleComponent;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+
+
+@RunWith(JUnit4TestRunner.class)
+public class ComponentEnableTest extends ComponentTestBase
+{
+    static
+    {
+        // uncomment to enable debugging of this test class
+        // paxRunnerVmOption = DEBUG_VM_OPTION;
+        descriptorFile = "/integration_test_enable.xml";
+    }
+
+
+    @Test
+    public void test_Component_Enable() throws Exception
+    {
+        final String enable = "org.apache.felix.scr.integration.components.enable";
+        final String name = "org.apache.felix.scr.integration.components.SimpleComponent";
+        
+        ComponentConfigurationDTO dto = findComponentConfigurationByName(enable, ComponentConfigurationDTO.SATISFIED);
+        
+        EnableComponent ec = getServiceFromConfiguration(dto, EnableComponent.class);
+        
+        TestCase.assertEquals(0, SimpleComponent.INSTANCES.size());
+
+        ec.enable(name);
+        delay();
+        TestCase.assertEquals(1, SimpleComponent.INSTANCES.size());
+        ec.enable(name);
+        delay();
+        TestCase.assertEquals(1, SimpleComponent.INSTANCES.size());
+
+    }
+
+
+}
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
index 76d540b..fa9abbb 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentFactoryTest.java
@@ -167,20 +167,15 @@
 
         checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
 
-        // delete config, ensure factory is not active anymore and component instance not changed
+        // delete config, ensure factory is not active anymore and component instance gone 
+        //(configuration required >> dispose of instance.  Also for pre-1.3 components, removing config unconditionally
+        //deactivates component.
         deleteConfig( componentname );
         delay();
         checkNoFactory(componentfactory);
 
-        TestCase.assertNotNull( instance.getInstance() );
-        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
-        TestCase.assertEquals( instanceObject, instance.getInstance() );
-        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
-        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
-
-        instance.dispose();
-        TestCase.assertNull( SimpleComponent.INSTANCE ); // component is deactivated
-        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
+        TestCase.assertNull( instance.getInstance() );
+        TestCase.assertNull( SimpleComponent.INSTANCE );
 
         // with removal of the factory, the created instance should also be removed
         checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java b/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
index e435e57..7c41a50 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/PersistentComponentFactoryTest.java
@@ -163,23 +163,16 @@
 
         checkConfigurationCount(componentname, 1, ComponentConfigurationDTO.ACTIVE);
 
-        // delete config, ensure factory is not active anymore and component instance not changed
+        // delete config, ensure factory is not active anymore and component instance dropped (config required)
         deleteConfig( componentname );
         delay();
         checkNoFactory(componentfactory);
 
-        TestCase.assertNotNull( instance.getInstance() );
-        TestCase.assertEquals( SimpleComponent.INSTANCE, instance.getInstance() );
-        TestCase.assertEquals( instanceObject, instance.getInstance() );
-        TestCase.assertEquals( PROP_NAME_FACTORY, SimpleComponent.INSTANCE.getProperty( PROP_NAME_FACTORY ) );
-        TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
-
-        instance.dispose();
-        TestCase.assertNull( SimpleComponent.INSTANCE ); // component is deactivated
-        TestCase.assertNull( instance.getInstance() ); // SCR 112.12.6.2
+        TestCase.assertNull( instance.getInstance() );
+        TestCase.assertNull( SimpleComponent.INSTANCE );
 
         // with removal of the factory, the created instance should also be removed
-        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.ACTIVE);
+        checkConfigurationCount(componentname, 0, ComponentConfigurationDTO.UNSATISFIED);
     }
 
 
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/components/EnableComponent.java b/scr/src/test/java/org/apache/felix/scr/integration/components/EnableComponent.java
new file mode 100644
index 0000000..cf4c7ab
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/integration/components/EnableComponent.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.scr.integration.components;
+
+import org.osgi.service.component.ComponentContext;
+
+public class EnableComponent
+{
+    
+    private ComponentContext cc;
+    
+    protected void activate(ComponentContext cc)
+    {
+        this.cc = cc;
+    }
+    
+    protected void deactivate()
+    {
+        cc = null;
+    }
+    
+    public void enable( String component )
+    {
+        cc.enableComponent(component);
+    }
+
+    public void disable( String component )
+    {
+        cc.disableComponent(component);
+    }
+
+}
diff --git a/scr/src/test/resources/integration_test_enable.xml b/scr/src/test/resources/integration_test_enable.xml
new file mode 100644
index 0000000..78ef87a
--- /dev/null
+++ b/scr/src/test/resources/integration_test_enable.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+	license agreements. See the NOTICE file distributed with this work for additional 
+	information regarding copyright ownership. The ASF licenses this file to 
+	you under the Apache License, Version 2.0 (the "License"); you may not use 
+	this file except in compliance with the License. You may obtain a copy of 
+	the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required 
+	by applicable law or agreed to in writing, software distributed under the 
+	License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS 
+	OF ANY KIND, either express or implied. See the License for the specific 
+	language governing permissions and limitations under the License. -->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+	<scr:component
+		name='org.apache.felix.scr.integration.components.enable'
+		>
+		<implementation
+			class='org.apache.felix.scr.integration.components.EnableComponent' />
+		<service>
+			<provide interface='org.apache.felix.scr.integration.components.EnableComponent' />
+		</service>
+	</scr:component>
+
+	<scr:component
+		name='org.apache.felix.scr.integration.components.SimpleComponent'
+		enabled="false">
+		<implementation
+			class='org.apache.felix.scr.integration.components.SimpleComponent' />
+	</scr:component>
+
+</components>
diff --git a/scr/src/test/resources/integration_test_persistent_factory_components.xml b/scr/src/test/resources/integration_test_persistent_factory_components.xml
index 816e0b1..141820c 100644
--- a/scr/src/test/resources/integration_test_persistent_factory_components.xml
+++ b/scr/src/test/resources/integration_test_persistent_factory_components.xml
@@ -33,7 +33,8 @@
         felix:persistentFactoryComponent="true"
         enabled="false"
         configuration-policy="require"
-        factory="factory.component.factory.configuration" >
+        factory="factory.component.factory.configuration" 
+        modified="modified">
         <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
     </scr:component>
     
diff --git a/scr/src/test/resources/integration_test_simple_factory_components.xml b/scr/src/test/resources/integration_test_simple_factory_components.xml
index 6ee6611..e8e9576 100644
--- a/scr/src/test/resources/integration_test_simple_factory_components.xml
+++ b/scr/src/test/resources/integration_test_simple_factory_components.xml
@@ -31,7 +31,8 @@
     <scr:component name="factory.component.configuration"
         enabled="false"
         configuration-policy="require"
-        factory="factory.component.factory.configuration" >
+        factory="factory.component.factory.configuration"
+        modified="modified" >
         <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
     </scr:component>