Fix issue Felix-815.
Properties becomes optional by default.
Unvalued properties are not published with the service reference until they receive a value.
Setter methods are not called until properties receive a value
Injected values in fields follow standard Java initialization (null for object and arrays, 0 for numeric types, false for boolean). 
Mandatory properties can be set with the 'mandatory' attribute (supported in XML and in the annotations).
The core.xsd XML Schema is also modified to add the new attribute.

This improvement allows removing default value in properties (such as in the architecture handlers).
Provides test about this new improvement

Fix issue Felix-816
The comparator attribute is now supported for any binding policy.
Provides test about using custom comparator with any binding policy

Fix issue Felix-817
Solve an issue in the ServiceExporter when a service in unregistered twice (throws an IllegalStateException since a recent modification of the Felix framework). 

Fix issue Felix-818
Implement the ServiceReferenceImpl compareTo method (method added in OSGi R4.1). This method reuse the same implementation as the Felix framework ServiceReferenceImpl method.

Remove junit4osgi embedded tests

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@713976 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/UnacceptableConfigurationTest.java b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/UnacceptableConfigurationTest.java
index 841efe0..2822832 100644
--- a/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/UnacceptableConfigurationTest.java
+++ b/ipojo/tests/core/factories/src/main/java/org/apache/felix/ipojo/test/scenarios/factories/UnacceptableConfigurationTest.java
@@ -52,6 +52,27 @@
 	}

 	

 	/**

+     * Configuration without the name property.

+     */

+    public void testWithoutNameOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-2opt");

+        

+        Properties  p = new Properties();

+        p.put("int", new Integer(3));

+        p.put("long", new Long(42));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) { fail("an acceptable configuration is refused : " + e.getMessage()); }

+        

+    }

+	

+	/**

 	 * Empty configuration.

 	 */

 	public void testEmptyConfiguration() {

@@ -66,6 +87,20 @@
 	}

 	

 	/**

+     * Empty configuration.

+     */

+    public void testEmptyConfigurationOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-2opt");

+        Properties  p = new Properties();

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) { fail("An acceptable configuration is refused"); }

+    }

+	

+	/**

 	 * Empty configuration (just the name).

 	 */

 	public void testEmptyConfiguration2() {

@@ -82,6 +117,23 @@
 	}

 	

 	/**

+     * Empty configuration (just the name).

+     */

+    public void testEmptyConfiguration2opt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        Properties  p = new Properties();

+        p.put("instance.name","ko");

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) { 

+            fail("An acceptable configuration is refused");

+        }

+        

+    }

+	

+	/**

 	 * Null configuration (accept).

 	 */

 	public void testNull() {

@@ -95,6 +147,19 @@
 	}

 	

 	/**

+     * Null configuration (accept).

+     */

+    public void testNullOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-2opt");

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(null);

+            ci.dispose();

+        } catch(Exception e) { fail("An acceptable configuration is refused"); }

+    }

+	

+	/**

 	 * Null configuration (fail).

 	 */

 	public void testNull2() {

@@ -110,6 +175,23 @@
 	}

 	

 	/**

+     * Null configuration (success).

+     */

+    public void testNull2Opt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(null);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is refused");

+        }

+        

+        

+    }

+	

+	/**

 	 * Check static properties.

 	 */

 	public void testStaticOK() {

@@ -133,6 +215,29 @@
 	}

 	

 	/**

+     * Check static properties.

+     */

+    public void testStaticOKopt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("long", new Long(42));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+    }

+	

+	/**

 	 * Check dynamic properties.

 	 */

 	public void testDynamicOK() {

@@ -156,6 +261,46 @@
 		}

 	}

 	

+	

+	/**

+     * Check dynamic properties.

+     */

+    public void testDynamicOKopt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dynopt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("boolean", new Boolean(true));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            e.printStackTrace();

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+        

+        p = new Properties();

+        p.put("instance.name","ok");

+        p.put("boolean", new Boolean(true));

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            e.printStackTrace();

+            fail("An acceptable configuration is rejected (2) : " + e.getMessage());

+        }

+    }

+    

 	/**

 	 * Check inconsistent types.

 	 */

@@ -180,6 +325,43 @@
 	}

 	

 	/**

+     * Check inconsistent types.

+     */

+    public void testDynamicBadTypeOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dynopt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("long", new Long(42));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+        

+        p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected (2) : " + e.getMessage());

+        }

+    }

+	

+	/**

 	 * Check good configuration (with overriding).

 	 */

 	public void testDynamicComplete() {

@@ -203,6 +385,44 @@
 	}

 	

 	/**

+     * Check good configuration (with overriding).

+     */

+    public void testDynamicCompleteOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("boolean", new Boolean(true));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+        

+        

+        p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected (2) : " + e.getMessage());

+        }

+    }

+	

+	/**

 	 * Check good configuration.

 	 */

 	public void testDynamicJustEnough() {

@@ -224,6 +444,40 @@
 	}

 	

 	/**

+     * Check good configuration.

+     */

+    public void testDynamicJustEnoughOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("boolean", new Boolean(true));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+        

+        p = new Properties();

+        p.put("instance.name","ok");

+        p.put("boolean", new Boolean(true));

+        p.put("strAProp", new String[] {"a"});

+        

+        ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+    }

+	

+	/**

 	 * Check good configuration.

 	 */

 	public void testDynamicMix() {

@@ -246,6 +500,42 @@
 	}

 	

 	/**

+     * Check good configuration.

+     */

+    public void testDynamicMixOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("boolean", new Boolean(true));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+        

+        p = new Properties();

+        p.put("instance.name","ok");

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+    }

+	

+	/**

 	 * Check uncomplete configuration.

 	 */

 	public void testDynamicUncomplete() {

@@ -267,6 +557,27 @@
 	}

 	

 	/**

+     * Check uncomplete configuration.

+     */

+    public void testDynamicUncompleteOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) { fail("An acceptable configuration is refused"); }

+        

+        

+    }

+	

+	/**

 	 * Check good configuration (more properties).

 	 */

 	public void testDynamicMore() {

@@ -291,6 +602,30 @@
 	}

 	

 	/**

+     * Check good configuration (more properties).

+     */

+    public void testDynamicMoreOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("boolean", new Boolean(true));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        p.put("tralala", "foo");

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+    }

+	

+	/**

 	 * Check properties affecting services and component.

 	 */

 	public void testDoubleProps() {

@@ -314,6 +649,31 @@
 			fail("An acceptable configuration is rejected : " + e.getMessage());

 		}

 	}

+	

+	/**

+     * Check properties affecting services and component.

+     */

+    public void testDoublePropsOpt() {

+        Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-Dyn2opt");

+        

+        Properties  p = new Properties();

+        p.put("instance.name","ok");

+        p.put("int", new Integer(3));

+        p.put("boolean", new Boolean(true));

+        p.put("string", "absdir");

+        p.put("strAProp", new String[] {"a"});

+        p.put("intAProp", new int[] {1,2});

+        p.put("boolean", new Boolean(false));

+        p.put("string", "toto");

+        

+        ComponentInstance ci = null;

+        try {

+            ci = f.createComponentInstance(p);

+            ci.dispose();

+        } catch(Exception e) {

+            fail("An acceptable configuration is rejected : " + e.getMessage());

+        }

+    }

     

     /**

      * Check instance name unicity.

@@ -367,7 +727,7 @@
     public void testUnicity3() {

         Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-2");

         

-        ComponentInstance ci1 = null,ci2 = null, ci3 = null;

+        ComponentInstance ci1 = null,ci2 = null;

         try {

             Properties p1 = new Properties();

             p1.put("instance.name","name1");

@@ -376,11 +736,8 @@
             p2.put("instance.name","name1");

             ci2 = f.createComponentInstance(p2);

             assertNotEquals("Check name ci1, ci2", ci1.getInstanceName(), ci2.getInstanceName());

-            assertNotEquals("Check name ci1, ci3", ci1.getInstanceName(), ci3.getInstanceName());

-            assertNotEquals("Check name ci3, ci2", ci3.getInstanceName(), ci3.getInstanceName());

             ci1.dispose();

             ci2.dispose();

-            ci3.dispose();

         } catch(Exception e) { 

             ci1.dispose();

             return; }

@@ -395,7 +752,7 @@
         Factory f = Utils.getFactoryByName(context, "Factories-FooProviderType-2");

         Factory f2 = Utils.getFactoryByName(context, "Factories-FooProviderType-1");

         

-        ComponentInstance ci1 = null,ci2 = null, ci3 = null;

+        ComponentInstance ci1 = null,ci2 = null;

         try {

             Properties p1 = new Properties();

             p1.put("instance.name","name1");

@@ -403,13 +760,9 @@
             Properties p2 = new Properties();

             p2.put("instance.name","name1");

             ci2 = f2.createComponentInstance(p2);

-            System.err.println("==== " + ci1.getInstanceName() + " === " + ci2.getInstanceName());

             assertNotEquals("Check name ci1, ci2", ci1.getInstanceName(), ci2.getInstanceName());

-            assertNotEquals("Check name ci1, ci3", ci1.getInstanceName(), ci3.getInstanceName());

-            assertNotEquals("Check name ci3, ci2", ci3.getInstanceName(), ci3.getInstanceName());

             ci1.dispose();

             ci2.dispose();

-            ci3.dispose();

         } catch(Exception e) { 

             ci1.dispose();

             return; }

diff --git a/ipojo/tests/core/factories/src/main/resources/metadata.xml b/ipojo/tests/core/factories/src/main/resources/metadata.xml
index 8781753..7daf702 100644
--- a/ipojo/tests/core/factories/src/main/resources/metadata.xml
+++ b/ipojo/tests/core/factories/src/main/resources/metadata.xml
@@ -1,8 +1,5 @@
-<ipojo

-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

-    xsi:schemaLocation="org.apache.felix.ipojo http://people.apache.org/~clement/ipojo/schemas/core.xsd"

-    xmlns="org.apache.felix.ipojo"

-    >

+<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

+	xsi:schemaLocation="org.apache.felix.ipojo http://people.apache.org/~clement/ipojo/schemas/core.xsd" xmlns="org.apache.felix.ipojo">

 	<!-- Simple provider  -->

 	<component

 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"

@@ -22,12 +19,25 @@
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"

 		name="Factories-FooProviderType-Dyn" architecture="true">

 		<provides>

-			<property name="int" field="intProp" value="2" />

-			<property name="boolean" field="boolProp" value="false" />

-			<property name="string" field="strProp" value="foo" />

+			<property name="int" field="intProp" value="2" mandatory="true"/>

+			<property name="boolean" field="boolProp" value="false" mandatory="true"/>

+			<property name="string" field="strProp" value="foo" mandatory="true"/>

 			<property name="strAProp" field="strAProp"

-				value="{foo, bar}" />

-			<property name="intAProp" field="intAProp" value="{ 1,2,3}" />

+				value="{foo, bar}" mandatory="true"/>

+			<property name="intAProp" field="intAProp" value="{ 1,2,3}" mandatory="true"/>

+		</provides>

+	</component>

+	

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn"

+		name="Factories-FooProviderType-Dynopt" architecture="true">

+		<provides>

+			<property name="int" field="intProp" value="2"/>

+			<property name="boolean" field="boolProp" value="false"/>

+			<property name="string" field="strProp" value="foo"/>

+			<property name="strAProp" field="strAProp"

+				value="{foo, bar}"/>

+			<property name="intAProp" field="intAProp" value="{ 1,2,3}"/>

 		</provides>

 	</component>

 	

@@ -35,12 +45,25 @@
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"

 		name="Factories-FooProviderType-2" architecture="true">

 		<provides>

-			<property name="int" type="int" value="2" />

-			<property name="long" type="long" value="40" />

-			<property name="string" type="java.lang.String" value="foo" />

+			<property name="int" type="int" value="2" mandatory="true" />

+			<property name="long" type="long" value="40" mandatory="true"/>

+			<property name="string" type="java.lang.String" value="foo" mandatory="true"/>

+			<property name="strAProp" type="java.lang.String[]"

+				value="{foo, bar}" mandatory="true" />

+			<property name="intAProp" type="int[]" value="{1,2,3}" mandatory="true"/>

+		</provides>

+	</component>

+	

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"

+		name="Factories-FooProviderType-2opt" architecture="true">

+		<provides>

+			<property name="int" type="int" value="2"/>

+			<property name="long" type="long" value="40"/>

+			<property name="string" type="java.lang.String" value="foo"/>

 			<property name="strAProp" type="java.lang.String[]"

 				value="{foo, bar}" />

-			<property name="intAProp" type="int[]" value="{1,2,3}" />

+			<property name="intAProp" type="int[]" value="{1,2,3}"/>

 		</provides>

 	</component>

 	

@@ -48,12 +71,25 @@
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"

 		name="Factories-FooProviderType-Dyn2" architecture="true">

 		<provides>

-			<property name="int" field="intProp" value="4" />

-			<property name="boolean" field="boolProp" />

-			<property name="string" field="strProp" />

-			<property name="strAProp" field="strAProp" />

+			<property name="int" field="intProp" value="4" mandatory="true"/>

+			<property name="boolean" field="boolProp" mandatory="true"/>

+			<property name="string" field="strProp" mandatory="true"/>

+			<property name="strAProp" field="strAProp" mandatory="true"/>

 			<property name="intAProp" field="intAProp"

-				value="{1, 2,3 }" />

+				value="{1, 2,3 }" mandatory="true"/>

+		</provides>

+	</component>

+	

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderTypeDyn2"

+		name="Factories-FooProviderType-Dyn2opt" architecture="true">

+		<provides>

+			<property name="int" field="intProp" value="4" />

+			<property name="boolean" field="boolProp"/>

+			<property name="string" field="strProp"/>

+			<property name="strAProp" field="strAProp"/>

+			<property name="intAProp" field="intAProp"

+				value="{1, 2,3 }"/>

 		</provides>

 	</component>

 	

@@ -61,13 +97,27 @@
 		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"

 		name="Factories-FooProviderType-3" architecture="true">

 		<provides>

-			<property name="foo" field="m_foo" />

-			<property name="bar" field="m_bar" />

-			<property name="baz" type="java.lang.String" />

+			<property name="foo" field="m_foo" mandatory="true"/>

+			<property name="bar" field="m_bar" mandatory="true"/>

+			<property name="baz" type="java.lang.String" mandatory="true"/>

 		</provides>

 		<properties propagation="true">

-			<property name="foo" field="m_foo" />

-			<property name="bar" field="m_bar" />

+			<property name="foo" field="m_foo" mandatory="true"/>

+			<property name="bar" field="m_bar" mandatory="true"/>

+		</properties>

+	</component>

+	

+	<component

+		classname="org.apache.felix.ipojo.test.scenarios.component.FooProviderType1"

+		name="Factories-FooProviderType-3opt" architecture="true">

+		<provides>

+			<property name="foo" field="m_foo"/>

+			<property name="bar" field="m_bar"/>

+			<property name="baz" type="java.lang.String"/>

+		</provides>

+		<properties propagation="true">

+			<property name="foo" field="m_foo"/>

+			<property name="bar" field="m_bar"/>

 		</properties>

 	</component>