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 2013/02/26 14:02:40 UTC
svn commit: r1450158 [2/9] - in /felix/trunk/ipojo/runtime/composite-it: ./
src/ src/it/ src/it/ipojo-composite-import-export-test/
src/it/ipojo-composite-import-export-test/src/
src/it/ipojo-composite-import-export-test/src/main/ src/it/ipojo-composit...
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/TotoProviderGlue.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,81 @@
+/*
+ * 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.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.Toto;
+
+import java.util.Properties;
+
+
+public class TotoProviderGlue implements Toto {
+
+ Toto m_toto;
+
+ private int i = 0;
+ public static int toto = 0;
+ public static int toto_2 = 0;
+ public static int toto_3 = 0;
+ public static int toto_4 = 0;
+ public static int toto1 = 0;
+
+ public int count() {
+ return i;
+ }
+
+ public void toto() {
+ toto++;
+ m_toto.toto();
+ }
+
+ public void toto(int i, int j) {
+ toto_2++;
+ m_toto.toto(i, j);
+ }
+
+ public String toto(String a) {
+ toto_3++;
+ return a;
+ }
+
+ public String toto(String[] a) {
+ toto_4++;
+ return "toto";
+ }
+
+ public void toto1(String j) {
+ i++;
+ toto1++;
+ m_toto.toto1(j);
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("i", new Integer(i));
+ props.put("gtoto", new Integer(toto));
+ props.put("gtoto_2", new Integer(toto_2));
+ props.put("gtoto_3", new Integer(toto_3));
+ props.put("gtoto_4", new Integer(toto_4));
+ props.put("gtoto1", new Integer(toto1));
+ props.put("glue", "glue");
+ Properties p2 = m_toto.getProps();
+ props.putAll(p2);
+ return props;
+ }
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/A123/CheckService2.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,25 @@
+/*
+ * 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.runtime.core.services.A123;
+
+public interface CheckService2 {
+
+ public boolean check();
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BarService.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,29 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface BarService {
+
+ public boolean bar();
+
+ public Properties getProps();
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/BazService.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface BazService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/CheckService.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,31 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface CheckService {
+
+ public static final String foo = "foo";
+
+ public boolean check();
+
+ public Properties getProps();
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/FooService.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,39 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface FooService {
+
+ boolean foo();
+
+ Properties fooProps();
+
+ Boolean getObject();
+
+ boolean getBoolean();
+
+ int getInt();
+
+ long getLong();
+
+ double getDouble();
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tata.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,62 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface Tata {
+
+ public Properties getPropsTata();
+
+ public void tata();
+
+ public int tataInt(int i);
+ public long tataLong(long l);
+ public double tataDouble(double d);
+ public char tataChar(char c);
+ public boolean tataBoolean(boolean b);
+ public short tataShort(short s);
+ public float tataFloat(float f);
+ public byte tataByte(byte b);
+
+ public int[] tataInts(int[] its);
+ public long[] tataLongs(long[] l);
+ public double[] tataDoubles(double[] d);
+ public char[] tataChars(char[] c);
+ public boolean[] tataBooleans(boolean[] b);
+ public short[] tataShorts(short[] s);
+ public float[] tataFloats(float[] f);
+ public byte[] tataBytes(byte[] b);
+
+ public String tataStr();
+ public String[] tataStrs();
+
+ public void tata(int i, int j);
+ public void tata(String s);
+
+ public String tata1(String a);
+ public String tata1(char[] a);
+
+ public String tata5(String a, int i);
+ public String tata5(String[] a, int i);
+ public String tata5(String a, int[] i);
+
+ public long add(int i, int j, int k);
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Tota.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,78 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface Tota {
+
+ public static final String specification="specification { " +
+ "requires { " +
+ "$specification=\"org.apache.felix.ipojo.test.composite.service.Toto\" " +
+ "$optional=\"true\" " +
+ "$aggregate=\"true\" " +
+ "$type=\"service\" " +
+ "} }";
+
+ public Properties getProps() throws UnsupportedOperationException;;
+ public Properties getPropsTata();
+
+ public void tata();
+
+ public int tataInt(int i);
+ public long tataLong(long l);
+ public double tataDouble(double d);
+ public char tataChar(char c);
+ public boolean tataBoolean(boolean b);
+ public short tataShort(short s);
+ public float tataFloat(float f);
+ public byte tataByte(byte b);
+
+ public int[] tataInts(int[] its);
+ public long[] tataLongs(long[] l);
+ public double[] tataDoubles(double[] d);
+ public char[] tataChars(char[] c);
+ public boolean[] tataBooleans(boolean[] b);
+ public short[] tataShorts(short[] s);
+ public float[] tataFloats(float[] f);
+ public byte[] tataBytes(byte[] b);
+
+ public String tataStr();
+ public String[] tataStrs();
+
+ public void tata(int i, int j);
+ public void tata(String s);
+
+ public String tata1(String a);
+ public String tata1(char[] a);
+
+ public String tata5(String a, int i);
+ public String tata5(String[] a, int i);
+ public String tata5(String a, int[] i);
+
+ public long add(int i, int j, int k);
+
+ public void toto() throws UnsupportedOperationException;
+ public void toto(int i, int j) throws UnsupportedOperationException;
+ public String toto(String a) throws UnsupportedOperationException;
+
+ public void toto1(String j) throws UnsupportedOperationException;
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/java/org/apache/felix/ipojo/runtime/core/services/Toto.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.runtime.core.services;
+
+import java.util.Properties;
+
+public interface Toto {
+
+ public Properties getProps();
+
+ public void toto();
+ public void toto(int i, int j);
+ public String toto(String a);
+ public String toto(String[] a);
+
+ public void toto1(String j);
+
+ public int count();
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata-import-export.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata-import-export.xml?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata-import-export.xml (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata-import-export.xml Tue Feb 26 13:02:34 2013
@@ -0,0 +1,87 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd
+ org.apache.felix.composite http://felix.apache.org/ipojo/schemas/SNAPSHOT/composite.xsd"
+ xmlns="org.apache.felix.ipojo"
+ xmlns:comp="org.apache.felix.ipojo.composite"
+ xmlns:cs="org.apache.felix.ipojo.test.composite.handler.CheckServiceHandler">
+ <comp:composite name="composite.requires.1" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.FooService"
+ scope="composite" />
+ </comp:composite>
+
+ <comp:composite name="composite.requires.2" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.FooService"
+ aggregate="true" scope="composite" />
+ </comp:composite>
+
+ <comp:composite name="composite.requires.3" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.FooService"
+ optional="true" scope="composite" />
+ </comp:composite>
+
+ <comp:composite name="composite.requires.4" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.FooService"
+ optional="true" aggregate="true" scope="composite" />
+ </comp:composite>
+
+ <comp:composite name="composite.requires.5" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.FooService"
+ filter="(&(int=2)(long=40))" scope="composite" />
+ </comp:composite>
+
+ <comp:composite name="composite.export.1" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ aggregate="true" optional="true" filter="(!(instance.name=export))"
+ scope="composite" />
+ <comp:provides action="export"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService" />
+ </comp:composite>
+
+ <comp:composite name="composite.export.2" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ scope="composite" aggregate="true" optional="true"
+ filter="(!(instance.name=export))" />
+ <comp:provides action="export"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ optional="true" />
+ </comp:composite>
+
+ <comp:composite name="composite.export.3" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ scope="composite" aggregate="true" optional="true"
+ filter="(!(instance.name=export))" />
+ <comp:provides action="export"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ aggregate="true" />
+ </comp:composite>
+
+ <comp:composite name="composite.export.4" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ aggregate="true" optional="true" filter="(!(instance.name=export))"
+ scope="composite" />
+ <comp:provides action="export"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ aggregate="true" optional="true" />
+ </comp:composite>
+
+ <comp:composite name="composite.export.5" architecture="true">
+ <subservice action="import"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ aggregate="true" optional="true" filter="(!(instance.name=export))"
+ scope="composite" />
+ <comp:provides action="export"
+ specification="org.apache.felix.ipojo.runtime.core.services.BazService"
+ filter="(instance.name=foo1)" />
+ </comp:composite>
+
+</ipojo>
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata.xml?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata.xml (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/main/resources/metadata.xml Tue Feb 26 13:02:34 2013
@@ -0,0 +1,112 @@
+<ipojo
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd
+ org.apache.felix.composite http://felix.apache.org/ipojo/schemas/SNAPSHOT/composite.xsd"
+ xmlns="org.apache.felix.ipojo"
+ xmlns:comp="org.apache.felix.ipojo.composite">
+ <!-- Used component type -->
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="COMPO-FooProviderType-1" architecture="true">
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderType1"
+ name="COMPO-FooProviderType-2" architecture="true">
+ <provides>
+ <property name="int" type="int" value="2" />
+ <property name="long" type="long" value="40" />
+ <property name="string" type="java.lang.String" value="foo" />
+ <property name="strAProp" type="java.lang.String[]"
+ value="{foo, bar}" />
+ <property name="intAProp" type="int[]" value="{1,2,3}" />
+ </provides>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn"
+ name="COMPO-FooProviderType-Dyn" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="2" />
+ <property name="boolean" field="boolProp" value="false" />
+ <property name="string" field="strProp" value="foo" />
+ <property name="strAProp" field="strAProp"
+ value="{foo, bar}" />
+ <property name="intAProp" field="intAProp" value="{ 1,2,3}" />
+ </provides>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooProviderTypeDyn2"
+ name="COMPO-FooProviderType-Dyn2" architecture="true">
+ <provides>
+ <property name="int" field="intProp" value="4" />
+ <property name="boolean" field="boolProp" />
+ <property name="string" field="strProp" />
+ <property name="strAProp" field="strAProp" />
+ <property name="intAProp" field="intAProp"
+ value="{1, 2,3 }" />
+ </provides>
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.CheckServiceProvider"
+ name="COMPO-SimpleCheckServiceProvider" architecture="true">
+ <requires field="fs" />
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"
+ name="COMPO-FooBarProviderType-1" architecture="true">
+ <provides />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"
+ name="COMPO-FooBarProviderType-2" architecture="true">
+ <provides
+ specifications="{org.apache.felix.ipojo.runtime.core.services.FooService, org.apache.felix.ipojo.runtime.core.services.BarService }" />
+ </component>
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.FooBarProviderType1"
+ name="COMPO-FooBarProviderType-3" architecture="true">
+ <provides
+ specifications="{org.apache.felix.ipojo.runtime.core.services.FooService}">
+ <property name="baz" type="java.lang.String" value="foo" />
+ </provides>
+ <provides
+ specifications="{org.apache.felix.ipojo.runtime.core.services.BarService}">
+ <property name="baz" type="java.lang.String" value="bar" />
+ </provides>
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.BazProviderType1"
+ name="BazProviderType">
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.TataProvider"
+ name="tata">
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.TotoProvider"
+ name="toto" architecture="true">
+ <provides />
+ </component>
+
+ <component
+ classname="org.apache.felix.ipojo.runtime.core.components.TotoProviderGlue"
+ name="totoglue">
+ <requires field="m_toto" scope="composite" />
+ </component>
+
+ <!-- Composite -->
+ <comp:composite name="composite.empty" architecture="true">
+ </comp:composite>
+
+ <component classname="org.apache.felix.ipojo.runtime.core.components.Baz2CheckProvider" name="Baz2CheckProvider" architecture="true">
+ <requires field="fs" scope="composite"/>
+ <provides/>
+ </component>
+
+</ipojo>
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/Common.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,225 @@
+package org.apache.felix.ipojo.runtime.core;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.TrueFileFilter;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.composite.CompositeManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.CompositeOption;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.ops4j.pax.exam.spi.reactors.PerMethod;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
+import org.ops4j.pax.tinybundles.core.TinyBundles;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
+import org.ow2.chameleon.testing.helpers.OSGiHelper;
+import org.ow2.chameleon.testing.tinybundles.ipojo.IPOJOStrategy;
+import org.slf4j.LoggerFactory;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import static junit.framework.Assert.fail;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+/**
+ * Bootstrap the test from this project
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerMethod.class)
+public class Common {
+
+ @Inject
+ protected
+ BundleContext bc;
+
+ protected OSGiHelper osgiHelper;
+ protected IPOJOHelper ipojoHelper;
+
+ protected boolean deployTestedBundle = true;
+
+ @Configuration
+ public Option[] config() throws IOException {
+ Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+ root.setLevel(Level.INFO);
+
+ if (deployTestedBundle) {
+ return options(
+ cleanCaches(),
+ ipojoBundles(),
+ junitBundles(),
+ testedBundle(),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ );
+ } else {
+ return options(
+ cleanCaches(),
+ ipojoBundles(),
+ junitBundles(),
+ systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("WARN")
+ );
+ }
+ }
+
+ public static Option junitAndMockitoBundles() {
+ return new DefaultCompositeOption(
+ // Repository required to load harmcrest (OSGi-fied version).
+ repository("http://repository.springsource.com/maven/bundles/external").id(
+ "com.springsource.repository.bundles.external"),
+
+ // Mockito without Hamcrest and Objenesis
+ mavenBundle("org.mockito", "mockito-core", "1.9.5"),
+
+ // Hamcrest with a version matching the range expected by Mockito
+ mavenBundle("org.hamcrest", "com.springsource.org.hamcrest.core", "1.1.0"),
+
+ // Objenesis with a version matching the range expected by Mockito
+ wrappedBundle(mavenBundle("org.objenesis", "objenesis", "1.2"))
+ .exports("*;version=1.2"),
+
+ // The default JUnit bundle also exports Hamcrest, but with an (incorrect) version of
+ // 4.9 which does not match the Mockito import.
+ CoreOptions.junitBundles(),
+
+ /*
+ * Felix has implicit boot delegation enabled by default. It conflicts with Mockito:
+ * java.lang.LinkageError: loader constraint violation in interface itable initialization:
+ * when resolving method "org.osgi.service.useradmin.User$$EnhancerByMockitoWithCGLIB$$dd2f81dc
+ * .newInstance(Lorg/mockito/cglib/proxy/Callback;)Ljava/lang/Object;" the class loader
+ * (instance of org/mockito/internal/creation/jmock/SearchingClassLoader) of the current class,
+ * org/osgi/service/useradmin/User$$EnhancerByMockitoWithCGLIB$$dd2f81dc, and the class loader
+ * (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for interface
+ * org/mockito/cglib/proxy/Factory have different Class objects for the type org/mockito/cglib/
+ * proxy/Callback used in the signature
+ *
+ * So we disable the bootdelegation.
+ */
+ frameworkProperty("felix.bootdelegation.implicit").value("false")
+ );
+ }
+
+
+ @Before
+ public void commonSetUp() {
+ osgiHelper = new OSGiHelper(bc);
+ ipojoHelper = new IPOJOHelper(bc);
+
+ // Dump OSGi Framework information
+ String vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VENDOR);
+ if (vendor == null) {
+ vendor = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_SYMBOLICNAME);
+ }
+ String version = (String) osgiHelper.getBundle(0).getHeaders().get(Constants.BUNDLE_VERSION);
+ System.out.println("OSGi Framework : " + vendor + " - " + version);
+ }
+
+ @After
+ public void commonTearDown() {
+ ipojoHelper.dispose();
+ osgiHelper.dispose();
+ }
+
+ public BundleContext getContext() {
+ return bc;
+ }
+
+ public static ServiceContext getServiceContext(ComponentInstance ci) {
+ if (ci instanceof CompositeManager) {
+ return ((CompositeManager) ci).getServiceContext();
+ } else {
+ throw new RuntimeException("Cannot get the service context from a non composite instance");
+ }
+ }
+
+ public CompositeOption ipojoBundles() {
+ return new DefaultCompositeOption(
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo").versionAsInProject(),
+ mavenBundle("org.apache.felix", "org.apache.felix.ipojo.composite").versionAsInProject(),
+ mavenBundle("org.ow2.chameleon.testing", "osgi-helpers").versionAsInProject(),
+ // configuration admin
+ mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject()
+ );
+ }
+
+ public Option testedBundle() throws MalformedURLException {
+ File out = new File("target/tested/bundle.jar");
+ if (out.exists()) {
+ return bundle(out.toURI().toURL().toExternalForm());
+ }
+
+ TinyBundle tested = TinyBundles.bundle();
+
+ // We look inside target/classes to find the class and resources
+ File classes = new File("target/classes");
+ Collection<File> files = FileUtils.listFilesAndDirs(classes, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
+ List<File> services = new ArrayList<File>();
+ for (File file : files) {
+ if (file.isDirectory()) {
+ // By convention we export of .services and .service package
+ if (file.getName().endsWith("services") || file.getName().endsWith("service")) {
+ services.add(file);
+ }
+ } else {
+ // We need to compute the path
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+ tested.add(path, file.toURI().toURL());
+ System.out.println(file.getName() + " added to " + path);
+ }
+ }
+
+ // Export the inherited package, components and strategies
+ String export = "";
+ for (File file : services) {
+ if (export.length() > 0) { export += ", "; }
+ String path = file.getAbsolutePath().substring(classes.getAbsolutePath().length() +1);
+ String packageName = path.replace('/', '.');
+ export += packageName;
+ }
+
+ System.out.println("Exported packages : " + export);
+
+ InputStream inputStream = tested
+ .set(Constants.BUNDLE_SYMBOLICNAME, "test.bundle")
+ .set(Constants.IMPORT_PACKAGE, "*")
+ .set(Constants.EXPORT_PACKAGE, export)
+ .build(IPOJOStrategy.withiPOJO(new File("src/main/resources")));
+
+ try {
+ org.apache.commons.io.FileUtils.copyInputStreamToFile(inputStream, out);
+ return bundle(out.toURI().toURL().toExternalForm());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Cannot compute the url of the manipulated bundle");
+ } catch (IOException e) {
+ throw new RuntimeException("Cannot write of the manipulated bundle");
+ }
+ }
+
+ public void assertContains(String s, String[] arrays, String object) {
+ for (String suspect : arrays) {
+ if (object.equals(suspect)) {
+ return;
+ }
+ }
+ fail("Assertion failed : " + s);
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestFilteredExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestFilteredExport.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestFilteredExport.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestFilteredExport.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,237 @@
+/*
+ * 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.runtime.core.exporter;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BazService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestFilteredExport extends Common {
+
+ ComponentInstance export1;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ @Before
+ public void setUp() {
+ fooProvider = ipojoHelper.getFactory("BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("instance.name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("instance.name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch (Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = ipojoHelper.getFactory("composite.export.5");
+ Properties props = new Properties();
+ props.put("instance.name", "export");
+ try {
+ export1 = factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export1.dispose();
+ foo1 = null;
+ foo2 = null;
+ export1 = null;
+ }
+
+ @Test
+ public void test1() {
+ export1.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", osgiHelper.getServiceReferences(FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.stop();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check invalidity - 5", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 0);
+ }
+
+ @Test
+ public void test2() {
+ export1.start();
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ @Test
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 2", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 0);
+
+ foo2.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+ @Test
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export1.start();
+ assertTrue("Check validity - 1", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export1.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check invalidity - 4", export1.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+ }
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export1.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export1.getInstanceName() + ")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export1.getInstanceName());
+ if (ref == null) {
+ return false;
+ }
+ BazService fs = (BazService) getContext().getService(ref);
+ return fs.foo();
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestMultipleExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestMultipleExport.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestMultipleExport.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestMultipleExport.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,260 @@
+/*
+ * 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.runtime.core.exporter;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BazService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestMultipleExport extends Common {
+
+ ComponentInstance export3;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ @Before
+ public void setUp() {
+ fooProvider = ipojoHelper.getFactory("BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("instance.name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("instance.name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch (Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = ipojoHelper.getFactory("composite.export.3");
+ Properties props = new Properties();
+ props.put("instance.name", "export");
+ try {
+ export3 = factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export3.dispose();
+ foo1 = null;
+ foo2 = null;
+ export3 = null;
+ }
+
+ @Test
+ public void test1() {
+ export3.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", osgiHelper.getServiceReferences(FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke(1));
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 (" + countFooServiceProvided() + ")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check invalidity - 4", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ @Test
+ public void test2() {
+ export3.start();
+
+ // Test invalidity
+ assertTrue("Check invalidity - 0", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check invalidity - 4", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ @Test
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check invalidity - 3", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+ @Test
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check invalidity - 3", export3.getState() == ComponentInstance.INVALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export3.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export3.getInstanceName() + ")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export3.getInstanceName());
+ if (ref == null) {
+ return false;
+ }
+ BazService fs = (BazService) getContext().getService(ref);
+ getContext().ungetService(ref);
+ return fs.foo();
+ }
+
+ private boolean invoke(int nb) {
+ ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export3.getInstanceName() + ")");
+ if (refs == null) {
+ return false;
+ }
+ if (nb > refs.length) {
+ return false;
+ }
+ for (int i = 0; i < nb; i++) {
+ BazService fs = (BazService) getContext().getService(refs[i]);
+ getContext().ungetService(refs[i]);
+ if (!fs.foo()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalExport.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalExport.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalExport.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,241 @@
+/*
+ * 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.runtime.core.exporter;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BazService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalExport extends Common {
+
+ ComponentInstance export2;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ @Before
+ public void setUp() {
+ fooProvider = ipojoHelper.getFactory("BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("instance.name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("instance.name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch (Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = ipojoHelper.getFactory("composite.export.2");
+ Properties props = new Properties();
+ props.put("instance.name", "export");
+ try {
+ export2 = factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export2.dispose();
+ foo1 = null;
+ foo2 = null;
+ export2 = null;
+ }
+
+ @Test
+ public void test1() {
+ export2.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", osgiHelper.getServiceReferences(FooService.class.getName(), null).length, 0);
+
+ // Test validity
+ assertTrue("Check validity - 0", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 (" + countFooServiceProvided() + ")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ @Test
+ public void test2() {
+ export2.start();
+
+ // Test invalidity
+ assertTrue("Check validity - 0", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke());
+ }
+
+ @Test
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export2.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+ @Test
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export2.start();
+ assertTrue("Check validity - 1", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke());
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export2.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export2.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke());
+ }
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export2.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export2.getInstanceName() + ")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export2.getInstanceName());
+ if (ref == null) {
+ return false;
+ }
+ BazService fs = (BazService) getContext().getService(ref);
+ return fs.foo();
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalMultipleExport.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalMultipleExport.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalMultipleExport.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-import-export-test/src/test/java/org/apache/felix/ipojo/runtime/core/exporter/TestOptionalMultipleExport.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,260 @@
+/*
+ * 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.runtime.core.exporter;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BazService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalMultipleExport extends Common {
+
+ ComponentInstance export3;
+ Factory fooProvider;
+ ComponentInstance foo1 = null, foo2 = null;
+
+ @Before
+ public void setUp() {
+ fooProvider = ipojoHelper.getFactory("BazProviderType");
+ assertNotNull("Check fooProvider availability", fooProvider);
+
+ Properties p1 = new Properties();
+ p1.put("instance.name", "foo1");
+ Properties p2 = new Properties();
+ p2.put("instance.name", "foo2");
+
+ try {
+ foo1 = fooProvider.createComponentInstance(p1);
+ foo2 = fooProvider.createComponentInstance(p2);
+ } catch (Exception e) {
+ fail("Fail to create foos : " + e.getMessage());
+ }
+
+ foo1.stop();
+ foo2.stop();
+
+ Factory factory = ipojoHelper.getFactory("composite.export.4");
+ Properties props = new Properties();
+ props.put("instance.name", "export");
+ try {
+ export3 = factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Fail to instantiate exporter " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ foo1.dispose();
+ foo2.dispose();
+ export3.dispose();
+ foo1 = null;
+ foo2 = null;
+ export3 = null;
+ }
+
+ @Test
+ public void test1() {
+ export3.start();
+
+ // Check that no foo service are available
+ assertEquals("Check no foo service", osgiHelper.getServiceReferences(FooService.class.getName(), null).length, 0);
+
+ // Test invalidity
+ assertTrue("Check validity - 0", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke(1));
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3 (" + countFooServiceProvided() + ")", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ @Test
+ public void test2() {
+ export3.start();
+
+ // Test invalidity
+ assertTrue("Check validity - 0", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 0", isFooServiceProvided());
+ assertEquals("Check number of provides - 0", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 1", invoke());
+
+ foo2.start();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 2", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 3", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 5", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 5", isFooServiceProvided());
+ assertEquals("Check number of provides - 5", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 5", invoke(1));
+ }
+
+ @Test
+ public void test3() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo1.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo2.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo1.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+ @Test
+ public void test4() {
+ foo1.start();
+ foo2.start();
+
+ export3.start();
+ assertTrue("Check validity - 1", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 1", isFooServiceProvided());
+ assertEquals("Check number of provides - 1", countFooServiceProvided(), 2);
+ assertTrue("Check invocation - 1", invoke(2));
+
+ foo2.stop();
+ assertTrue("Check validity - 2", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 2", isFooServiceProvided());
+ assertEquals("Check number of provides - 2", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 2", invoke(1));
+
+ foo1.stop();
+ assertTrue("Check validity - 3", export3.getState() == ComponentInstance.VALID);
+ assertFalse("Check providing - 3", isFooServiceProvided());
+ assertEquals("Check number of provides - 3", countFooServiceProvided(), 0);
+
+ foo2.start();
+ assertTrue("Check validity - 4", export3.getState() == ComponentInstance.VALID);
+ assertTrue("Check providing - 4", isFooServiceProvided());
+ assertEquals("Check number of provides - 4", countFooServiceProvided(), 1);
+ assertTrue("Check invocation - 4", invoke(1));
+ }
+
+
+ private boolean isFooServiceProvided() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export3.getInstanceName());
+ return ref != null;
+ }
+
+ private int countFooServiceProvided() {
+ ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export3.getInstanceName() + ")");
+ return refs.length;
+ }
+
+ private boolean invoke() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(BazService.class.getName(), export3.getInstanceName());
+ if (ref == null) {
+ return false;
+ }
+ BazService fs = (BazService) getContext().getService(ref);
+ getContext().ungetService(ref);
+ return fs.foo();
+ }
+
+ private boolean invoke(int nb) {
+ ServiceReference[] refs = osgiHelper.getServiceReferences(BazService.class.getName(), "(instance.name=" + export3.getInstanceName() + ")");
+ if (refs == null) {
+ return false;
+ }
+ if (nb > refs.length) {
+ return false;
+ }
+ for (int i = 0; i < nb; i++) {
+ BazService fs = (BazService) getContext().getService(refs[i]);
+ getContext().ungetService(refs[i]);
+ if (!fs.foo()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+}