FELIX-3754 Add tests for delayed and service factory service components
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1409819 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java b/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java
index a6d7d53..8d78003 100644
--- a/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/integration/ComponentActivationTest.java
@@ -26,6 +26,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.ServiceReference;
@RunWith(JUnit4TestRunner.class)
@@ -213,4 +214,62 @@
delay();
TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
}
+
+
+ @Test
+ public void test_activate_register_service_delayed()
+ {
+ final String componentname = "ActivatorComponent.activate.delayed.with.bind";
+
+ final Component component = findComponentByName( componentname );
+
+ TestCase.assertNotNull( component );
+ TestCase.assertFalse( component.isDefaultEnabled() );
+
+ TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+ component.enable();
+ delay();
+
+ TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+
+ ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference( ActivatorComponent.class );
+ ActivatorComponent ac = bundleContext.getService( ref );
+ TestCase.assertNotNull( ac.getSimpleService() );
+
+ TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+
+ component.disable();
+
+ delay();
+ TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ }
+ @Test
+ public void test_activate_service_factory_register_service()
+ {
+ final String componentname = "ActivatorComponent.activate.service.factory.with.bind";
+
+ final Component component = findComponentByName( componentname );
+
+ TestCase.assertNotNull( component );
+ TestCase.assertFalse( component.isDefaultEnabled() );
+
+ TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+
+ component.enable();
+ delay();
+
+ TestCase.assertEquals( Component.STATE_REGISTERED, component.getState() );
+
+ ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference( ActivatorComponent.class );
+ ActivatorComponent ac = bundleContext.getService( ref );
+ TestCase.assertNotNull( ac.getSimpleService() );
+
+ TestCase.assertEquals( Component.STATE_ACTIVE, component.getState() );
+
+ component.disable();
+
+ delay();
+ TestCase.assertEquals( Component.STATE_DISABLED, component.getState() );
+ }
}
diff --git a/scr/src/test/resources/integration_test_activation_components.xml b/scr/src/test/resources/integration_test_activation_components.xml
index a3026e8..ddf8ba4 100644
--- a/scr/src/test/resources/integration_test_activation_components.xml
+++ b/scr/src/test/resources/integration_test_activation_components.xml
@@ -87,4 +87,44 @@
cardinality="0..n"
/>
</scr:component>
+
+ <!-- bind service during activate -->
+ <scr:component name="ActivatorComponent.activate.delayed.with.bind"
+ enabled="false"
+ activate="myActivate"
+ deactivate="myDeactivate">
+ <implementation class="org.apache.felix.scr.integration.components.ActivatorComponent" />
+ <service factory="false">
+ <provide interface="org.apache.felix.scr.integration.components.ActivatorComponent"/>
+ </service>
+ <property name="registerService" value="true" />
+ <reference
+ name="service"
+ interface="org.apache.felix.scr.integration.components.SimpleService"
+ bind="bindSimpleService"
+ unbind="unbindSimpleService"
+ policy="dynamic"
+ cardinality="0..n"
+ />
+ </scr:component>
+
+ <!-- bind service during activate -->
+ <scr:component name="ActivatorComponent.activate.service.factory.with.bind"
+ enabled="false"
+ activate="myActivate"
+ deactivate="myDeactivate">
+ <implementation class="org.apache.felix.scr.integration.components.ActivatorComponent" />
+ <service factory="true">
+ <provide interface="org.apache.felix.scr.integration.components.ActivatorComponent"/>
+ </service>
+ <property name="registerService" value="true" />
+ <reference
+ name="service"
+ interface="org.apache.felix.scr.integration.components.SimpleService"
+ bind="bindSimpleService"
+ unbind="unbindSimpleService"
+ policy="dynamic"
+ cardinality="0..n"
+ />
+ </scr:component>
</components>