Split the iPOJO test suite in several bundles.


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@651646 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/tests/tests.core.lifecycle.callback/pom.xml b/ipojo/tests/tests.core.lifecycle.callback/pom.xml
new file mode 100644
index 0000000..ef77750
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/pom.xml
@@ -0,0 +1,102 @@
+<!--

+	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.

+-->

+<project>

+	<modelVersion>4.0.0</modelVersion>

+	<packaging>bundle</packaging>

+	<name>iPOJO Lifecycle callback Test Suite</name>

+	<artifactId>tests.core.lifecycle.callback</artifactId>

+	<groupId>ipojo.tests</groupId>

+	<version>0.7.6-SNAPSHOT</version>

+	<dependencies>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo</artifactId>

+			<version>0.7.6-SNAPSHOT</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.apache.felix.ipojo.metadata</artifactId>

+			<version>0.7.6-SNAPSHOT</version>

+		</dependency>

+		<dependency>

+			<groupId>org.apache.felix</groupId>

+			<artifactId>org.osgi.core</artifactId>

+			<version>1.0.0</version>

+		</dependency>

+		<dependency>

+			<groupId>junit</groupId>

+			<artifactId>junit</artifactId>

+			<version>3.8.1</version>

+		</dependency>

+		<dependency>

+			<groupId>ipojo.examples</groupId>

+			<artifactId>org.apache.felix.ipojo.junit4osgi</artifactId>

+			<version>0.7.6-SNAPSHOT</version>

+		</dependency>

+	</dependencies>

+	<build>

+		<plugins>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-bundle-plugin</artifactId>

+				<version>1.4.0</version>

+				<extensions>true</extensions>

+				<configuration>

+					<instructions>

+						<Export-Package>

+							org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service

+						</Export-Package>

+						<Bundle-SymbolicName>

+							${pom.artifactId}

+						</Bundle-SymbolicName>

+						<Private-Package>

+							org.apache.felix.ipojo.test*

+						</Private-Package>

+						<Test-Suite>

+							org.apache.felix.ipojo.test.scenarios.lifecycle.callback.LifeCycleCallbackTest

+						</Test-Suite>

+					</instructions>

+				</configuration>

+			</plugin>

+			<plugin>

+				<groupId>org.apache.felix</groupId>

+				<artifactId>maven-ipojo-plugin</artifactId>

+				<version>0.7.6-SNAPSHOT</version>

+				<executions>

+					<execution>

+						<goals>

+							<goal>ipojo-bundle</goal>

+						</goals>

+						<configuration>

+							<ignoreAnnotations>true</ignoreAnnotations>

+						</configuration>

+					</execution>

+				</executions>

+			</plugin>

+			<plugin>

+				<groupId>org.apache.maven.plugins</groupId>

+				<artifactId>maven-compiler-plugin</artifactId>

+				<configuration>

+					<source>1.4</source>

+					<target>1.4</target>

+				</configuration>

+			</plugin>

+		</plugins>

+	</build>

+</project>

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallbackCheckService.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallbackCheckService.java
new file mode 100644
index 0000000..edffc63
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CallbackCheckService.java
@@ -0,0 +1,68 @@
+/* 

+ * 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.scenarios.component;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.FooService;

+

+public class CallbackCheckService extends ParentClass implements CheckService {

+

+    int i = 0;

+

+    FooService fs;

+

+    public static CallbackCheckService singleton;

+

+    public static int count = 0;

+

+    private static CallbackCheckService singleton() {

+        if (singleton == null) {

+            count++;

+            singleton = new CallbackCheckService();

+        }

+        return singleton;

+    }

+

+    public static CallbackCheckService several() {

+        count++;

+        return new CallbackCheckService();

+    }

+

+    private void start() {

+        i++;

+    }

+

+    protected void stop() {

+        i++;

+    }

+

+    public boolean check() {

+        return fs.foo();

+    }

+

+    public Properties getProps() {

+        Properties p = new Properties();

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

+        p.put("count", new Integer(count));

+        return p;

+    }

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
new file mode 100644
index 0000000..d4ad3bf
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/FooProviderType1.java
@@ -0,0 +1,109 @@
+/* 

+ * 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.scenarios.component;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.FooService;

+import org.osgi.framework.BundleContext;

+

+public class FooProviderType1 implements FooService {

+	

+	private int m_bar;

+	private String m_foo;

+    

+    private BundleContext m_context;

+    

+    private static FooProviderType1 singleton;

+    private static int count = 0;

+    

+    private static FooProviderType1 singleton(BundleContext bc) {

+        if (singleton == null) {

+            count++;

+            singleton = new FooProviderType1(bc);

+        }

+        return singleton;

+    }

+    

+    public static FooProviderType1 several(BundleContext bc) {

+        count++;

+        return new FooProviderType1(bc);

+    }

+        

+    public FooProviderType1(BundleContext bc) {

+        if (bc ==null) {

+            throw new RuntimeException("Injected bundle context null");

+        }

+            m_context = bc;

+    }

+

+	public boolean foo() {

+		return true;

+	}

+

+	public Properties fooProps() {

+		Properties p = new Properties();

+		p.put("bar", new Integer(m_bar));

+        if(m_foo != null) {

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

+        }

+        p.put("context", m_context);

+        

+        p.put("count", new Integer(count));

+		return p;

+	}

+    

+	public void testException() throws Exception {

+        String a = "foobarbaz";

+	    throw new Exception("foo"+a);

+    }

+    

+    public void testTry() {

+            String a = "foo";

+            a.charAt(0);

+    }

+    

+    public void testTry2(String s) {

+            String a = "foo";

+            a.charAt(0);

+    }

+    

+	public boolean getBoolean() { return true; }

+

+	public double getDouble() { return 1.0; }

+

+	public int getInt() { return 1; }

+

+	public long getLong() { return 1; }

+

+	public Boolean getObject() { return new Boolean(true); }

+	

+	/**

+	 * Custom constructor.

+	 * @param bar

+	 * @param foo

+	 * @param bc

+	 */

+	public FooProviderType1(int bar, String foo, BundleContext bc) {

+	    m_bar = bar;

+	    m_foo = foo;

+	    m_context = bc;

+	}

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java
new file mode 100644
index 0000000..f7fb580
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/component/ParentClass.java
@@ -0,0 +1,51 @@
+/* 

+ * 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.scenarios.component;

+

+public class ParentClass {

+    

+    public void parentStart() {

+        

+    }

+    

+    public void parentStop() {

+        

+    }

+	

+	protected String[] strings;

+	

+	protected String string;

+	

+	protected int upStrings;

+	

+	protected int upString;

+	

+	public void updateStrings(String[] bb) {

+        strings = bb;

+        upStrings++;

+    }

+    

+    public void updateString(String bb) {

+        string = bb;

+        upString++;

+    }

+	

+	

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/CallbackTestCase.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/CallbackTestCase.java
new file mode 100644
index 0000000..6f229e7
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/CallbackTestCase.java
@@ -0,0 +1,115 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class CallbackTestCase extends OSGiTestCase {

+	

+	ComponentInstance instance; // Instance under test

+	ComponentInstance fooProvider;

+

+	public void setUp() {

+		Properties p2 = new Properties();

+		p2.put("name", "fooProvider");

+		fooProvider = Utils.getComponentInstance(context, "LFCB-FooProviderType-1", p2);

+		fooProvider.stop();

+		

+		Properties p1 = new Properties();

+		p1.put("name", "callback");

+		instance = Utils.getComponentInstance(context, "LFCB-CallbackCheckService", p1);

+		

+	}

+	

+	public void tearDown() {

+		instance.dispose();

+		fooProvider.dispose();

+		instance= null;

+		fooProvider = null;

+	}

+	

+	public void testCallback() {

+		// Check instance is invalid

+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());

+		assertNotNull("Check architecture availability", arch_ref);

+		InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);

+		assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);

+		

+		// Start fooprovider

+		fooProvider.start();

+		

+		// Check instance validity

+		id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);

+		

+		// Check service providing

+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+		assertNotNull("Check CheckService availability", cs_ref);

+		CheckService cs = (CheckService) context.getService(cs_ref);

+		assertTrue("check CheckService invocation", cs.check());

+		

+		// Check int property

+		Integer index = (Integer) (cs.getProps().get("int"));

+		assertEquals("Check int property - 1", index.intValue(), 1);

+		

+		assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);

+		

+		fooProvider.stop();

+		

+		id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);

+		

+		assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);

+		

+		fooProvider.start();

+		

+		// Check instance validity

+		id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);

+		

+		// Check service providing

+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+		assertNotNull("Check CheckService availability", cs_ref);

+		cs = (CheckService) context.getService(cs_ref);

+		assertTrue("check CheckService invocation", cs.check());

+		

+		// Check int property

+		index = (Integer) (cs.getProps().get("int"));

+		assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);

+		

+		assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);

+		

+		// Clean up

+		context.ungetService(arch_ref);

+		context.ungetService(cs_ref);

+		cs = null;

+		id_dep = null;

+	}

+		

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackSeveralFactoryTest.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackSeveralFactoryTest.java
new file mode 100644
index 0000000..0cfd554
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackSeveralFactoryTest.java
@@ -0,0 +1,120 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class ImmediateCallbackSeveralFactoryTest extends OSGiTestCase {

+    

+    ComponentInstance instance; // Instance under test

+    ComponentInstance fooProvider;

+

+    public void setUp() {

+        Properties p2 = new Properties();

+        p2.put("name", "fooProvider");

+        fooProvider = Utils.getComponentInstance(context, "LFCB-FooProviderType-1", p2);

+        fooProvider.stop();

+        

+        Properties p1 = new Properties();

+        p1.put("name", "callback");

+        instance = Utils.getComponentInstance(context, "LFCB-ImmediateCallbackCheckServiceSeveral", p1);

+        

+    }

+    

+    public void tearDown() {

+        instance.dispose();

+        fooProvider.dispose();

+        instance= null;

+        fooProvider = null;

+        CallbackCheckService.count = 0;

+    }

+    

+    public void testCallback() {

+        // Check instance is invalid

+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());

+        assertNotNull("Check architecture availability", arch_ref);

+        InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);

+        assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);

+        

+        // Start fooprovider

+        fooProvider.start();

+        

+        // Check instance validity

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);

+        

+        // Check service providing

+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        CheckService cs = (CheckService) context.getService(cs_ref);

+        assertTrue("check CheckService invocation", cs.check());

+        

+        assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);

+        // Check int property

+        Integer index = (Integer) (cs.getProps().get("int"));

+        Integer count = (Integer) (cs.getProps().get("count"));

+        assertEquals("Check int property - 1 (" + index.intValue() +")", index.intValue(), 1);

+        assertEquals("Check count property - 1 (" + count.intValue() +")", count.intValue(), 1);

+        

+        fooProvider.stop();

+        

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);

+        

+        assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);

+        

+        fooProvider.start();

+        

+        // Check instance validity

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);

+        

+        // Check service providing

+        cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        cs = (CheckService) context.getService(cs_ref);

+        assertTrue("check CheckService invocation", cs.check());

+        

+        // Check int property

+        index = (Integer) (cs.getProps().get("int"));

+        count = (Integer) (cs.getProps().get("count"));

+        assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);

+        assertEquals("Check count property - 2 ("+count.intValue()+")", count.intValue(), 1);

+        

+        assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);

+        

+        // Clean up

+        context.ungetService(arch_ref);

+        context.ungetService(cs_ref);

+        cs = null;

+        id_dep = null;

+    }

+        

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackSingletonFactoryTest.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackSingletonFactoryTest.java
new file mode 100644
index 0000000..310d7ce
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackSingletonFactoryTest.java
@@ -0,0 +1,117 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class ImmediateCallbackSingletonFactoryTest extends OSGiTestCase {

+    

+    ComponentInstance instance; // Instance under test

+    ComponentInstance fooProvider;

+

+    public void setUp() {

+        Properties p2 = new Properties();

+        p2.put("name", "fooProvider");

+        fooProvider = Utils.getComponentInstance(context, "LFCB-FooProviderType-1", p2);

+        fooProvider.stop();

+        

+        Properties p1 = new Properties();

+        p1.put("name", "callback");

+        instance = Utils.getComponentInstance(context, "LFCB-ImmediateCallbackCheckServiceSingleton", p1);

+        

+    }

+    

+    public void tearDown() {

+        instance.dispose();

+        fooProvider.dispose();

+        instance= null;

+        fooProvider = null;

+        CallbackCheckService.count = 0;

+        CallbackCheckService.singleton = null;

+    }

+    

+    public void testCallback() {

+        // Check instance is invalid

+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());

+        assertNotNull("Check architecture availability", arch_ref);

+        InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);

+        assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);

+        

+        // Start fooprovider

+        fooProvider.start();

+        

+        // Check instance validity

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);

+        

+        // Check service providing

+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        CheckService cs = (CheckService) context.getService(cs_ref);

+        assertTrue("check CheckService invocation", cs.check());

+        

+        assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);

+        // Check int property

+        Integer index = (Integer) (cs.getProps().get("int"));

+        assertEquals("Check int property - 1 (" + index.intValue() +")", index.intValue(), 1);

+        

+        fooProvider.stop();

+        

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);

+        

+        assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);

+        

+        fooProvider.start();

+        

+        // Check instance validity

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);

+        

+        // Check service providing

+        cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        cs = (CheckService) context.getService(cs_ref);

+        assertTrue("check CheckService invocation", cs.check());

+        

+        // Check int property

+        index = (Integer) (cs.getProps().get("int"));

+        assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);

+        

+        assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);

+        

+        // Clean up

+        context.ungetService(arch_ref);

+        context.ungetService(cs_ref);

+        cs = null;

+        id_dep = null;

+    }

+        

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackTest.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackTest.java
new file mode 100644
index 0000000..a8e1795
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateCallbackTest.java
@@ -0,0 +1,114 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class ImmediateCallbackTest extends OSGiTestCase {

+    

+    ComponentInstance instance; // Instance under test

+    ComponentInstance fooProvider;

+

+    public void setUp() {

+        Properties p2 = new Properties();

+        p2.put("name", "fooProvider");

+        fooProvider = Utils.getComponentInstance(context, "LFCB-FooProviderType-1", p2);

+        fooProvider.stop();

+        

+        Properties p1 = new Properties();

+        p1.put("name", "callback");

+        instance = Utils.getComponentInstance(context, "LFCB-ImmediateCallbackCheckService", p1);

+        

+    }

+    

+    public void tearDown() {

+        instance.dispose();

+        fooProvider.dispose();

+        instance= null;

+        fooProvider = null;

+    }

+    

+    public void testCallback() {

+        // Check instance is invalid

+        ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());

+        assertNotNull("Check architecture availability", arch_ref);

+        InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);

+        assertEquals("Check pojo count - 1", id_dep.getCreatedObjects().length, 0);

+        

+        // Start fooprovider

+        fooProvider.start();

+        

+        // Check instance validity

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);

+        

+        // Check service providing

+        ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        CheckService cs = (CheckService) context.getService(cs_ref);

+        assertTrue("check CheckService invocation", cs.check());

+        

+        assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);

+        // Check int property

+        Integer index = (Integer) (cs.getProps().get("int"));

+        assertEquals("Check int property - 1 (" + index.intValue() +")", index.intValue(), 1);

+        

+        fooProvider.stop();

+        

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);

+        

+        assertEquals("Check pojo count - 3", id_dep.getCreatedObjects().length, 1);

+        

+        fooProvider.start();

+        

+        // Check instance validity

+        id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+        assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);

+        

+        // Check service providing

+        cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+        assertNotNull("Check CheckService availability", cs_ref);

+        cs = (CheckService) context.getService(cs_ref);

+        assertTrue("check CheckService invocation", cs.check());

+        

+        // Check int property

+        index = (Integer) (cs.getProps().get("int"));

+        assertEquals("Check int property - 2 ("+index.intValue()+")", index.intValue(), 3);

+        

+        assertEquals("Check pojo count - 4 ", id_dep.getCreatedObjects().length, 1);

+        

+        // Clean up

+        context.ungetService(arch_ref);

+        context.ungetService(cs_ref);

+        cs = null;

+        id_dep = null;

+    }

+        

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateLifeCycleControllerTest.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateLifeCycleControllerTest.java
new file mode 100644
index 0000000..fe53fb4
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ImmediateLifeCycleControllerTest.java
@@ -0,0 +1,115 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.Factory;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class ImmediateLifeCycleControllerTest extends OSGiTestCase {

+    

+    private ComponentInstance under;

+    private Factory factory;

+    

+    public void setUp() {

+        factory = Utils.getFactoryByName(context, "LFC-Test-Immediate");

+    }

+    

+    public void testOne() {

+        Properties props = new Properties();

+        props.put("conf", "foo");

+        props.put("name", "under");

+        under = Utils.getComponentInstance(context, "LFC-Test-Immediate", props);

+        

+        // The conf is correct, the PS must be provided

+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");

+        assertNotNull("Check service availability -1", ref);

+        CheckService cs = (CheckService) context.getService(ref);

+        assertTrue("Check state 1", cs.check());

+        context.ungetService(ref);

+        cs = null;

+        

+        // Reconfigure the instance with a bad configuration

+        props.put("conf", "bar"); // Bar is a bad conf

+        try {

+            factory.reconfigure(props);

+        } catch(Exception e) {

+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);

+        }

+        

+        // The instance should now be invalid 

+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");

+        assertNull("Check service availability -2", ref);

+        

+        // Reconfigure the instance with a valid configuration

+        props.put("conf", "foo"); // Bar is a bad conf

+        try {

+            factory.reconfigure(props);

+        } catch(Exception e) {

+            fail("The reconfiguration is not unacceptable and seems unacceptable (2) : " + props);

+        }

+        

+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");

+        assertNotNull("Check service availability -3", ref);

+        cs = (CheckService) context.getService(ref);

+        assertTrue("Check state 2", cs.check());

+        context.ungetService(ref);

+        cs = null;

+        

+        under.dispose();

+    }

+    

+    public void testTwo() {        

+        Properties props = new Properties();

+        props.put("conf", "bar");

+        props.put("name", "under");

+        under = Utils.getComponentInstance(context, "LFC-Test-Immediate", props);    

+        

+        assertEquals("check under state", under.getState(), ComponentInstance.INVALID);

+        

+        // The conf is incorrect, the PS must not be provided

+        ServiceReference ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");

+        assertNull("Check service availability -1", ref);

+        

+        // Reconfigure the instance with a correct configuration

+        props.put("conf", "foo");

+        try {

+            factory.reconfigure(props);

+        } catch(Exception e) {

+            fail("The reconfiguration is not unacceptable and seems unacceptable : " + props);

+        }

+        

+        ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), "under");

+        assertNotNull("Check service availability -2", ref);

+        CheckService cs = (CheckService) context.getService(ref);

+        assertTrue("Check state ", cs.check());

+        context.ungetService(ref);

+        cs = null;

+        

+        under.dispose();

+    }

+    

+    

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/LifeCycleCallbackTest.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/LifeCycleCallbackTest.java
new file mode 100644
index 0000000..ed5a6bc
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/LifeCycleCallbackTest.java
@@ -0,0 +1,41 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import junit.framework.Test;

+import junit.framework.TestSuite;

+

+import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite;

+import org.osgi.framework.BundleContext;

+

+public class LifeCycleCallbackTest extends TestSuite {

+	

+

+	public static Test suite(BundleContext bc) {

+		OSGiTestSuite ots = new OSGiTestSuite("Lifecycle callbacks Test Suite", bc);

+		ots.addTestSuite(CallbackTestCase.class);

+		ots.addTestSuite(ParentCallbackTestCase.class);

+        ots.addTestSuite(ImmediateCallbackTest.class);

+        ots.addTestSuite(ImmediateCallbackSingletonFactoryTest.class);

+        ots.addTestSuite(ImmediateCallbackSeveralFactoryTest.class);

+		return ots;

+	}

+

+}

+

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ParentCallbackTestCase.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ParentCallbackTestCase.java
new file mode 100644
index 0000000..fef421b
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/ParentCallbackTestCase.java
@@ -0,0 +1,102 @@
+/* 

+ * 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.scenarios.lifecycle.callback;

+

+import java.util.Properties;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.architecture.Architecture;

+import org.apache.felix.ipojo.architecture.InstanceDescription;

+import org.apache.felix.ipojo.junit4osgi.OSGiTestCase;

+import org.apache.felix.ipojo.test.scenarios.lifecycle.callback.service.CheckService;

+import org.apache.felix.ipojo.test.scenarios.util.Utils;

+import org.osgi.framework.ServiceReference;

+

+public class ParentCallbackTestCase extends OSGiTestCase {

+	

+	ComponentInstance instance; // Instance under test

+	ComponentInstance fooProvider;

+

+	public void setUp() {

+		Properties p2 = new Properties();

+		p2.put("name", "fooProvider");

+		fooProvider = Utils.getComponentInstance(context, "LFCB-FooProviderType-1", p2);

+		fooProvider.stop();

+		

+		Properties p1 = new Properties();

+		p1.put("name", "callback");

+		instance = Utils.getComponentInstance(context, "LFCB-ParentCallbackCheckService", p1);

+		

+	}

+	

+	public void tearDown() {

+		instance.dispose();

+		fooProvider.dispose();

+		instance= null;

+		fooProvider = null;

+	}

+	

+	public void testCallback() {

+		// Check instance is invalid

+		ServiceReference arch_ref = Utils.getServiceReferenceByName(context, Architecture.class.getName(), instance.getInstanceName());

+		assertNotNull("Check architecture availability", arch_ref);

+		InstanceDescription id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance invalidity - 1", id_dep.getState() == ComponentInstance.INVALID);

+		

+		// Start fooprovider

+		fooProvider.start();

+		

+		// Check instance validity

+		id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 1", id_dep.getState() == ComponentInstance.VALID);

+		

+		// Check service providing

+		ServiceReference cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+		assertNotNull("Check CheckService availability", cs_ref);

+		CheckService cs = (CheckService) context.getService(cs_ref);

+		

+		// Check int property		

+		assertEquals("Check pojo count - 2", id_dep.getCreatedObjects().length, 1);

+		

+		fooProvider.stop();

+		

+		id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance invalidity - 2", id_dep.getState() == ComponentInstance.INVALID);

+		

+		fooProvider.start();

+		

+		// Check instance validity

+		id_dep = ((Architecture) context.getService(arch_ref)).getInstanceDescription();

+		assertTrue("Check instance validity - 2", id_dep.getState() == ComponentInstance.VALID);

+		

+		// Check service providing

+		cs_ref = Utils.getServiceReferenceByName(context, CheckService.class.getName(), instance.getInstanceName());

+		assertNotNull("Check CheckService availability", cs_ref);

+		cs = (CheckService) context.getService(cs_ref);

+		assertTrue("check CheckService invocation", cs.check());

+		

+		// Clean up

+		context.ungetService(arch_ref);

+		context.ungetService(cs_ref);

+		cs = null;

+		id_dep = null;

+	}

+		

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/service/CheckService.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/service/CheckService.java
new file mode 100644
index 0000000..45684ab
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/service/CheckService.java
@@ -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.test.scenarios.lifecycle.callback.service;

+

+import java.util.Properties;

+

+public interface CheckService {

+    

+    public static final String foo = "foo";

+	

+	public boolean check();

+	

+	public Properties getProps();

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/service/FooService.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/service/FooService.java
new file mode 100644
index 0000000..b1fdd34
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/lifecycle/callback/service/FooService.java
@@ -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.test.scenarios.lifecycle.callback.service;

+

+import java.util.Properties;

+

+public interface FooService {

+

+	boolean foo();

+	

+	Properties fooProps();

+	

+	Boolean getObject();

+	

+	boolean getBoolean();

+	

+	int getInt();

+	

+	long getLong();

+	

+	double getDouble();

+	

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
new file mode 100644
index 0000000..7dbb8d0
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/java/org/apache/felix/ipojo/test/scenarios/util/Utils.java
@@ -0,0 +1,325 @@
+/* 

+ * 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.scenarios.util;

+

+import java.util.Dictionary;

+import java.util.Properties;

+

+import junit.framework.Assert;

+

+import org.apache.felix.ipojo.ComponentInstance;

+import org.apache.felix.ipojo.Factory;

+import org.apache.felix.ipojo.Handler;

+import org.apache.felix.ipojo.HandlerFactory;

+import org.apache.felix.ipojo.ServiceContext;

+import org.osgi.framework.BundleContext;

+import org.osgi.framework.InvalidSyntaxException;

+import org.osgi.framework.ServiceReference;

+import org.osgi.service.cm.ManagedServiceFactory;

+

+public class Utils {

+

+    public static Factory getFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static HandlerFactory getHandlerFactoryByName(BundleContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(" + Handler.HANDLER_NAME_PROPERTY + "=" + factoryName + ")");

+            if (refs == null) {

+                System.err.println("Cannot get the factory " + factoryName);

+                return null;

+            }

+            return (HandlerFactory) bc.getService(refs[0]);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(BundleContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        // if(fact.isAcceptable(configuration)) {

+        try {

+            return fact.createComponentInstance(configuration);

+        } catch (Exception e) {

+            e.printStackTrace();

+            Assert.fail("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+        // }

+        // else {

+        // System.err.println("Configuration not accepted by : " + factoryName);

+        // return null;

+        // }

+    }

+

+    public static ComponentInstance getComponentInstanceByName(BundleContext bc, String factoryName, String name) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) {

+            System.err.println("Factory " + factoryName + " not found");

+            return null;

+        }

+

+        try {

+            Properties props = new Properties();

+            props.put("name", name);

+            return fact.createComponentInstance(props);

+        } catch (Exception e) {

+            System.err.println("Cannot create the instance from " + factoryName + " : " + e.getMessage());

+            e.printStackTrace();

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(BundleContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+    

+    public static ServiceReference getServiceReferenceByPID(BundleContext bc, String itf, String pid) {

+        ServiceReference[] refs = null;

+        String filter = "(" + "service.pid" + "=" + pid + ")";

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else if (refs.length == 1) {

+            return refs[0];

+        } else {

+            Assert.fail("A service lookup by PID returned several providers (" + refs.length + ")" + " for " + itf + " with " + pid);

+            return null;

+        }

+    }

+

+    public static Object getServiceObject(BundleContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(BundleContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

+            for (int i = 0; i < refs.length; i++) {

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+

+//    public static ServiceContext getServiceContext(ComponentInstance ci) {

+//        if (ci instanceof CompositeManager) {

+//            return ((CompositeManager) ci).getServiceContext();

+//        } else {

+//            throw new RuntimeException("Cannot get the service context form an non composite instance");

+//        }

+//    }

+

+    public static Factory getFactoryByName(ServiceContext bc, String factoryName) {

+        ServiceReference[] refs;

+        try {

+            refs = bc.getServiceReferences(Factory.class.getName(), "(factory.name=" + factoryName + ")");

+            if (refs == null) { return null; }

+            return ((Factory) bc.getService(refs[0]));

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Cannot get the factory " + factoryName + " : " + e.getMessage());

+            return null;

+        }

+    }

+

+    public static ComponentInstance getComponentInstance(ServiceContext bc, String factoryName, Dictionary configuration) {

+        Factory fact = getFactoryByName(bc, factoryName);

+

+        if (fact == null) { return null; }

+

+        if (fact.isAcceptable(configuration)) {

+            try {

+                return fact.createComponentInstance(configuration);

+            } catch (Exception e) {

+                System.err.println(e.getMessage());

+                e.printStackTrace();

+                return null;

+            }

+        } else {

+            System.err.println("Configuration not accepted by : " + factoryName);

+            return null;

+        }

+    }

+

+    public static ServiceReference[] getServiceReferences(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return new ServiceReference[0];

+        } else {

+            return refs;

+        }

+    }

+

+    public static ServiceReference getServiceReference(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = null;

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static ServiceReference getServiceReferenceByName(ServiceContext bc, String itf, String name) {

+        ServiceReference[] refs = null;

+        String filter = null;

+        if (itf.equals(Factory.class.getName()) || itf.equals(ManagedServiceFactory.class.getName())) {

+            filter = "(" + "factory.name" + "=" + name + ")";

+        } else {

+            filter = "(" + "instance.name" + "=" + name + ")";

+        }

+        try {

+            refs = bc.getServiceReferences(itf, filter);

+        } catch (InvalidSyntaxException e) {

+            System.err.println("Invalid Filter : " + filter);

+        }

+        if (refs == null) {

+            return null;

+        } else {

+            return refs[0];

+        }

+    }

+

+    public static Object getServiceObject(ServiceContext bc, String itf, String filter) {

+        ServiceReference ref = getServiceReference(bc, itf, filter);

+        if (ref != null) {

+            return bc.getService(ref);

+        } else {

+            return null;

+        }

+    }

+

+    public static Object[] getServiceObjects(ServiceContext bc, String itf, String filter) {

+        ServiceReference[] refs = getServiceReferences(bc, itf, filter);

+        if (refs != null) {

+            Object[] list = new Object[refs.length];

+            for (int i = 0; i < refs.length; i++) {

+                list[i] = bc.getService(refs[i]);

+            }

+            return list;

+        } else {

+            return new Object[0];

+        }

+    }

+    

+    public static boolean contains(String string, String[] array) {

+        for (int i = 0; array != null && i < array.length; i++) {

+            if (array[i] != null  && array[i].equals(string)) {

+                return true;

+            }

+        }

+        return false;

+    }

+    

+    public static boolean contains(int value, int[] array) {

+        for (int i = 0; array != null && i < array.length; i++) {

+            if (array[i] == value) {

+                return true;

+            }

+        }

+        return false;

+    }

+

+}

diff --git a/ipojo/tests/tests.core.lifecycle.callback/src/main/resources/metadata.xml b/ipojo/tests/tests.core.lifecycle.callback/src/main/resources/metadata.xml
new file mode 100644
index 0000000..c60c239
--- /dev/null
+++ b/ipojo/tests/tests.core.lifecycle.callback/src/main/resources/metadata.xml
@@ -0,0 +1,52 @@
+<ipojo>

+	<component

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

+		factory="LFCB-FooProviderType-1" architecture="true">

+		<provides />

+	</component>

+	

+	<!-- Lifecycle Callback -->

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"

+		factory="LFCB-CallbackCheckService" architecture="true">

+		<requires field="fs" />

+		<provides />

+		<callback transition="validate" method="start" />

+		<callback transition="invalidate" method="stop" />

+	</component>

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"

+		factory="LFCB-ParentCallbackCheckService" architecture="true">

+		<requires field="fs" />

+		<provides />

+		<callback transition="validate" method="parentStart" />

+		<callback transition="invalidate" method="parentStop" />

+	</component>

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"

+		immediate="true" factory="LFCB-ImmediateCallbackCheckService"

+		architecture="true">

+		<requires field="fs" />

+		<provides />

+		<callback transition="validate" method="start" />

+		<callback transition="invalidate" method="stop" />

+	</component>

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"

+		immediate="true" factory="LFCB-ImmediateCallbackCheckServiceSingleton"

+		factory-method="singleton" architecture="true">

+		<requires field="fs" />

+		<provides />

+		<callback transition="validate" method="start" />

+		<callback transition="invalidate" method="stop" />

+	</component>

+	<component

+		className="org.apache.felix.ipojo.test.scenarios.component.CallbackCheckService"

+		immediate="true" factory="LFCB-ImmediateCallbackCheckServiceSeveral"

+		factory-method="several" architecture="true">

+		<requires field="fs" />

+		<provides />

+		<callback transition="validate" method="start" />

+		<callback transition="invalidate" method="stop" />

+	</component>

+</ipojo>