You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2007/09/25 17:07:18 UTC

svn commit: r579291 [6/12] - in /felix/sandbox/clement/Tests/Suite: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/ipojo/ src/main/java/org/apache/felix/ipojo...

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp4.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp4.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp4.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp4.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,249 @@
+package org.apache.felix.ipojo.test.scenarios.composite.provides;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.test.scenarios.component.TotoProvider;
+import org.apache.felix.ipojo.test.scenarios.service.Tota;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class TestComp4 extends TestCase {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+	private ComponentFactory tataFactory2;
+    
+    public TestComp4(BundleContext arg0) {
+        super(arg0);
+    }
+    
+    public void setUp() {
+        tataFactory = (ComponentFactory) Utils.getFactoryByName(context, "tata");
+        totoFactory = (ComponentFactory) Utils.getFactoryByName(context, "toto");
+        tataFactory2 = (ComponentFactory) Utils.getFactoryByName(context, "comp-6");
+        tataFactory2.stop();
+        tataFactory.stop();
+        
+        Properties props = new Properties();
+        props.put("name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        Properties props3 = new Properties();
+        props3.put("name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        totoProv.stop();
+        totoProv2.stop();
+        
+        Factory factory = Utils.getFactoryByName(context, "comp-4");
+        Properties props2 = new Properties();
+        props2.put("name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+         
+    }
+    
+    public void tearDown() {  
+    	tataFactory2.start();
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+    
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2 ("+under.getState()+")", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", context.getServiceReference(Tota.class.getName()));
+        ServiceReference ref = context.getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        Integer toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 3 ("+toto.intValue()+")", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 3 (" + toto_1.intValue() + ")", toto_1.intValue(), 1);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 4 ("+toto.intValue()+")", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4 ("+toto_2.intValue()+")", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 4", toto_1.intValue(), 2);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Stop the factory
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", context.getServiceReference(Tota.class.getName()));
+        
+        totoProv2.stop();
+        totoProv.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAllOpt(tota);
+        // Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Is arch exposed
+        assertNotNull("Test arch", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        
+        tataFactory.stop();
+        
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        assertNull("Assert no tota service - 7", context.getServiceReference(Tota.class.getName()));
+        
+        under.dispose();
+        under = null;
+    }
+
+    private void invoke(Tota tota) {
+        tota.tata();
+        
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte)2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short)5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5);
+        
+    }
+    
+    
+    private void invokeStr(Tota tota) {
+        tota.tataStr();
+    }
+    
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1,2);
+        tota.toto1("foo");
+    }
+    
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        //invokeArrays(tota);
+        invokeStr(tota);
+        //invokeTata(tota);
+        //invokeTata1(tota);
+        //invokeTata5(tota);
+        //invokeAdd(tota);
+        invokeToto(tota);
+    }
+    
+    private void invokeAllOpt(Tota tota) {
+        invoke(tota);
+        //invokeArrays(tota);
+        invokeStr(tota);
+        //invokeTata(tota);
+        //invokeTata1(tota);
+        //invokeTata5(tota);
+        //invokeAdd(tota);
+        invokeTotoOpt(tota);
+    }
+    
+    private void invokeTotoOpt(Tota tota) {
+        try {
+            tota.toto();
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        try {
+            assertEquals("Assert toto", tota.toto("foo"), "foo");
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        
+        try {
+            tota.toto(1,2);
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        try {
+            tota.toto1("foo");
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+    }
+    
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp5.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp5.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp5.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp5.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,253 @@
+package org.apache.felix.ipojo.test.scenarios.composite.provides;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.test.scenarios.component.TotoProvider;
+import org.apache.felix.ipojo.test.scenarios.service.Tota;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class TestComp5 extends TestCase {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+	private ComponentFactory tataFactory2;
+    
+    public TestComp5(BundleContext arg0) {
+        super(arg0);
+    }
+
+    public void setUp() {
+        tataFactory = (ComponentFactory) Utils.getFactoryByName(context, "tata");
+        totoFactory = (ComponentFactory) Utils.getFactoryByName(context, "toto");
+        tataFactory2 = (ComponentFactory) Utils.getFactoryByName(context, "comp-6");
+        tataFactory2.stop();
+        tataFactory.stop();
+        
+        Properties props = new Properties();
+        props.put("name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        Properties props3 = new Properties();
+        props3.put("name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        totoProv.stop();
+        totoProv2.stop();
+        
+        Factory factory = Utils.getFactoryByName(context, "comp-5");
+        Properties props2 = new Properties();
+        props2.put("name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch(Exception e) {
+            e.printStackTrace();
+            fail();
+        }
+         
+    }
+    
+    public void tearDown() {    
+    	tataFactory2.start();
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+    
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2 ("+under.getState()+")", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", context.getServiceReference(Tota.class.getName()));
+        ServiceReference ref = context.getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        Integer toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 3 ("+toto.intValue()+")", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 3 (" + toto_1.intValue() + ")", toto_1.intValue(), 1);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 4 ("+toto.intValue()+")", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4 ("+toto_2.intValue()+")", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 4", toto_1.intValue(), 3);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Stop the factory
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", context.getServiceReference(Tota.class.getName()));
+        
+        totoProv2.stop();
+        totoProv.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAllOpt(tota);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Is arch exposed
+        assertNotNull("Test arch", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        
+        tataFactory.stop();
+        
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        assertNull("Assert no tota service - 7", context.getServiceReference(Tota.class.getName()));
+        
+        under.dispose();
+        under = null;
+    }
+
+
+
+    private void invoke(Tota tota) {
+        tota.tata();
+        
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte)2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short)5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5);
+        
+    }
+    
+    
+    private void invokeStr(Tota tota) {
+        tota.tataStr();
+    }
+    
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1,2);
+        tota.toto1("foo");
+    }
+    
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        //invokeArrays(tota);
+        invokeStr(tota);
+        //invokeTata(tota);
+        //invokeTata1(tota);
+        //invokeTata5(tota);
+        //invokeAdd(tota);
+        invokeToto(tota);
+    }
+    
+    private void invokeAllOpt(Tota tota) {
+        invoke(tota);
+        //invokeArrays(tota);
+        invokeStr(tota);
+        //invokeTata(tota);
+        //invokeTata1(tota);
+        //invokeTata5(tota);
+        //invokeAdd(tota);
+        invokeTotoOpt(tota);
+    }
+    
+    private void invokeTotoOpt(Tota tota) {
+        try {
+            tota.toto();
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        try {
+            assertEquals("Assert toto", tota.toto("foo"), "foo");
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        
+        try {
+            tota.toto(1,2);
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        try {
+        	tota.toto1("foo");
+        	fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+    }
+    
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp6.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp6.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp6.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp6.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,272 @@
+package org.apache.felix.ipojo.test.scenarios.composite.provides;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.test.scenarios.component.TotoProvider;
+import org.apache.felix.ipojo.test.scenarios.service.Tata;
+import org.apache.felix.ipojo.test.scenarios.service.Toto;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class TestComp6 extends TestCase {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+    
+    public TestComp6(BundleContext arg0) {
+        super(arg0);
+    }
+    
+    public void setUp() {
+        tataFactory = (ComponentFactory) Utils.getFactoryByName(context, "tata");
+        totoFactory = (ComponentFactory) Utils.getFactoryByName(context, "toto");
+        
+        tataFactory.stop();
+        
+        Properties props = new Properties();
+        props.put("name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        Properties props3 = new Properties();
+        props3.put("name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        totoProv.stop();
+        totoProv2.stop();
+        
+        Factory factory = Utils.getFactoryByName(context, "comp-6");
+        Properties props2 = new Properties();
+        props2.put("name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+         
+    }
+    
+    public void tearDown() {       
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+    
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        ServiceReference refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        ServiceReference refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNull("Assert no toto service - 1", refToto);
+        assertNull("Assert no tata service - 1", refTata);
+
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2 ("+under.getState()+")", under.getState() == ComponentInstance.INVALID);
+        refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNull("Assert no toto service - 2", refToto);
+        assertNull("Assert no tata service - 2", refTata);
+
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNotNull("Assert toto service - 3", refToto);
+        assertNotNull("Assert tata service - 3", refTata);
+        Toto toto = (Toto) context.getService(refToto);
+        Tata tata = (Tata) context.getService(refTata);
+ 
+        invokeAll(tata);
+        invokeToto(toto);
+ 
+        // Check toto
+        Properties props = toto.getProps();
+        Integer toto_0 = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        Integer toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 3 ("+toto_0.intValue()+")", toto_0.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 3 (" + toto_1.intValue() + ")", toto_1.intValue(), 1);
+        //Check tata
+        props = tata.getPropsTata();
+        Integer tata_0 = (Integer) props.get("tata");
+        assertEquals("Assert tata - 3", tata_0.intValue(), 1);
+
+        context.ungetService(refToto);
+        context.ungetService(refTata);
+        toto = null;
+        tata = null;
+        
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNotNull("Assert toto service - 4", refToto);
+        assertNotNull("Assert tata service - 4", refTata);
+        
+        toto = (Toto) context.getService(refToto);
+        tata = (Tata) context.getService(refTata);
+        invokeAll(tata);
+        invokeToto(toto);
+
+        // Check toto
+        props = toto.getProps();
+        toto_0 = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        toto_1 = (Integer) props.get("toto1");
+        assertEquals("Assert toto - 4 ("+toto_0.intValue()+")", toto_0.intValue(), 2);
+        assertEquals("Assert toto_2 - 4 ("+toto_2.intValue()+")", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        assertEquals("Assert toto1 - 4", toto_1.intValue(), 3);
+        //Check tata
+        props = tata.getPropsTata();
+        tata_0 = (Integer) props.get("tata");
+        assertEquals("Assert tata - 4", tata_0.intValue(), 2);
+        context.ungetService(refToto);
+        context.ungetService(refTata);
+        toto = null;
+        tata = null;
+
+        // Stop the factory
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNull("Assert no toto service - 5", refToto);
+        assertNull("Assert no tata service - 5", refTata);
+ 
+        totoProv2.stop();
+        totoProv.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNotNull("Assert toto service - 6", refToto);
+        assertNotNull("Assert tata service - 6", refTata);
+        toto = (Toto) context.getService(refToto);
+        tata = (Tata) context.getService(refTata);
+ 
+        invokeAll(tata);
+        invokeTotoOpt(toto);
+        //  Check tata
+        props = tata.getPropsTata();
+        tata_0 = (Integer) props.get("tata");
+        assertEquals("Assert tata - 6", tata_0.intValue(), 1);
+        context.ungetService(refToto);
+        context.ungetService(refTata);
+        toto = null;
+        tata = null;
+ 
+        // Is arch exposed
+        assertNotNull("Test arch", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        
+        tataFactory.stop();
+        
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        refToto = Utils.getServiceReferenceByName(context, Toto.class.getName(), "ff");
+        refTata = Utils.getServiceReferenceByName(context, Tata.class.getName(), "ff");
+        assertNull("Assert no toto service - 7", refToto);
+        assertNull("Assert no tata service - 7", refTata);
+        
+        under.dispose();
+        under = null;
+    }
+
+    private void invoke(Tata tota) {
+        tota.tata();
+        
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte)2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short)5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5);
+        
+    }
+    
+    
+    private void invokeStr(Tata tota) {
+        tota.tataStr();
+    }
+    
+    private void invokeToto(Toto tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1,2);
+        tota.toto1("foo");
+    }
+    
+    private void invokeAll(Tata tota) {
+        invoke(tota);
+        //invokeArrays(tota);
+        invokeStr(tota);
+        //invokeTata(tota);
+        //invokeTata1(tota);
+        //invokeTata5(tota);
+        //invokeAdd(tota);
+    }
+    
+    private void invokeTotoOpt(Toto tota) {
+        try {
+            tota.toto();
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        try {
+            assertEquals("Assert toto", tota.toto("foo"), "foo");
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        
+        try {
+            tota.toto(1,2);
+            fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+        
+        try {
+        	tota.toto1("foo");
+        	fail("UnsupportedOperationException expected");
+        } catch(UnsupportedOperationException e) { }
+    }
+    
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp7.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp7.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp7.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp7.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,321 @@
+package org.apache.felix.ipojo.test.scenarios.composite.provides;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.test.scenarios.component.TotoProvider;
+import org.apache.felix.ipojo.test.scenarios.service.Tota;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class TestComp7 extends TestCase {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    private ComponentFactory tataFactory2;
+    
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+    
+    public TestComp7(BundleContext arg0) {
+        super(arg0);
+    }
+    
+    public void setUp() {
+        tataFactory = (ComponentFactory) Utils.getFactoryByName(context, "tata");
+        totoFactory = (ComponentFactory) Utils.getFactoryByName(context, "toto");
+        tataFactory2 = (ComponentFactory) Utils.getFactoryByName(context, "comp-6");
+        tataFactory2.stop();
+        
+        Properties props = new Properties();
+        props.put("name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        Properties props3 = new Properties();
+        props3.put("name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        totoProv.stop();
+        totoProv2.stop();
+        
+        Factory factory = Utils.getFactoryByName(context, "comp-7");
+        Properties props2 = new Properties();
+        props2.put("name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        tataFactory.stop();
+         
+    }
+    
+    public void tearDown() {
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        tataFactory2.start();
+        
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+    }
+    
+    public void testSimple() {
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", context.getServiceReference(Tota.class.getName()));
+        ServiceReference ref = context.getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 3 ("+toto.intValue()+")", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 1);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        Integer tataStr = (Integer) props.get("tataStr");
+        Integer tataStrs = (Integer) props.get("tataStrs");
+        Integer tata_2 = (Integer) props.get("tata_2");
+        Integer tata_3 = (Integer) props.get("tata_3");
+        Integer tata1 = (Integer) props.get("tata1");
+        Integer tata1_1 = (Integer) props.get("tata1_1");
+        Integer tata5 = (Integer) props.get("tata5");
+        Integer tata5_1 = (Integer) props.get("tata5_1");
+        Integer tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 3", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 3", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 3", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 3", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 3", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 3", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 3", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 3", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 3", tata5_2.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 4", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 2);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+        assertEquals("Assert tataStr - 4", tataStr.intValue(), 2);
+        assertEquals("Assert tataStrs - 4", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 4", tata_2.intValue(), 2);
+        assertEquals("Assert tata_3 - 4", tata_3.intValue(), 2);
+        assertEquals("Assert tata1 - 4", tata1.intValue(), 2);
+        assertEquals("Assert tata1_1 - 4", tata1_1.intValue(), 2);
+        assertEquals("Assert tata5 - 4", tata5.intValue(), 2);
+        assertEquals("Assert tata5_1 - 4", tata5_1.intValue(), 2);
+        assertEquals("Assert tata5_2 - 4", tata5_2.intValue(), 2);
+
+        context.ungetService(ref);
+        tota = null;
+        
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", context.getServiceReference(Tota.class.getName()));
+        
+        totoProv2.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        assertEquals("Assert toto - 6", toto.intValue(), 3);
+        assertEquals("Assert toto_2 - 6", toto_2.intValue(), 3);
+        assertEquals("Assert toto_3 - 6", toto_3.intValue(), 3);
+        assertEquals("Assert toto_4 - 6", toto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 6", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 6", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 6", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 6", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 6", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 6", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 6", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 6", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 6", tata5_2.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Is arch exposed
+        assertNotNull("Test arch", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        
+        totoProv.stop();
+        
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        assertNull("Assert no tota service - 7", context.getServiceReference(Tota.class.getName()));
+        
+        under.dispose();
+        under = null;
+    }
+
+    private void invoke(Tota tota) {
+        tota.tata();
+        
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte)2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short)5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5);
+        
+    }
+    
+    private void invokeArrays(Tota tota) {
+        
+        int[] a = new int[] {1,2,3};
+        assertEquals("Assert invoke tataint[]", tota.tataInts(a), a);
+        
+        long[] b = new long[] {1,2,3};
+        assertEquals("Assert invoke tataLong[]", tota.tataLongs(b), b);
+        
+        double[] c = new double[] {1,2,3};
+        assertEquals("Assert invoke tataDouble[]", tota.tataDoubles(c), c);
+        
+        char[] d = new char[] {'a','b', 'c'};
+        assertEquals("Assert invoke tataChar[]", tota.tataChars(d), d);
+        
+        boolean[] e = new boolean[] {true, false};
+        assertEquals("Assert invoke tataBoolean[]", tota.tataBooleans(e), e);
+        
+        byte[] f = new byte[] {(byte) 1};
+        assertEquals("Assert invoke tataByte[]", tota.tataBytes(f), f);
+        
+        short[] g = new short[] {(short) 1};
+        assertEquals("Assert invoke tataShort[]", tota.tataShorts(g), g);
+        
+        float[] h = new float[] {5,6,7};
+        assertEquals("Assert invoke tataFloat[]", tota.tataFloats(h), h);
+        
+    }
+    
+    private void invokeStr(Tota tota) {
+        tota.tataStr();
+    }
+    
+    private void invokeTata(Tota tota) {
+        tota.tata(1,2);
+        tota.tata("tototototo");
+    }
+    
+    private void invokeTata1(Tota tota) {
+        assertEquals("Assert tata1", tota.tata1("foo"), "foo");
+        assertEquals("Assert tata1 - 2", tota.tata1(new char[] {'a','b','c'}), "abc");
+    }
+    
+    private void invokeTata5(Tota tota) {
+        assertEquals("Assert tata5 -1", tota.tata5("foo",1), "foo"+1);
+        assertEquals("Assert tata5 - 2", tota.tata5(new String[] {"a","b","c"}, 1), "31");
+        assertEquals("Assert tata5 - 3", tota.tata5("foo", new int[] {1,2,3}), "foo3");
+    }
+    
+    private void invokeAdd(Tota tota) {
+        assertEquals("Assert add", tota.add(1,1,1), 3);
+    }
+    
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1,2);
+    }
+    
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        invokeArrays(tota);
+        invokeStr(tota);
+        invokeTata(tota);
+        invokeTata1(tota);
+        invokeTata5(tota);
+        invokeAdd(tota);
+        invokeToto(tota);
+    }
+    
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp8.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp8.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp8.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/provides/TestComp8.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,353 @@
+package org.apache.felix.ipojo.test.scenarios.composite.provides;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.test.scenarios.component.TotoProvider;
+import org.apache.felix.ipojo.test.scenarios.component.TotoProviderGlue;
+import org.apache.felix.ipojo.test.scenarios.service.Tota;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class TestComp8 extends TestCase {
+
+    private ComponentFactory tataFactory;
+    private ComponentFactory totoFactory;
+    private ComponentFactory tataFactory2;
+    
+    private ComponentInstance totoProv, totoProv2;
+    private ComponentInstance under;
+    
+    public TestComp8(BundleContext arg0) {
+        super(arg0);
+    }
+
+    public void setUp() {
+        tataFactory = (ComponentFactory) Utils.getFactoryByName(context, "tata");
+        totoFactory = (ComponentFactory) Utils.getFactoryByName(context, "toto");
+        tataFactory2 = (ComponentFactory) Utils.getFactoryByName(context, "comp-6");
+        tataFactory2.stop();
+        
+        Properties props = new Properties();
+        props.put("name", "toto provider");
+        try {
+            totoProv = totoFactory.createComponentInstance(props);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        Properties props3 = new Properties();
+        props3.put("name", "toto provider 2");
+        try {
+            totoProv2 = totoFactory.createComponentInstance(props3);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        
+        totoProv.stop();
+        totoProv2.stop();
+        
+        Factory factory = Utils.getFactoryByName(context, "comp-8");
+        Properties props2 = new Properties();
+        props2.put("name", "ff");
+        try {
+            under = factory.createComponentInstance(props2);
+        } catch(Exception e) {
+            e.printStackTrace();
+        }
+        tataFactory.stop();
+         
+    }
+    
+    public void tearDown() {
+        tataFactory.start();
+        totoProv.dispose();
+        totoProv = null;
+        totoProv2.dispose();
+        totoProv2 = null;
+        tataFactory2.start();
+        
+        // Reset counters
+        TotoProvider.toto = 0;
+        TotoProvider.toto_2 = 0;
+        TotoProvider.toto_3 = 0;
+        TotoProvider.toto_4 = 0;
+        TotoProvider.toto1 = 0;
+        TotoProviderGlue.toto = 0;
+        TotoProviderGlue.toto_2 = 0;
+        TotoProviderGlue.toto_3 = 0;
+        TotoProviderGlue.toto_4 = 0;
+        TotoProviderGlue.toto1 = 0;
+    }
+    
+    public void testSimple() {        
+        // Neither factory nor instance
+        assertTrue("Assert under state - 1", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 1", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the importer
+        totoProv.start();
+        assertTrue("Assert under state - 2", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 2", context.getServiceReference(Tota.class.getName()));
+        
+        // Start the factory
+        tataFactory.start();
+        assertTrue("Assert under state - 3", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 3", context.getServiceReference(Tota.class.getName()));
+        ServiceReference ref = context.getServiceReference(Tota.class.getName());
+        Tota tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        Properties props = tota.getProps();
+        Integer toto = (Integer) props.get("toto");
+        Integer toto_2 = (Integer) props.get("toto_2");
+        Integer toto_3 = (Integer) props.get("toto_3");
+        Integer toto_4 = (Integer) props.get("toto_4");
+        Integer gtoto = (Integer) props.get("gtoto");
+        Integer gtoto_2 = (Integer) props.get("gtoto_2");
+        Integer gtoto_3 = (Integer) props.get("gtoto_3");
+        Integer gtoto_4 = (Integer) props.get("gtoto_4");
+        assertEquals("Assert toto - 3 ("+toto.intValue()+")", toto.intValue(), 1);
+        assertEquals("Assert toto_2 - 3", toto_2.intValue(), 1);
+        assertEquals("Assert toto_3 - 3", toto_3.intValue(), 0);
+        assertEquals("Assert toto_4 - 3", toto_4.intValue(), 0);
+        assertEquals("Assert gtoto - 3 ("+gtoto.intValue()+")", gtoto.intValue(), 1);
+        assertEquals("Assert gtoto_2 - 3", gtoto_2.intValue(), 1);
+        assertEquals("Assert gtoto_3 - 3", gtoto_3.intValue(), 1);
+        assertEquals("Assert gtoto_4 - 3", gtoto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        Integer tata = (Integer) props.get("tata");
+        Integer tataStr = (Integer) props.get("tataStr");
+        Integer tataStrs = (Integer) props.get("tataStrs");
+        Integer tata_2 = (Integer) props.get("tata_2");
+        Integer tata_3 = (Integer) props.get("tata_3");
+        Integer tata1 = (Integer) props.get("tata1");
+        Integer tata1_1 = (Integer) props.get("tata1_1");
+        Integer tata5 = (Integer) props.get("tata5");
+        Integer tata5_1 = (Integer) props.get("tata5_1");
+        Integer tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 3", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 3", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 3", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 3", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 3", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 3", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 3", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 3", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 3", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 3", tata5_2.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Start a second import
+        totoProv2.start();
+        assertTrue("Assert under state - 4", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 4", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        gtoto = (Integer) props.get("gtoto");
+        gtoto_2 = (Integer) props.get("gtoto_2");
+        gtoto_3 = (Integer) props.get("gtoto_3");
+        gtoto_4 = (Integer) props.get("gtoto_4");
+        assertEquals("Assert toto - 4", toto.intValue(), 2);
+        assertEquals("Assert toto_2 - 4", toto_2.intValue(), 2);
+        assertEquals("Assert toto_3 - 4", toto_3.intValue(), 0);
+        assertEquals("Assert toto_4 - 4", toto_4.intValue(), 0);
+        assertEquals("Assert gtoto - 4 ("+gtoto.intValue()+")", gtoto.intValue(), 2);
+        assertEquals("Assert gtoto_2 - 4", gtoto_2.intValue(), 2);
+        assertEquals("Assert gtoto_3 - 4", gtoto_3.intValue(), 2);
+        assertEquals("Assert gtoto_4 - 4", gtoto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 4", tata.intValue(), 2);
+        assertEquals("Assert tataStr - 4", tataStr.intValue(), 2);
+        assertEquals("Assert tataStrs - 4", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 4", tata_2.intValue(), 2);
+        assertEquals("Assert tata_3 - 4", tata_3.intValue(), 2);
+        assertEquals("Assert tata1 - 4", tata1.intValue(), 2);
+        assertEquals("Assert tata1_1 - 4", tata1_1.intValue(), 2);
+        assertEquals("Assert tata5 - 4", tata5.intValue(), 2);
+        assertEquals("Assert tata5_1 - 4", tata5_1.intValue(), 2);
+        assertEquals("Assert tata5_2 - 4", tata5_2.intValue(), 2);
+
+        context.ungetService(ref);
+        tota = null;
+        
+        tataFactory.stop();
+        assertTrue("Assert under state - 5", under.getState() == ComponentInstance.INVALID);
+        assertNull("Assert no tota service - 5", context.getServiceReference(Tota.class.getName()));
+        
+        totoProv2.stop();
+        tataFactory.start();
+        assertTrue("Assert under state - 6", under.getState() == ComponentInstance.VALID);
+        assertNotNull("Assert tota service - 6", context.getServiceReference(Tota.class.getName()));
+        ref = context.getServiceReference(Tota.class.getName());
+        tota = (Tota) context.getService(ref);
+        invokeAll(tota);
+        // Check toto
+        props = tota.getProps();
+        toto = (Integer) props.get("toto");
+        toto_2 = (Integer) props.get("toto_2");
+        toto_3 = (Integer) props.get("toto_3");
+        toto_4 = (Integer) props.get("toto_4");
+        gtoto = (Integer) props.get("gtoto");
+        gtoto_2 = (Integer) props.get("gtoto_2");
+        gtoto_3 = (Integer) props.get("gtoto_3");
+        gtoto_4 = (Integer) props.get("gtoto_4");
+        assertEquals("Assert toto - 6", toto.intValue(), 3);
+        assertEquals("Assert toto_2 - 6", toto_2.intValue(), 3);
+        assertEquals("Assert toto_3 - 6", toto_3.intValue(), 0);
+        assertEquals("Assert toto_4 - 6", toto_4.intValue(), 0);
+        assertEquals("Assert gtoto - 6 ("+gtoto.intValue()+")", gtoto.intValue(), 3);
+        assertEquals("Assert gtoto_2 - 6", gtoto_2.intValue(), 3);
+        assertEquals("Assert gtoto_3 - 6", gtoto_3.intValue(), 3);
+        assertEquals("Assert gtoto_4 - 6", gtoto_4.intValue(), 0);
+        //Check tata
+        props = tota.getPropsTata();
+        tata = (Integer) props.get("tata");
+        tataStr = (Integer) props.get("tataStr");
+        tataStrs = (Integer) props.get("tataStrs");
+        tata_2 = (Integer) props.get("tata_2");
+        tata_3 = (Integer) props.get("tata_3");
+        tata1 = (Integer) props.get("tata1");
+        tata1_1 = (Integer) props.get("tata1_1");
+        tata5 = (Integer) props.get("tata5");
+        tata5_1 = (Integer) props.get("tata5_1");
+        tata5_2 = (Integer) props.get("tata5_2");
+        assertEquals("Assert tata - 6", tata.intValue(), 1);
+        assertEquals("Assert tataStr - 6", tataStr.intValue(), 1);
+        assertEquals("Assert tataStrs - 6", tataStrs.intValue(), 0);
+        assertEquals("Assert tata_2 - 6", tata_2.intValue(), 1);
+        assertEquals("Assert tata_3 - 6", tata_3.intValue(), 1);
+        assertEquals("Assert tata1 - 6", tata1.intValue(), 1);
+        assertEquals("Assert tata1_1 - 6", tata1_1.intValue(), 1);
+        assertEquals("Assert tata5 - 6", tata5.intValue(), 1);
+        assertEquals("Assert tata5_1 - 6", tata5_1.intValue(), 1);
+        assertEquals("Assert tata5_2 - 6", tata5_2.intValue(), 1);
+        context.ungetService(ref);
+        tota = null;
+        
+        // Is arch exposed
+        assertNotNull("Test arch", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        
+        totoProv.stop();
+        
+        assertTrue("Assert under state - 7", under.getState() == ComponentInstance.INVALID);
+        assertNotNull("Test arch-2", Utils.getServiceReferenceByName(context, Architecture.class.getName(), "ff"));
+        assertNull("Assert no tota service - 7", context.getServiceReference(Tota.class.getName()));
+        
+        under.dispose();
+        under = null;
+    }
+
+
+
+    private void invoke(Tota tota) {
+        tota.tata();
+        
+        assertEquals("Assert invoke tataint", tota.tataInt(2), 2);
+        assertEquals("Assert invoke tataLong", tota.tataLong(2), 2);
+        assertEquals("Assert invoke tataDouble", tota.tataDouble(2), 2);
+        assertEquals("Assert invoke tataChar", tota.tataChar('a'), 'a');
+        assertTrue("Assert invoke tataBoolean", tota.tataBoolean(true));
+        assertEquals("Assert invoke tataByte", tota.tataByte((byte)2), 2);
+        assertEquals("Assert invoke tataShort", tota.tataShort((short)5), 5);
+        assertEquals("Assert invoke tataFloat", tota.tataFloat(5), 5);
+        
+    }
+    
+    private void invokeArrays(Tota tota) {
+        
+        int[] a = new int[] {1,2,3};
+        assertEquals("Assert invoke tataint[]", tota.tataInts(a), a);
+        
+        long[] b = new long[] {1,2,3};
+        assertEquals("Assert invoke tataLong[]", tota.tataLongs(b), b);
+        
+        double[] c = new double[] {1,2,3};
+        assertEquals("Assert invoke tataDouble[]", tota.tataDoubles(c), c);
+        
+        char[] d = new char[] {'a','b', 'c'};
+        assertEquals("Assert invoke tataChar[]", tota.tataChars(d), d);
+        
+        boolean[] e = new boolean[] {true, false};
+        assertEquals("Assert invoke tataBoolean[]", tota.tataBooleans(e), e);
+        
+        byte[] f = new byte[] {(byte) 1};
+        assertEquals("Assert invoke tataByte[]", tota.tataBytes(f), f);
+        
+        short[] g = new short[] {(short) 1};
+        assertEquals("Assert invoke tataShort[]", tota.tataShorts(g), g);
+        
+        float[] h = new float[] {5,6,7};
+        assertEquals("Assert invoke tataFloat[]", tota.tataFloats(h), h);
+        
+    }
+    
+    private void invokeStr(Tota tota) {
+        tota.tataStr();
+    }
+    
+    private void invokeTata(Tota tota) {
+        tota.tata(1,2);
+        tota.tata("tototototo");
+    }
+    
+    private void invokeTata1(Tota tota) {
+        assertEquals("Assert tata1", tota.tata1("foo"), "foo");
+        assertEquals("Assert tata1 - 2", tota.tata1(new char[] {'a','b','c'}), "abc");
+    }
+    
+    private void invokeTata5(Tota tota) {
+        assertEquals("Assert tata5 -1", tota.tata5("foo",1), "foo"+1);
+        assertEquals("Assert tata5 - 2", tota.tata5(new String[] {"a","b","c"}, 1), "31");
+        assertEquals("Assert tata5 - 3", tota.tata5("foo", new int[] {1,2,3}), "foo3");
+    }
+    
+    private void invokeAdd(Tota tota) {
+        assertEquals("Assert add", tota.add(1,1,1), 3);
+    }
+    
+    private void invokeToto(Tota tota) {
+        tota.toto();
+        assertEquals("Assert toto", tota.toto("foo"), "foo");
+        tota.toto(1,2);
+    }
+    
+    private void invokeAll(Tota tota) {
+        invoke(tota);
+        invokeArrays(tota);
+        invokeStr(tota);
+        invokeTata(tota);
+        invokeTata1(tota);
+        invokeTata5(tota);
+        invokeAdd(tota);
+        invokeToto(tota);
+    }
+    
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/test/CompositeTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/test/CompositeTest.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/test/CompositeTest.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/composite/test/CompositeTest.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,168 @@
+package org.apache.felix.ipojo.test.scenarios.composite.test;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.test.scenarios.service.BazService;
+import org.apache.felix.ipojo.test.scenarios.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class CompositeTest extends TestCase {
+
+	public CompositeTest(BundleContext arg0) {
+		super(arg0);
+	}
+	
+	public void testAPI() {
+		Factory fact1 = Utils.getFactoryByName(context, "composite.empty");
+		Properties p = new Properties();
+		p.put("name", "empty-1");
+		ComponentInstance empty = null;
+		try {
+			empty = fact1.createComponentInstance(p);
+		} catch(Exception e) {
+			e.printStackTrace();
+			fail(e.getMessage());
+		}
+		
+		ServiceContext sc = Utils.getServiceContext(empty);
+		
+		Factory fact2 = Utils.getFactoryByName(context, "composite.test.2");
+		Properties props2 = new Properties();
+		props2.put("name", "2"); // 2
+		Factory fact3 = Utils.getFactoryByName(context, "composite.test.3");
+		Properties props3 = new Properties();
+		props3.put("name", "3");
+		ComponentInstance comp2 = null;
+		ComponentInstance comp3 = null;
+		try {
+			comp2 = fact2.createComponentInstance(props2, sc);
+			comp3 = fact3.createComponentInstance(props3, sc);
+		} catch(Throwable e) {
+		    e.printStackTrace();
+		    fail(e.getMessage());
+		}
+		
+		assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
+		assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
+		
+		ServiceReference ref = null;
+
+		ref = Utils.getServiceReferenceByName(sc, CheckService.class.getName(), "2"); // 2
+
+		assertNotNull("Check ref", ref);
+		CheckService cs = (CheckService) sc.getService(ref);
+		assertTrue("Check invoke", cs.check());
+		
+		comp3.dispose();
+		comp2.dispose();
+		empty.dispose();
+	}
+	
+	public void testInstantiator() {
+		String type = "composite.instantiator";
+		Factory fact = Utils.getFactoryByName(context, type);
+		ComponentInstance ci = null;
+		Properties p = new Properties();
+		p.put("name", "mon_coeur");
+		try {
+			ci = fact.createComponentInstance(p);
+		} catch(Exception e) {
+			e.printStackTrace();
+		}
+				
+		assertTrue("Check ci", ci.getState() == ComponentInstance.VALID);
+		ServiceReference ref = Utils.getServiceReferenceByName(context, BazService.class.getName(), "mon_coeur");
+		assertNotNull("Check ref",ref);
+		BazService bs = (BazService) context.getService(ref);
+		assertTrue("Check invocation", bs.foo());
+		context.ungetService(ref);
+		ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), "mon_coeur");
+		assertNotNull("Check ref 2 ",ref);
+		FooService fs = (FooService) context.getService(ref);
+		assertTrue("Check invocation", fs.foo());
+		context.ungetService(ref);
+		ci.dispose();
+	}
+	
+	public void testAPI2() {
+		Factory fact1 = Utils.getFactoryByName(context, "composite.empty");
+		Properties p = new Properties();
+		p.put("name", "empty-2");
+		ComponentInstance empty = null;
+		try {
+			empty = fact1.createComponentInstance(p);
+		} catch(Exception e) {
+			e.printStackTrace();
+		}
+		
+		ServiceContext sc = Utils.getServiceContext(empty);
+		
+		Factory fact2 = Utils.getFactoryByName(sc, "composite.test.2");
+		Properties props2 = new Properties();
+		props2.put("name", "4");
+		Factory fact3 = Utils.getFactoryByName(sc, "composite.test.3");
+		Properties props3 = new Properties();
+		props3.put("name", "5");
+		ComponentInstance comp2 = null;
+		ComponentInstance comp3 = null;
+		try {
+			comp2 = fact2.createComponentInstance(props2, sc);
+			comp3 = fact3.createComponentInstance(props3, sc);
+		} catch(Exception e) {
+			e.printStackTrace();
+		}
+		
+		assertTrue("Test comp3", comp3.getState() == ComponentInstance.VALID);
+		assertTrue("Test comp2", comp2.getState() == ComponentInstance.VALID);
+		
+		ServiceReference ref = null;
+
+		ref = Utils.getServiceReferenceByName(sc, CheckService.class.getName(), "4");
+
+		assertNotNull("Check ref", ref);
+		CheckService cs = (CheckService) sc.getService(ref);
+		assertTrue("Check invoke", cs.check());
+		
+		comp3.dispose();
+		comp2.dispose();
+		empty.dispose();
+	}
+
+	
+	public void testApplication() {
+		Factory factory = Utils.getFactoryByName(context, "composite.test.1");
+		ComponentInstance ci = null;
+		Properties props = new Properties();
+		props.put("name", "Test");
+		try {
+			ci = factory.createComponentInstance(props);
+		} catch(Exception e) {
+			fail("Cannot instantiate Test " + e.getMessage());
+		}
+		
+		assertTrue("Check ci state", ci.getState() == ComponentInstance.VALID );
+		
+		ServiceReference[] refs = null;
+		try {
+			refs = context.getServiceReferences(CheckService.class.getName(), "(instance.name=Test)");
+		} catch (InvalidSyntaxException e) {
+			fail("Invalid filter : " + e.getMessage());
+		}
+		assertNotNull("Check refs not null", refs);
+		CheckService cs = (CheckService) context.getService(refs[0]);
+		
+		assertTrue("Check invocation", cs.check());
+		ci.dispose();
+		
+	}
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/ConfigurationTestSuite.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,25 @@
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+
+import fr.imag.adele.escoffier.utf.framework.TestSuite;
+
+public class ConfigurationTestSuite extends TestSuite {
+	
+	public ConfigurationTestSuite(BundleContext bc) { super(bc); }
+
+	public List suite() {
+		List suite = new ArrayList();
+		suite.add(new SimpleProperties(context));
+		suite.add(new DynamicallyConfigurableProperties(context));
+        suite.add(new TestFieldProperties(context));
+        suite.add(new TestMethodProperties(context));
+        suite.add(new TestBothProperties(context));
+		suite.add(new TestSuperMethodProperties(context));
+		return suite;
+	}
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/DynamicallyConfigurableProperties.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,166 @@
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedServiceFactory;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class DynamicallyConfigurableProperties extends TestCase {
+
+	ComponentInstance instance;
+	
+	public DynamicallyConfigurableProperties(BundleContext bc) { super(bc); }
+	
+	public void setUp() {
+		String type = "FooProviderType-3";
+		
+		Properties p1 = new Properties();
+		p1.put("name", "instance");
+		p1.put("foo", "foo");
+		p1.put("bar", "2");
+		p1.put("baz", "baz");
+		instance = Utils.getComponentInstance(context, type, p1);
+	}
+	
+	public void tearDown() {
+		instance.dispose();
+		instance = null;
+	}
+	
+	public void testStatic() {
+		ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+		assertNotNull("Check FS availability", fooRef);
+		String fooP = (String) fooRef.getProperty("foo");
+		Integer barP = (Integer) fooRef.getProperty("bar");
+		String bazP = (String) fooRef.getProperty("baz");
+		assertEquals("Check foo equality -1", fooP, "foo");
+		assertEquals("Check bar equality -1", barP, new Integer(2));
+		assertEquals("Check baz equality -1", bazP, "baz");
+		
+		ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+		assertNotNull("Check ManagedServiceFactory availability", msRef);
+		
+		
+		// Configuration of baz
+		Properties conf = new Properties();
+		conf.put("baz", "zab");
+		conf.put("bar", new Integer(2));
+		conf.put("foo", "foo");
+		ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+		try {
+			ms.updated(instance.getInstanceName(), conf);
+		} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+		
+		// Recheck props
+		fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+		fooP = (String) fooRef.getProperty("foo");
+		barP = (Integer) fooRef.getProperty("bar");
+		bazP = (String) fooRef.getProperty("baz");
+		assertEquals("Check foo equality -2", fooP, "foo");
+		assertEquals("Check bar equality -2", barP, new Integer(2));
+		assertEquals("Check baz equality -2", bazP, "zab");
+		context.ungetService(msRef);
+	}
+	
+	public void testDynamic() {
+		ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+		assertNotNull("Check FS availability", fooRef);
+		
+		String fooP = (String) fooRef.getProperty("foo");
+		Integer barP = (Integer) fooRef.getProperty("bar");
+		String bazP = (String) fooRef.getProperty("baz");
+		
+		assertEquals("Check foo equality", fooP, "foo");
+		assertEquals("Check bar equality", barP, new Integer(2));
+		assertEquals("Check baz equality", bazP, "baz");
+		
+		ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+		assertNotNull("Check ManagedServiceFactory availability", msRef);
+		
+		// Configuration of baz
+		Properties conf = new Properties();
+		conf.put("baz", "zab");
+		conf.put("foo", "oof");
+		conf.put("bar", new Integer(0));
+		ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+		try {
+			ms.updated(instance.getInstanceName(), conf);
+		} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+		
+		// Recheck props
+		fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+		fooP = (String) fooRef.getProperty("foo");
+		barP = (Integer) fooRef.getProperty("bar");
+		bazP = (String) fooRef.getProperty("baz");
+		
+		assertEquals("Check foo equality", fooP, "oof");
+		assertEquals("Check bar equality", barP, new Integer(0));
+		assertEquals("Check baz equality", bazP, "zab");
+		
+		// Check field value
+		FooService fs = (FooService) context.getService(fooRef);
+		Properties p = fs.fooProps();
+		fooP = (String) p.get("foo");
+		barP = (Integer) p.get("bar");
+		
+		assertEquals("Check foo field equality", fooP, "oof");
+		assertEquals("Check bar field equality", barP, new Integer(0));
+		
+		context.ungetService(fooRef);
+		context.ungetService(msRef);
+	}
+	
+	public void testPropagation() {
+		ServiceReference fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+		assertNotNull("Check FS availability", fooRef);
+		
+		String fooP = (String) fooRef.getProperty("foo");
+		Integer barP = (Integer) fooRef.getProperty("bar");
+		String bazP = (String) fooRef.getProperty("baz");
+		
+		assertEquals("Check foo equality", fooP, "foo");
+		assertEquals("Check bar equality", barP, new Integer(2));
+		assertEquals("Check baz equality", bazP, "baz");
+		
+		ServiceReference msRef = Utils.getServiceReferenceByName(context, ManagedServiceFactory.class.getName(), instance.getFactory().getName());
+		assertNotNull("Check ManagedServiceFactory availability", msRef);
+		
+		// Configuration of baz
+		Properties conf = new Properties();
+		conf.put("baz", "zab");
+		conf.put("foo", "foo");
+		conf.put("bar", new Integer(2));
+		conf.put("propagated1", "propagated");
+		conf.put("propagated2", new Integer(1));
+		ManagedServiceFactory ms = (ManagedServiceFactory) context.getService(msRef);
+		try {
+			ms.updated(instance.getInstanceName(), conf);
+		} catch (ConfigurationException e) { fail("Configuration Exception : " + e); }
+		
+		// Recheck props
+		fooRef = Utils.getServiceReferenceByName(context, FooService.class.getName(), instance.getInstanceName());
+		fooP = (String) fooRef.getProperty("foo");
+		barP = (Integer) fooRef.getProperty("bar");
+		bazP = (String) fooRef.getProperty("baz");
+		assertNotNull("Check the propagated1 existency", fooRef.getProperty("propagated1"));
+		String prop1 = (String) fooRef.getProperty("propagated1");
+		assertNotNull("Check the propagated2 existency", fooRef.getProperty("propagated2"));
+		Integer prop2 = (Integer) fooRef.getProperty("propagated2");
+		
+		assertEquals("Check foo equality", fooP, "foo");
+		assertEquals("Check bar equality", barP, new Integer(2));
+		assertEquals("Check baz equality", bazP, "zab");
+		assertEquals("Check propagated1 equality", prop1, "propagated");
+		assertEquals("Check propagated2 equality", prop2, new Integer(1));
+		
+		context.ungetService(msRef);
+	}
+
+}

Added: felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java?rev=579291&view=auto
==============================================================================
--- felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java (added)
+++ felix/sandbox/clement/Tests/Suite/src/main/java/org/apache/felix/ipojo/test/scenarios/configuration/SimpleProperties.java Tue Sep 25 08:06:53 2007
@@ -0,0 +1,157 @@
+package org.apache.felix.ipojo.test.scenarios.configuration;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.test.scenarios.service.FooService;
+import org.apache.felix.ipojo.test.scenarios.util.Utils;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import fr.imag.adele.escoffier.utf.framework.TestCase;
+
+public class SimpleProperties extends TestCase {
+	
+	ComponentInstance fooProvider1;
+	ComponentInstance fooProvider2;
+	
+	public SimpleProperties(BundleContext bc) { super(bc); }
+	
+	public void setUp() {
+		String type = "FooProviderType-Conf";
+		
+		Properties p1 = new Properties();
+		p1.put("name", "FooProvider-1");
+		fooProvider1 = Utils.getComponentInstance(context, type, p1);
+		
+		Properties p2 = new Properties();
+		p2.put("name", "FooProvider-2");
+		p2.put("int", new Integer(4));
+		p2.put("boolean", new Boolean(false));
+		p2.put("string", new String("bar"));
+		p2.put("strAProp", new String[] {"bar", "foo"});
+		p2.put("intAProp", new int[] {1, 2, 3});
+		fooProvider2 = Utils.getComponentInstance(context, type, p2);
+	}
+	
+	public void tearDown() {
+		fooProvider1.dispose();
+		fooProvider2.dispose();
+		fooProvider1 = null;
+		fooProvider2 = null;
+	}
+	
+	public void testComponentTypeConfiguration() {
+		ServiceReference ref = Utils.getServiceReferenceByName(context, FooService.class.getName(), fooProvider1.getInstanceName());
+		assertNotNull("Check FooService availability", ref);
+		FooService fs = (FooService) context.getService(ref);
+		Properties toCheck = fs.fooProps();
+		
+		Integer intProp = (Integer) toCheck.get("intProp");
+		Boolean boolProp = (Boolean) toCheck.get("boolProp");
+		String strProp = (String) toCheck.get("strProp");
+		String[] strAProp = (String[]) toCheck.get("strAProp");
+		int[] intAProp = (int[]) toCheck.get("intAProp");
+		
+		assertEquals("Check intProp equality (1)", intProp, new Integer(2));
+		assertEquals("Check longProp equality (1)", boolProp, new Boolean(false));
+		assertEquals("Check strProp equality (1)", strProp, new String("foo"));
+		assertNotNull("Check strAProp not nullity (1)", strAProp);
+		String[] v = new String[] {"foo", "bar"};
+		for (int i = 0; i < strAProp.length; i++) {
+			if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality (1) : " + strAProp[i] + " != " + v[i]); }
+		}
+		assertNotNull("Check intAProp not nullity", intAProp);
+		int[] v2 = new int[] {1, 2, 3};
+		for (int i = 0; i < intAProp.length; i++) {
+			if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (1) : " + intAProp[i] + " != " + v2[i]); }
+		}
+		
+		// change the field value
+		assertTrue("Invoke the fs service", fs.foo());
+		toCheck = fs.fooProps();
+		
+		
+		//	Re-check the property (change)
+		intProp = (Integer) toCheck.get("intProp");
+		boolProp = (Boolean) toCheck.get("boolProp");
+		strProp = (String) toCheck.get("strProp");
+		strAProp = (String[]) toCheck.get("strAProp");
+		intAProp = (int[]) toCheck.get("intAProp");
+		
+		assertEquals("Check intProp equality (2) ("+intProp+")", intProp, new Integer(3));
+		assertEquals("Check longProp equality (2)", boolProp, new Boolean(true));
+		assertEquals("Check strProp equality (2)", strProp, new String("bar"));
+		assertNotNull("Check strAProp not nullity (2)", strAProp);
+		v = new String[] {"foo", "bar", "baz"};
+		for (int i = 0; i < strAProp.length; i++) {
+			if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality (2)"); }
+		}
+		assertNotNull("Check intAProp not nullity (2)", intAProp);
+		v2 = new int[] {3, 2, 1};
+		for (int i = 0; i < intAProp.length; i++) {
+			if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality (2) : " + intAProp[i] + " != " + v2[i]); }
+		}
+		
+		fs = null;
+		context.ungetService(ref);
+	}
+	
+	public void testInstanceConfiguration() {
+		ServiceReference sr = Utils.getServiceReferenceByName(context, FooService.class.getName(), "FooProvider-2");
+		assertNotNull("Check the availability of the FS service", sr);
+		
+		FooService fs = (FooService) context.getService(sr);
+		Properties toCheck = fs.fooProps();
+		
+		// Check service properties
+		Integer intProp = (Integer) toCheck.get("intProp");
+		Boolean boolProp = (Boolean) toCheck.get("boolProp");
+		String strProp = (String) toCheck.get("strProp");
+		String[] strAProp = (String[]) toCheck.get("strAProp");
+		int[] intAProp = (int[]) toCheck.get("intAProp");
+		
+		assertEquals("Check intProp equality", intProp, new Integer(4));
+		assertEquals("Check longProp equality", boolProp, new Boolean(false));
+		assertEquals("Check strProp equality", strProp, new String("bar"));
+		assertNotNull("Check strAProp not nullity", strAProp);
+		String[] v = new String[] {"bar", "foo"};
+		for (int i = 0; i < strAProp.length; i++) {
+			if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+		}
+		assertNotNull("Check intAProp not nullity", intAProp);
+		int[] v2 = new int[] {1, 2, 3};
+		for (int i = 0; i < intAProp.length; i++) {
+			if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+		}
+		
+		
+		assertTrue("invoke fs", fs.foo());
+		toCheck = fs.fooProps();
+		
+		// Re-check the property (change)
+		intProp = (Integer) toCheck.get("intProp");
+		boolProp = (Boolean) toCheck.get("boolProp");
+		strProp = (String) toCheck.get("strProp");
+		strAProp = (String[]) toCheck.get("strAProp");
+		intAProp = (int[]) toCheck.get("intAProp");
+		
+		assertEquals("Check intProp equality", intProp, new Integer(3));
+		assertEquals("Check longProp equality", boolProp, new Boolean(true));
+		assertEquals("Check strProp equality", strProp, new String("foo"));
+		assertNotNull("Check strAProp not nullity", strAProp);
+		v = new String[] {"foo", "bar", "baz"};
+		for (int i = 0; i < strAProp.length; i++) {
+			if(!strAProp[i].equals(v[i])) { fail("Check the strAProp Equality"); }
+		}
+		assertNotNull("Check intAProp not nullity", intAProp);
+		v2 = new int[] {3, 2, 1};
+		for (int i = 0; i < intAProp.length; i++) {
+			if(intAProp[i] != v2[i]) { fail("Check the intAProp Equality"); }
+		}
+		
+		fs = null;
+		context.ungetService(sr);	
+	}
+
+}