FELIX-4360 Add a test case ensuring value order of Collection properties

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1553885 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java
index f35c0f0..9d1025e 100644
--- a/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java
+++ b/configadmin/src/test/java/org/apache/felix/cm/integration/ConfigurationBaseTest.java
@@ -20,8 +20,13 @@
 
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
 
 import junit.framework.TestCase;
 
@@ -1257,4 +1262,65 @@
             getConfigurationAdmin().getConfiguration( pid, null ).delete();
         }
     }
+
+   @Test
+    public void test_collection_property_order() throws IOException, BundleException
+    {
+        final String pid = "test_collection_property_order";
+        final String[] value = new String[]
+            { "a", "b", "c" };
+        final Bundle cmBundle = getCmBundle();
+        try
+        {
+            final Vector v = new Vector( Arrays.asList( value ) );
+            getConfigurationAdmin().getConfiguration( pid ).update( new Hashtable()
+            {
+                {
+                    put( "v", v );
+                }
+            } );
+            assertOrder( value, getConfigurationAdmin().getConfiguration( pid ).getProperties().get( "v" ) );
+
+            cmBundle.stop();
+            cmBundle.start();
+
+            assertOrder( value, getConfigurationAdmin().getConfiguration( pid ).getProperties().get( "v" ) );
+            getConfigurationAdmin().getConfiguration( pid, null ).delete();
+
+            final List l = Arrays.asList( value );
+            getConfigurationAdmin().getConfiguration( pid ).update( new Hashtable()
+            {
+                {
+                    put( "v", l );
+                }
+            } );
+            assertOrder( value, getConfigurationAdmin().getConfiguration( pid ).getProperties().get( "v" ) );
+
+            cmBundle.stop();
+            cmBundle.start();
+
+            assertOrder( value, getConfigurationAdmin().getConfiguration( pid ).getProperties().get( "v" ) );
+            getConfigurationAdmin().getConfiguration( pid, null ).delete();
+        }
+        finally
+        {
+            // make sure no configuration survives ...
+            getConfigurationAdmin().getConfiguration( pid, null ).delete();
+        }
+    }
+
+
+    private void assertOrder( final String[] expected, final Object actual )
+    {
+        TestCase.assertTrue( "Actual value must be a collection", actual instanceof Collection );
+        TestCase.assertEquals( "Collection must have " + expected.length + " entries", expected.length,
+            ( ( Collection ) actual ).size() );
+
+        final Iterator actualI = ( ( Collection ) actual ).iterator();
+        for ( int i = 0; i < expected.length; i++ )
+        {
+            String string = expected[i];
+            TestCase.assertEquals( i + "th element must be " + string, string, actualI.next() );
+        }
+    }
 }