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 [5/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-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestInstanceScope.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,86 @@
+package org.apache.felix.ipojo.runtime.core.instance;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.composite.CompositeFactory;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.Service;
+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 TestInstanceScope extends Common {
+
+ CompositeFactory factory;
+ ComponentInstance instance;
+
+ @Before
+ public void setUp() {
+ factory = (CompositeFactory) ipojoHelper.getFactory("SCOPE-scope");
+ assertNotNull("Factory", factory);
+ try {
+ instance = factory.createComponentInstance(null);
+ } catch (Exception e) {
+ fail("Fail instantiation : " + e.getMessage());
+ }
+
+
+ }
+
+ @After
+ public void tearDown() {
+ instance.dispose();
+ instance = null;
+ }
+
+ @Test
+ public void testScope() {
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), instance.getInstanceName());
+ assertNotNull("Check architecture availability", ref);
+ Architecture arch = (Architecture) getContext().getService(ref);
+ assertTrue("Validity", arch.getInstanceDescription().getState() == ComponentInstance.VALID);
+
+ // Get internal service
+ ServiceContext sc = getServiceContext(instance);
+ ServiceReference ref2 = ipojoHelper.getServiceReference(sc, CheckService.class.getName(), null);
+ assertNotNull("Check CheckService availability", ref2);
+ CheckService svc = (CheckService) sc.getService(ref2);
+ Properties props = svc.getProps();
+ assertEquals("Check props - 1", 1, ((Integer) props.get("1")).intValue());
+ assertEquals("Check props - 2", 2, ((Integer) props.get("2")).intValue());
+ assertEquals("Check props - 3", 3, ((Integer) props.get("3")).intValue());
+
+ }
+
+ @Test
+ public void testGlobalUnavailability() {
+ ServiceReference ref2 = osgiHelper.getServiceReference(Service.class.getName(), null);
+ assertNull("Check Service unavailability", ref2);
+ }
+
+ @Test
+ public void testScopeUnvailability() {
+ CompositeFactory factory2 = (CompositeFactory) ipojoHelper.getFactory("SCOPE-badscope");
+ assertNotNull("Factory", factory2);
+ ComponentInstance instance2 = null;
+ try {
+ instance2 = factory2.createComponentInstance(null);
+ } catch (Exception e) {
+ fail("Fail instantiation : " + e.getMessage());
+ }
+ //System.out.println(instance2.getInstanceDescription().getDescription());
+
+ assertEquals("Check invalidity", ComponentInstance.INVALID, instance2.getState());
+ instance2.dispose();
+
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instance/TestSimpleInstance.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,279 @@
+/*
+ * 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.instance;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.composite.CompositeInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+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 junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+public class TestSimpleInstance extends Common {
+
+ private ComponentFactory fooFactory1, fooFactory2;
+ private ComponentFactory compoFactory;
+ private ComponentInstance empty;
+
+ @Before
+ public void setUp() {
+ fooFactory1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooProviderType-1");
+ fooFactory2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooProviderType-Dyn2");
+ compoFactory = (ComponentFactory) ipojoHelper.getFactory("composite.inst.1");
+ Factory fact = ipojoHelper.getFactory("composite.empty");
+ Properties props = new Properties();
+ props.put("instance.name", "empty-X");
+ try {
+ empty = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot create the empty composite : " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ empty.dispose();
+ empty = null;
+ }
+
+ @Test
+ public void testCreation() {
+ Properties props = new Properties();
+ props.put("instance.name", "under-A");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Cannot instantiate under from " + compoFactory.getName() + " -> " + e.getMessage());
+ }
+
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailability() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+
+ assertNotNull("Check service availability", sc.getServiceReference(FooService.class.getName()));
+ assertEquals("Check service provider", ipojoHelper.getServiceReferences(sc, FooService.class.getName(), null).length,
+ 2);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testCreationLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailabilityLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under-X");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+
+ assertNotNull("Check service availability", sc2.getServiceReference(FooService.class.getName()));
+ assertEquals("Check service providers", ipojoHelper.getServiceReferences(sc2, FooService.class.getName(),
+ null).length, 2);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testFactoryManagement() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ fooFactory1.stop();
+ assertTrue("Check instance invalidity - 2", under.getState() == ComponentInstance.INVALID);
+
+ fooFactory1.start();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+
+ fooFactory2.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+
+ fooFactory2.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fooFactory1.start();
+ fooFactory2.start();
+ }
+
+ @Test
+ public void testFactoryManagementLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ fooFactory1.stop();
+ assertTrue("Check instance invalidity - 2", under.getState() == ComponentInstance.INVALID);
+
+ fooFactory1.start();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+
+ fooFactory2.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+
+ fooFactory2.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fooFactory1.start();
+ fooFactory2.start();
+ }
+
+ public void atestArchitecture() { // TODO fix and reactivate the method.
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = compoFactory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ ServiceReference ref = osgiHelper.getServiceReference(Architecture.class.getName(),
+ "(architecture.instance=under)");
+ assertNotNull("Check architecture availability", ref);
+ Architecture arch = (Architecture) getContext().getService(ref);
+ CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
+
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ InstanceDescription[] contained = id.getContainedInstances();
+ assertEquals("Check contained instances count (" + contained.length + ")", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ ref = osgiHelper.getServiceReference(Architecture.class.getName(), "(architecture.instance=under)");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 0);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfigurableInstantiation.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,112 @@
+/*
+ * 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.instantiator;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.runtime.core.Common;
+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 TestConfigurableInstantiation extends Common {
+
+ private ComponentFactory acceptF;
+ private ComponentFactory refuse1F;
+ private ComponentFactory refuse2F;
+
+ @Before
+ public void setUp() {
+ acceptF = (ComponentFactory) ipojoHelper.getFactory("composite.bar.5-accept");
+ refuse1F = (ComponentFactory) ipojoHelper.getFactory("composite.bar.5-refuse1");
+ refuse2F = (ComponentFactory) ipojoHelper.getFactory("composite.bar.5-refuse2");
+
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void testAccept() {
+ Properties props = new Properties();
+ props.put("instance.name", "under-A");
+ ComponentInstance under = null;
+ try {
+ under = acceptF.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ ServiceReference ref = sc.getServiceReference(FooService.class.getName());
+ assertNotNull("Check refs not null", ref);
+ FooService foo = (FooService) sc.getService(ref);
+ Properties p = foo.fooProps();
+ boolean b = ((Boolean) p.get("boolProp")).booleanValue();
+ String s = (String) p.get("strProp");
+ int i = ((Integer) p.get("intProp")).intValue();
+ assertTrue("Test boolean", b);
+ assertEquals("Test string", s, "foo");
+ //TODO See why it fails...
+ //assertEquals("Test int", i, 5); // The code fix to 5.
+ under.dispose();
+ }
+
+ @Test
+ public void testRefuse1() {
+ Properties props = new Properties();
+ props.put("instance.name", "under-ref1");
+ ComponentInstance under = null;
+ try {
+ under = refuse1F.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+
+ assertTrue("Check that under is not valid", under.getState() == ComponentInstance.INVALID);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testRefuse2() {
+ Properties props = new Properties();
+ props.put("instance.name", "under-ref2");
+ ComponentInstance under = null;
+ try {
+ under = refuse2F.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+
+ assertTrue("Check that under is not valid", under.getState() == ComponentInstance.INVALID);
+
+ under.dispose();
+ }
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestConfiguration.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,97 @@
+/*
+ * 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.instantiator;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.runtime.core.Common;
+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.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestConfiguration extends Common {
+
+ private ComponentFactory compositeFactory;
+
+ @Before
+ public void setUp() {
+ compositeFactory = (ComponentFactory) ipojoHelper.getFactory("CONF-MySuperComposite");
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+
+ @Test
+ public void testDefaultInstantiation() throws InvalidSyntaxException {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = compositeFactory.createComponentInstance(props);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ ServiceReference[] refs = sc.getServiceReferences(FooService.class.getName(), null);
+ assertEquals(2, refs.length);
+ for (int i = 0; i < refs.length; i++) {
+ assertEquals(3, ((Integer) refs[i].getProperty("int")).intValue());
+ assertEquals("foo", (String) refs[i].getProperty("string"));
+ }
+ under.dispose();
+ }
+
+ @Test
+ public void testConfiguredInstantiation() throws InvalidSyntaxException {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ props.put("string", "bar");
+ props.put("int", "25");
+ ComponentInstance under = null;
+ try {
+ under = compositeFactory.createComponentInstance(props);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ ServiceReference[] refs = sc.getServiceReferences(FooService.class.getName(), null);
+ assertEquals(2, refs.length);
+ for (int i = 0; i < refs.length; i++) {
+ assertEquals(25, ((Integer) refs[i].getProperty("int")).intValue());
+ assertEquals("bar", (String) refs[i].getProperty("string"));
+ }
+ under.dispose();
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestMultipleInstantiation.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,287 @@
+/*
+ * 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.instantiator;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.composite.CompositeInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+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 TestMultipleInstantiation extends Common {
+
+ private ComponentFactory bar2Factory;
+ private ComponentInstance empty;
+
+ @Before
+ public void setUp() {
+ bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.2");
+ Factory fact = ipojoHelper.getFactory("composite.empty");
+ Properties props = new Properties();
+ props.put("instance.name", "empty");
+ try {
+ empty = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot create the empty composite : " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ empty.dispose();
+ empty = null;
+ }
+
+ @Test
+ public void testCreation() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailability() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+ int count = ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length;
+ assertEquals("Check service provider number : " + count, count, 3);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testCreationLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailabilityLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+ assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 3);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testFactoryManagement() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ ServiceContext sc = getServiceContext(under);
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 2);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 0);
+
+ fact1.start();
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length, 1);
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test
+ public void testFactoryManagementLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 2);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 0);
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2, BarService.class.getName(), null).length, 1);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test
+ public void testArchitecture() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ Architecture arch = (Architecture) getContext().getService(ref);
+ CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
+
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ InstanceDescription[] contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 3);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 2);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 0);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.2");
+
+ getContext().ungetService(ref);
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalInstantiation.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,273 @@
+/*
+ * 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.instantiator;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.composite.CompositeInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+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 TestOptionalInstantiation extends Common {
+
+ private ComponentFactory bar1Factory;
+ private ComponentInstance empty;
+
+ @Before
+ public void setUp() {
+ bar1Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.3");
+ Factory fact = ipojoHelper.getFactory("composite.empty");
+ Properties props = new Properties();
+ props.put("instance.name","empty");
+ try {
+ empty = fact.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot create the empty composite : " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ empty.dispose();
+ empty = null;
+ }
+
+ @Test
+ public void testCreation() {
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test public void testServiceAvailability() {
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+
+ under.dispose();
+ }
+
+ @Test public void testCreationLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props, sc);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test public void testServiceAvailabilityLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props, sc);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+ assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+
+ under.dispose();
+ }
+
+ @Test public void testFactoryManagement() {
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+
+ fact3.stop();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ assertNull("Check that no Bar Service is available", sc.getServiceReference(BarService.class.getName()));
+
+ fact1.start();
+ assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test public void testFactoryManagementLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props, sc);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+
+ fact3.stop();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+
+ fact1.start();
+ assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test public void testArchitecture() {
+ Properties props = new Properties();
+ props.put("instance.name","under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch(Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ Architecture arch = (Architecture) getContext().getService(ref);
+ assertNotNull("Check architecture", arch);
+ CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ InstanceDescription[] contained = id.getContainedInstances();
+ assertNotNull("Check contained not null", contained);
+ assertEquals("Check contained instances count ("+contained.length+") - 1", contained.length, 1);
+ assertEquals("Check instance name" , id.getName(), "under");
+ assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name" , id.getName(), "under");
+ assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name" , id.getName(), "under");
+ assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 0);
+ assertEquals("Check instance name" , id.getName(), "under");
+ assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName( Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name" , id.getName(), "under");
+ assertEquals("Check component type name" , id.getComponentDescription().getName(), "composite.bar.3");
+
+ getContext().ungetService(ref);
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestOptionalMultipleInstantiation.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,214 @@
+/*
+ * 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.instantiator;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+public class TestOptionalMultipleInstantiation extends Common {
+
+ private ComponentFactory bar2Factory;
+ private ComponentInstance empty;
+
+ @Before
+ public void setUp() {
+ bar2Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.4");
+ assertNotNull("Check bar2factory availability", bar2Factory);
+
+ Factory fact = ipojoHelper.getFactory("composite.empty");
+ Properties props = new Properties();
+ props.put("instance.name", "empty");
+ try {
+ empty = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot create the empty composite : " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ empty.dispose();
+ empty = null;
+ }
+
+ @Test
+ public void testCreation() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailability() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+ int count = ipojoHelper.getServiceReferences(sc, BarService.class.getName(), null).length;
+ assertEquals("Check service provider number : " + count, count, 3);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testCreationLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailabilityLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+ assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,
+ BarService.class.getName(), null).length, 3);
+
+ under.dispose();
+ }
+
+ @Test
+ public void testFactoryManagement() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ ServiceContext sc = getServiceContext(under);
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,
+ BarService.class.getName(), null).length, 2);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,
+ BarService.class.getName(), null).length, 1);
+
+ fact3.stop();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,
+ BarService.class.getName(), null).length, 0);
+
+ fact1.start();
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc,
+ BarService.class.getName(), null).length, 1);
+ assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test
+ public void testFactoryManagementLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar2Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,
+ BarService.class.getName(), null).length, 2);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,
+ BarService.class.getName(), null).length, 1);
+
+ fact3.stop();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,
+ BarService.class.getName(), null).length, 0);
+
+ fact1.start();
+ assertTrue("Check instance validity - 5", under.getState() == ComponentInstance.VALID);
+ assertEquals("Check service provider number", ipojoHelper.getServiceReferences(sc2,
+ BarService.class.getName(), null).length, 1);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-instance-test/src/test/java/org/apache/felix/ipojo/runtime/core/instantiator/TestSimpleInstantiation.java Tue Feb 26 13:02:34 2013
@@ -0,0 +1,274 @@
+/*
+ * 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.instantiator;
+
+import org.apache.felix.ipojo.ComponentFactory;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
+import org.apache.felix.ipojo.ServiceContext;
+import org.apache.felix.ipojo.architecture.Architecture;
+import org.apache.felix.ipojo.architecture.InstanceDescription;
+import org.apache.felix.ipojo.composite.CompositeInstanceDescription;
+import org.apache.felix.ipojo.runtime.core.Common;
+import org.apache.felix.ipojo.runtime.core.services.BarService;
+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 TestSimpleInstantiation extends Common {
+
+ private ComponentFactory bar1Factory;
+ private ComponentInstance empty;
+
+ @Before
+ public void setUp() {
+ bar1Factory = (ComponentFactory) ipojoHelper.getFactory("composite.bar.1");
+ Factory fact = ipojoHelper.getFactory("composite.empty");
+ Properties props = new Properties();
+ props.put("instance.name", "empty-X");
+ try {
+ empty = fact.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot create the empty composite : " + e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ empty.dispose();
+ empty = null;
+ }
+
+ @Test
+ public void testCreation() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailability() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc = getServiceContext(under);
+ assertNotNull("Check service availability", sc.getServiceReference(BarService.class.getName()));
+
+ under.dispose();
+ }
+
+ @Test
+ public void testCreationLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ under.dispose();
+ }
+
+ @Test
+ public void testServiceAvailabilityLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under-X");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity", under.getState() == ComponentInstance.VALID);
+ ServiceContext sc2 = getServiceContext(under);
+ assertNotNull("Check service availability", sc2.getServiceReference(BarService.class.getName()));
+
+ under.dispose();
+ }
+
+ @Test
+ public void testFactoryManagement() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test
+ public void testFactoryManagementLevel2() {
+ ServiceContext sc = getServiceContext(empty);
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props, sc);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ assertTrue("Check instance validity - 1", under.getState() == ComponentInstance.VALID);
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+ @Test
+ public void testArchitecture() {
+ Properties props = new Properties();
+ props.put("instance.name", "under");
+ ComponentInstance under = null;
+ try {
+ under = bar1Factory.createComponentInstance(props);
+ } catch (Exception e) {
+ fail("Cannot instantiate under : " + e.getMessage());
+ }
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ Architecture arch = (Architecture) getContext().getService(ref);
+ CompositeInstanceDescription id = (CompositeInstanceDescription) arch.getInstanceDescription();
+
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ InstanceDescription[] contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ ComponentFactory fact1 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-1");
+ ComponentFactory fact2 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-2");
+ ComponentFactory fact3 = (ComponentFactory) ipojoHelper.getFactory("COMPO-FooBarProviderType-3");
+
+ fact1.stop();
+ assertTrue("Check instance validity - 2", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ fact2.stop();
+ assertTrue("Check instance validity - 3", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ fact3.stop();
+ assertTrue("Check instance invalidity", under.getState() == ComponentInstance.INVALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.INVALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 0);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ fact1.start();
+ assertTrue("Check instance validity - 4", under.getState() == ComponentInstance.VALID);
+ ref = ipojoHelper.getServiceReferenceByName(Architecture.class.getName(), "under");
+ assertNotNull("Check architecture availability", ref);
+ arch = (Architecture) getContext().getService(ref);
+ //id = arch.getInstanceDescription();
+ assertTrue("Check instance validity - 1", id.getState() == ComponentInstance.VALID);
+ contained = id.getContainedInstances();
+ assertEquals("Check contained instances count", contained.length, 1);
+ assertEquals("Check instance name", id.getName(), "under");
+ assertEquals("Check component type name", id.getComponentDescription().getName(), "composite.bar.1");
+
+ under.dispose();
+ fact2.start();
+ fact3.start();
+ }
+
+}
Propchange: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Feb 26 13:02:34 2013
@@ -0,0 +1,3 @@
+target
+*.iml
+.idea
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/pom.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/pom.xml?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/pom.xml (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/pom.xml Tue Feb 26 13:02:34 2013
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.ipojo.runtime.composite-it</artifactId>
+ <version>1.9.0-SNAPSHOT</version>
+ <relativePath>../../../pom.xml</relativePath>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.felix</groupId>
+ <artifactId>ipojo-composite-runtime-test</artifactId>
+
+ <name>${project.artifactId}</name>
+
+</project>
\ No newline at end of file
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/Baz2CheckProvider.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.BazService;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Properties;
+
+public class Baz2CheckProvider implements CheckService {
+
+ BazService fs;
+
+ int simpleB = 0;
+ int objectB = 0;
+ int refB = 0;
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+
+ public boolean check() {
+ return fs.foo();
+ }
+
+ public Properties getProps() {
+ Properties props = new Properties();
+ props.put("result", new Boolean(fs.foo()));
+ props.put("voidB", new Integer(simpleB));
+ props.put("objectB", new Integer(objectB));
+ props.put("refB", new Integer(refB));
+ props.put("voidU", new Integer(simpleU));
+ props.put("objectU", new Integer(objectU));
+ props.put("refU", new Integer(refU));
+ props.put("boolean", new Boolean(fs.getBoolean()));
+ props.put("int", new Integer(fs.getInt()));
+ props.put("long", new Long(fs.getLong()));
+ props.put("double", new Double(fs.getDouble()));
+ if(fs.getObject() != null) { props.put("object", fs.getObject()); }
+
+ return props;
+ }
+
+ private void voidBind() {
+ simpleB++;
+ }
+ private void voidUnbind() {
+ simpleU++;
+ }
+
+ protected void objectBind(Object o) {
+ if(o != null && o instanceof FooService) { objectB++; }
+ }
+ protected void objectUnbind(Object o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ }
+
+ public void refBind(ServiceReference sr) {
+ if(sr != null) { refB++; }
+ }
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ }
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/BazProviderType1.java Tue Feb 26 13:02:34 2013
@@ -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.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.BazService;
+
+import java.util.Properties;
+
+public class BazProviderType1 implements BazService {
+
+ private int m_bar;
+ private String m_foo;
+
+ public boolean foo() {
+ return true;
+ }
+
+ public Properties fooProps() {
+ Properties p = new Properties();
+ p.put("bar", new Integer(m_bar));
+ p.put("foo", m_foo);
+ return p;
+ }
+
+ 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); }
+
+}
Added: felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java?rev=1450158&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java (added)
+++ felix/trunk/ipojo/runtime/composite-it/src/it/ipojo-composite-runtime-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/CheckProviderParentClass.java Tue Feb 26 13:02:34 2013
@@ -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.runtime.core.components;
+
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.osgi.framework.ServiceReference;
+
+public abstract class CheckProviderParentClass {
+
+ int simpleU = 0;
+ int objectU = 0;
+ int refU = 0;
+ int bothU = 0;
+
+
+ public void bothUnbind(FooService o, ServiceReference sr) {
+ if(sr != null && o != null && o instanceof FooService) { bothU++; }
+ }
+
+ public void refUnbind(ServiceReference sr) {
+ if(sr != null) { refU++; }
+ }
+
+ public void objectUnbind(FooService o) {
+ if(o != null && o instanceof FooService) { objectU++; }
+ else {
+ System.err.println("Unbind null : " + o);
+ }
+ }
+
+ public void voidUnbind() {
+ simpleU++;
+ }
+
+}