Author: clement
Date: Mon Apr 14 13:20:47 2008
New Revision: 647984

URL: http://svn.apache.org/viewvc?rev=647984&view=rev
Log:
Add a method to check if a value is contained in an array. This method is used 
because sometimes the service interface arrays not have always the same order 
(depending on the VM). So, this allow to launch the test suites on any VM.

Modified:
    
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java
    
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java

Modified: 
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java?rev=647984&r1=647983&r2=647984&view=diff
==============================================================================
--- 
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java
 (original)
+++ 
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/core/ComponentDesc.java
 Mon Apr 14 13:20:47 2008
@@ -304,8 +304,8 @@
                
                String[] specs = (String[]) 
sr_foobarProvider.getProperty("component.providedServiceSpecifications");
                assertEquals("Check component.providedServiceSpecifications 
length", specs.length, 2);
-               assertEquals("Check component.providedServiceSpecifications 1", 
FooService.class.getName(), specs[1]);
-               assertEquals("Check component.providedServiceSpecifications 2", 
BarService.class.getName(), specs[0]);
+               assertTrue("Check component.providedServiceSpecifications 1", 
Utils.contains(FooService.class.getName(), specs));
+               assertTrue("Check component.providedServiceSpecifications 2", 
Utils.contains(BarService.class.getName(), specs));
                
                PropertyDescription[] pd = (PropertyDescription[]) 
sr_foobarProvider.getProperty("component.properties");
                assertEquals("Check component.properties length", pd.length, 0);
@@ -318,8 +318,8 @@
                
         Element[] specs2 = cd.getElements("provides");
         assertEquals("Check specs length", specs2.length, 2);
-        assertEquals("Check specs", FooService.class.getName(), 
specs2[1].getAttribute("specification"));
-        assertEquals("Check specs", BarService.class.getName(), 
specs2[0].getAttribute("specification"));
+        assertTrue("Check specs", 
containsSpecification(FooService.class.getName(), specs2));
+        assertTrue("Check specs", 
containsSpecification(BarService.class.getName(), specs2));
         
         Element[] pd2 = cd.getElements("property");
         assertNull("Check props null", pd2);
@@ -328,6 +328,15 @@
         ComponentTypeDescription desc = (ComponentTypeDescription) 
sr_foobarProvider.getProperty("component.description");
                assertNotNull("check description equality", desc);
 
+       }
+       
+       private boolean containsSpecification(String value, Element[] array) {
+           for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] != null && 
array[i].containsAttribute("specification") && 
array[i].getAttribute("specification").equals(value)) {
+                return true;
+            }
+        }
+        return false;
        }
        
        

Modified: 
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
URL: 
http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java?rev=647984&r1=647983&r2=647984&view=diff
==============================================================================
--- 
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
 (original)
+++ 
felix/trunk/ipojo/tests/tests.core/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
 Mon Apr 14 13:20:47 2008
@@ -304,5 +304,23 @@
             return new Object[0];
         }
     }
+    
+    public static boolean contains(String string, String[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] != null  && array[i].equals(string)) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    public static boolean contains(int value, int[] array) {
+        for (int i = 0; array != null && i < array.length; i++) {
+            if (array[i] == value) {
+                return true;
+            }
+        }
+        return false;
+    }
 
 }


Reply via email to