FELIX-3524: Added test_get_configuration_pid_method in order to validate that
ComponentMetadata.getConfigurationPid() never returns null if configuration-pid
is not specified in the component declaration.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1346815 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java b/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
index 8dafdf8..e8fd9e1 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
@@ -724,6 +724,53 @@
         }
     }
 
+    public void test_get_configuration_pid_method()
+    {
+        doTest_get_configuration_pid_method(XmlHandler.DS_VERSION_1_0);
+        doTest_get_configuration_pid_method(XmlHandler.DS_VERSION_1_1);
+        doTest_get_configuration_pid_method(XmlHandler.DS_VERSION_1_2);
+    }
+    
+    private void doTest_get_configuration_pid_method(int specVersion)
+    {            
+        // Make sure that getConfigurationPid returns the default component name (implementation class name).
+        // We only do this kind of test if spec is greater than ds 1.0, because in ds 1.0, the component name is mandatory.
+        if (specVersion > XmlHandler.DS_VERSION_1_0)
+        {
+            ComponentMetadata cm = new ComponentMetadata( specVersion );
+            try
+            {          
+                cm.setImplementationClassName("implementation.class");
+                cm.setName( null );
+                cm.validate( logger );
+            }
+            catch ( ComponentException ce )
+            {
+                fail( "Expect correct validation for unnamed component" );
+            }
+            String pid = cm.getConfigurationPid();
+            assertNotNull( "Expect non-null configuration pid when component name is not specified", pid );
+            assertEquals( "Expect configuration-pid to be equals to component implementation", 
+                          "implementation.class", cm.getConfigurationPid() );
+        }
+        
+        // Make sure that getConfigurationPid returns the name of the component, if specified
+        ComponentMetadata cm = new ComponentMetadata( specVersion );
+        try
+        {     
+            cm.setImplementationClassName("implementation.class");
+            cm.setName("my.component.name");
+            cm.validate( logger );
+        }
+        catch ( ComponentException ce )
+        {
+            fail( "Expect correct validation for named component" );
+        }
+        String pid = cm.getConfigurationPid();
+        assertNotNull( "Expect non-null configuration pid when component name is specified", pid );
+        assertEquals( "Expect configuration-pid to be equals to component name", 
+                      "my.component.name", cm.getConfigurationPid() );
+    }
 
     public void test_property_character_ds11() throws ComponentException
     {