Added: felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp6.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp6.java?rev=654249&view=auto ============================================================================== --- felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp6.java (added) +++ felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp6.java Wed May 7 13:11:29 2008 @@ -0,0 +1,284 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.ipojo.test.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.junit4osgi.OSGiTestCase; +import org.apache.felix.ipojo.test.composite.component.TotoProvider; +import org.apache.felix.ipojo.test.composite.service.Tata; +import org.apache.felix.ipojo.test.composite.service.Toto; +import org.apache.felix.ipojo.test.composite.util.Utils; +import org.osgi.framework.ServiceReference; + +public class TestComp6 extends OSGiTestCase { + + private ComponentFactory tataFactory; + private ComponentFactory totoFactory; + + private ComponentInstance totoProv, totoProv2; + private ComponentInstance under; + + 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/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp7.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp7.java?rev=654249&view=auto ============================================================================== --- felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp7.java (added) +++ felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp7.java Wed May 7 13:11:29 2008 @@ -0,0 +1,333 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.ipojo.test.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.junit4osgi.OSGiTestCase; +import org.apache.felix.ipojo.test.composite.component.TotoProvider; +import org.apache.felix.ipojo.test.composite.service.Tota; +import org.apache.felix.ipojo.test.composite.util.Utils; +import org.osgi.framework.ServiceReference; + +public class TestComp7 extends OSGiTestCase { + + private ComponentFactory tataFactory; + private ComponentFactory totoFactory; + private ComponentFactory tataFactory2; + + private ComponentInstance totoProv, totoProv2; + private ComponentInstance under; + + 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", 1, tata.intValue()); + 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/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp8.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp8.java?rev=654249&view=auto ============================================================================== --- felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp8.java (added) +++ felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/provides/TestComp8.java Wed May 7 13:11:29 2008 @@ -0,0 +1,365 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.ipojo.test.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.junit4osgi.OSGiTestCase; +import org.apache.felix.ipojo.test.composite.component.TotoProvider; +import org.apache.felix.ipojo.test.composite.component.TotoProviderGlue; +import org.apache.felix.ipojo.test.composite.service.Tota; +import org.apache.felix.ipojo.test.composite.util.Utils; +import org.osgi.framework.ServiceReference; + +public class TestComp8 extends OSGiTestCase { + + private ComponentFactory tataFactory; + private ComponentFactory totoFactory; + private ComponentFactory tataFactory2; + + private ComponentInstance totoProv, totoProv2; + private ComponentInstance under; + + 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/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/test/CompositeTest.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/test/CompositeTest.java?rev=654249&view=auto ============================================================================== --- felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/test/CompositeTest.java (added) +++ felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/java/org/apache/felix/ipojo/test/composite/test/CompositeTest.java Wed May 7 13:11:29 2008 @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.ipojo.test.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.junit4osgi.OSGiTestCase; +import org.apache.felix.ipojo.test.composite.service.BazService; +import org.apache.felix.ipojo.test.composite.service.CheckService; +import org.apache.felix.ipojo.test.composite.service.FooService; +import org.apache.felix.ipojo.test.composite.util.Utils; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +public class CompositeTest extends OSGiTestCase { + + 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/trunk/ipojo/tests/tests.composite.service.providing/src/main/resources/metadata.xml URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/resources/metadata.xml?rev=654249&view=auto ============================================================================== --- felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/resources/metadata.xml (added) +++ felix/trunk/ipojo/tests/tests.composite.service.providing/src/main/resources/metadata.xml Wed May 7 13:11:29 2008 @@ -0,0 +1,150 @@ +<ipojo> + <composite name="composite.test.3" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.BazService" + aggregate="true" filter="(factory.name=BazProviderType)" /> + <provides action="export" + specification="org.apache.felix.ipojo.test.composite.service.BazService" /> + </composite> + + <composite name="composite.test.2" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.CheckService" + filter="(factory.name=Baz2CheckProvider)" /> + <provides action="export" + specification="org.apache.felix.ipojo.test.composite.service.CheckService" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.BazService" + scope="composite" /> + </composite> + + <composite name="composite.test.1" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.BazService" + filter="(factory.name=composite.test.3)" /> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.CheckService" + filter="(factory.name=composite.test.2)" /> + <provides action="export" + specification="org.apache.felix.ipojo.test.composite.service.CheckService" /> + </composite> + + <composite name="composite.instantiator" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.BazService" + filter="(factory.name=composite.test.3)" /> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.FooService" /> + <provides action="export" + specification="org.apache.felix.ipojo.test.composite.service.BazService" /> + <provides action="export" + specification="org.apache.felix.ipojo.test.composite.service.FooService" /> + </composite> + + <!-- Test composition provides --> + + <composite name="comp-0" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota" /> + </composite> + + <composite name="comp-1" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota"> + <delegation method="tataInt" policy="One" /> + <delegation method="toto1" policy="All" /> + </provides> + </composite> + + <composite name="comp-2" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" + aggregate="true" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" + aggregate="true" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota"> + <delegation method="tataInt" policy="One" /> + <delegation method="toto1" policy="All" /> + </provides> + </composite> + + <composite name="comp-3" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" + optional="true" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota"> + </provides> + </composite> + + <composite name="comp-4" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" + optional="true" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota"> + <delegation method="tataInt" policy="One" /> + <delegation method="toto1" policy="All" /> + </provides> + </composite> + + <composite name="comp-5" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" + aggregate="true" /> + <!-- <subservice action="import" specification="org.apache.felix.ipojo.test.composite.service.Toto" aggregate ="true" optional="true"/> --> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota"> + <delegation method="tataInt" policy="One" /> + <delegation method="toto1" policy="All" /> + </provides> + </composite> + + <composite name="comp-6" architecture="true"> + <subservice action="instantiate" + specification="org.apache.felix.ipojo.test.composite.service.Tata" + aggregate="true" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" + aggregate="true" optional="true" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Toto"> + <delegation method="toto1" policy="All" /> + </provides> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tata"> + <delegation method="tataInt" policy="One" /> + </provides> + </composite> + + <composite name="comp-7" architecture="true"> + <instance component="tata" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota" /> + </composite> + + <composite name="comp-8" architecture="true"> + <instance component="tata" /> + <instance component="totoglue" /> + <subservice action="import" + specification="org.apache.felix.ipojo.test.composite.service.Toto" /> + <provides action="implement" + specification="org.apache.felix.ipojo.test.composite.service.Tota" /> + </composite> +</ipojo>
