You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by pd...@apache.org on 2015/07/09 00:10:16 UTC
svn commit: r1689973 [2/25] - in /felix/sandbox/pderop/dependencymanager.ds:
cnf/ext/ cnf/localrepo/ cnf/localrepo/org.apache.felix.framework/
cnf/releaserepo/ org.apache.felix.dependencymanager.ds.itest/
org.apache.felix.dependencymanager.ds.itest/.se...
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_circularFactory.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_circularFactory.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_circularFactory.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_component_concurrency.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_component_concurrency.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_component_concurrency.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_enable.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_enable.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_enable.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_locate.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_locate.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_locate.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_min_cardinality.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_min_cardinality.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_min_cardinality.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_mutable_properties.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_mutable_properties.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_mutable_properties.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_persistent_factory_components.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_persistent_factory_components.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_persistent_factory_components.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_signature_components.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_signature_components.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_signature_components.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_configuration_change.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_configuration_change.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_configuration_change.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_configuration_pid.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_configuration_pid.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_configuration_pid.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_location.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_location.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_location.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_service_binding.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_service_binding.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_service_binding.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_service_binding_greedy.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_service_binding_greedy.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_components_service_binding_greedy.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_factory_components.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_factory_components.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_simple_factory_components.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_target_properties.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_target_properties.xml?rev=1689973&view=auto
==============================================================================
Binary file - no diff available.
Propchange: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/resource/integration_test_target_properties.xml
------------------------------------------------------------------------------
svn:mime-type = application/xml
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ActivateSignatureTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ActivateSignatureTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ActivateSignatureTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ActivateSignatureTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,66 @@
+/*
+ * 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.scr.integration;
+
+
+import java.util.Collection;
+
+import org.apache.felix.scr.integration.components.activatesignature.AbstractActivateSignatureTestComponent;
+import org.junit.Test;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
+
+import junit.framework.TestCase;
+
+
+/**
+ * The <code>ActivateSignatureTest</code> tests various DS 1.1 activation
+ * signatures for the default method name
+ */
+public class ActivateSignatureTest extends ComponentTestBase
+{
+ public ActivateSignatureTest()
+ {
+ super("/resource/integration_test_signature_components.xml", "activatesignature");
+ }
+
+ @Test
+ public void test()
+ {
+ // wait for components to fire up in the background....
+ delay();
+
+ final Collection<ComponentDescriptionDTO> components = getComponentDescriptions();
+ TestCase.assertNotNull( components );
+
+ for ( ComponentDescriptionDTO component : components )
+ {
+ TestCase.assertTrue( "Expecting component " + component.name + " to be enabled", component
+ .defaultEnabled );
+
+ ComponentConfigurationDTO cc = findComponentConfigurationByName(component.name, -1);
+ TestCase.assertEquals( "Expecting component " + component.name + " to be active",
+ ComponentConfigurationDTO.ACTIVE, cc.state );
+
+ TestCase.assertNotNull("Expect activate method to be called", AbstractActivateSignatureTestComponent.getInstance(component.name));
+
+ }
+ }
+
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/AnnoConfigTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/AnnoConfigTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/AnnoConfigTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/AnnoConfigTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,248 @@
+/*
+ * 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.scr.integration;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.felix.scr.integration.components.annoconfig.AnnoComponent;
+import org.apache.felix.scr.integration.components.annoconfig.AnnoComponent.A1;
+import org.apache.felix.scr.integration.components.annoconfig.AnnoComponent.A1Arrays;
+import org.apache.felix.scr.integration.components.annoconfig.AnnoComponent.E1;
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+
+import junit.framework.TestCase;
+
+public class AnnoConfigTest extends ComponentTestBase
+{
+ public AnnoConfigTest()
+ {
+ super("/resource/integration_test_annoconfig.xml", "annoconfig");
+ }
+
+ @Test
+ public void testAnnoConfig() throws Exception
+ {
+ String name = "org.apache.felix.scr.integration.components.annoconfig";
+ ComponentConfigurationDTO dto = findComponentConfigurationByName(name, ComponentConfigurationDTO.SATISFIED);
+ AnnoComponent ac = getServiceFromConfiguration(dto, AnnoComponent.class);
+ checkA1NoValues(ac.m_a1_activate);
+ checkA1ArraysNoValues(ac.m_a1Arrays_activate);
+
+ Configuration c = configure(name, null, allValues());
+ delay();
+
+ checkA1(ac.m_a1_modified);
+ checkA1Array(ac.m_a1Arrays_modified);
+
+ ungetServiceFromConfiguration(dto, AnnoComponent.class);
+ checkA1(ac.m_a1_deactivate);
+ checkA1Array(ac.m_a1Arrays_deactivate);
+ ac = getServiceFromConfiguration(dto, AnnoComponent.class);
+ checkA1(ac.m_a1_activate);
+ checkA1Array(ac.m_a1Arrays_activate);
+
+ c.delete();
+ delay();
+
+ checkA1NoValues(ac.m_a1_modified);
+ checkA1ArraysNoValues(ac.m_a1Arrays_modified);
+
+ c = configure(name, null, arrayValues());
+ delay();
+
+ checkA1FromArray(ac.m_a1_modified);
+ checkA1ArrayFromArray(ac.m_a1Arrays_modified, false);
+
+ c.delete();
+ delay();
+
+ checkA1NoValues(ac.m_a1_modified);
+ checkA1ArraysNoValues(ac.m_a1Arrays_modified);
+
+ c = configure(name, null, collectionValues());
+ delay();
+
+ checkA1FromArray(ac.m_a1_modified);
+ checkA1ArrayFromArray(ac.m_a1Arrays_modified, true);
+
+ c.delete();
+ }
+
+ private Hashtable<String, Object> allValues()
+ {
+ Hashtable<String, Object> values = new Hashtable<String, Object>();
+ values.put("bool", "true");
+ values.put("byt", 12l);
+ values.put("clas", String.class.getName());
+ values.put("e1", E1.a.toString());
+ values.put("doubl", "3.14");
+ values.put("floa", 500l);
+ values.put("integer", 3.0d);
+ values.put("lon", "12345678");
+ values.put("shor", 3l);
+ values.put("string", 3);
+ return values;
+ }
+
+ private Hashtable<String, Object> arrayValues()
+ {
+ Hashtable<String, Object> values = new Hashtable<String, Object>();
+ values.put("bool", new boolean[] {true, false});
+ values.put("byt", new byte[] {12, 3});
+ values.put("clas", new String[] {String.class.getName(), Integer.class.getName()});
+ values.put("e1", new String[] {E1.a.name(), E1.b.name()});
+ values.put("doubl", new double[] {3.14, 2.78, 9});
+ values.put("floa", new float[] {500, 37.44f});
+ values.put("integer", new int[] {3, 6, 9});
+ values.put("lon", new long[] {12345678l, -1});
+ values.put("shor", new short[] {3, 88});
+ values.put("string", new String[] {});
+ return values;
+ }
+
+ private Hashtable<String, Object> collectionValues()
+ {
+ Hashtable<String, Object> values = arrayValues();
+ Hashtable<String, Object> collectionValues = new Hashtable<String, Object>();
+ for (Map.Entry<String, Object> entry: values.entrySet())
+ {
+ collectionValues.put(entry.getKey(), toList(entry.getValue()));
+ }
+ //yuck
+ collectionValues.remove("string");
+ return collectionValues;
+ }
+
+ private List<?> toList(Object value)
+ {
+ List result = new ArrayList();
+ for (int i = 0; i < Array.getLength(value); i++)
+ {
+ result.add(Array.get(value, i));
+ }
+ return result;
+ }
+
+ private void checkA1(A1 a)
+ {
+ TestCase.assertEquals(true, a.bool());
+ TestCase.assertEquals((byte)12, a.byt());
+ TestCase.assertEquals(String.class, a.clas());
+ TestCase.assertEquals(E1.a, a.e1());
+ TestCase.assertEquals(3.14d, a.doubl());
+ TestCase.assertEquals(500f, a.floa());
+ TestCase.assertEquals(3, a.integer());
+ TestCase.assertEquals(12345678l, a.lon());
+ TestCase.assertEquals((short)3, a.shor());
+ TestCase.assertEquals("3", a.string());
+ }
+
+
+ private void checkA1FromArray(A1 a)
+ {
+ TestCase.assertEquals(true, a.bool());
+ TestCase.assertEquals((byte)12, a.byt());
+ TestCase.assertEquals(String.class, a.clas());
+ TestCase.assertEquals(E1.a, a.e1());
+ TestCase.assertEquals(3.14d, a.doubl());
+ TestCase.assertEquals(500f, a.floa());
+ TestCase.assertEquals(3, a.integer());
+ TestCase.assertEquals(12345678l, a.lon());
+ TestCase.assertEquals((short)3, a.shor());
+ TestCase.assertEquals(null, a.string());
+ }
+
+ private void checkA1Array(A1Arrays a)
+ {
+ assertArrayEquals(new boolean[] {true}, a.bool());
+ assertArrayEquals(new byte[] {(byte)12}, a.byt());
+ assertArrayEquals(new Class<?>[] {String.class}, a.clas());
+ assertArrayEquals(new E1[] {E1.a}, a.e1());
+ assertArrayEquals(new double[] {3.14d}, a.doubl());
+ assertArrayEquals(new float[] {500f}, a.floa());
+ assertArrayEquals(new int[] {3}, a.integer());
+ assertArrayEquals(new long[] {12345678l}, a.lon());
+ assertArrayEquals(new short[] {(short)3}, a.shor());
+ assertArrayEquals(new String[] {"3"}, a.string());
+ }
+
+ private void checkA1ArrayFromArray(A1Arrays a, boolean caBug)
+ {
+ assertArrayEquals(new boolean[] {true, false}, a.bool());
+ assertArrayEquals(new byte[] {12, 3}, a.byt());
+ assertArrayEquals(new Class<?>[] {String.class, Integer.class}, a.clas());
+ assertArrayEquals(new E1[] {E1.a, E1.b}, a.e1());
+ assertArrayEquals(new double[] {3.14, 2.78, 9}, a.doubl());
+ assertArrayEquals(new float[] {500f, 37.44f}, a.floa());
+ assertArrayEquals(new int[] {3, 6, 9}, a.integer());
+ assertArrayEquals(new long[] {12345678l, -1}, a.lon());
+ assertArrayEquals(new short[] {(short)3, 88}, a.shor());
+ if (!caBug)
+ {
+ assertArrayEquals(new String[] {}, a.string());
+ }
+ }
+
+ private void assertArrayEquals(Object a, Object b)
+ {
+ TestCase.assertTrue(a.getClass().isArray());
+ TestCase.assertTrue(b.getClass().isArray());
+ TestCase.assertEquals("wrong length", Array.getLength(a), Array.getLength(b));
+ TestCase.assertEquals("wrong type", a.getClass().getComponentType(), b.getClass().getComponentType());
+ for (int i = 0; i < Array.getLength(a); i++)
+ {
+ TestCase.assertEquals("different value at " + i, Array.get(a, i), Array.get(b, i));
+ }
+
+ }
+
+ private void checkA1NoValues(A1 a)
+ {
+ TestCase.assertEquals(false, a.bool());
+ TestCase.assertEquals((byte)0, a.byt());
+ TestCase.assertEquals(null, a.clas());
+ TestCase.assertEquals(null, a.e1());
+ TestCase.assertEquals(0d, a.doubl());
+ TestCase.assertEquals(0f, a.floa());
+ TestCase.assertEquals(0, a.integer());
+ TestCase.assertEquals(0l, a.lon());
+ TestCase.assertEquals((short)0, a.shor());
+ TestCase.assertEquals(null, a.string());
+ }
+
+ private void checkA1ArraysNoValues(A1Arrays a)
+ {
+ TestCase.assertEquals(null, a.bool());
+ TestCase.assertEquals(null, a.byt());
+ TestCase.assertEquals(null, a.clas());
+ TestCase.assertEquals(null, a.e1());
+ TestCase.assertEquals(null, a.doubl());
+ TestCase.assertEquals(null, a.floa());
+ TestCase.assertEquals(null, a.integer());
+ TestCase.assertEquals(null, a.lon());
+ TestCase.assertEquals(null, a.shor());
+ TestCase.assertEquals(null, a.string());
+ }
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/BundleGenerator.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/BundleGenerator.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/BundleGenerator.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/BundleGenerator.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,229 @@
+/*
+* 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.scr.integration;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import aQute.bnd.osgi.Analyzer;
+import aQute.bnd.osgi.Builder;
+import aQute.bnd.osgi.EmbeddedResource;
+import aQute.bnd.osgi.Jar;
+import aQute.bnd.osgi.Resource;
+
+/**
+ * Helper used to generate a bundle dynamically.
+ */
+public class BundleGenerator
+{
+ /**
+ * The Bnd directives
+ */
+ private Properties m_directives = new Properties();
+
+ /**
+ * The class loader used to get the classpath where to collect the bundle classes
+ */
+ private ClassLoader m_classLoader = BundleGenerator.class.getClassLoader();
+
+ /**
+ * Some resource files to be added to the component. The hashtable key is the path
+ * to a descriptor. The value is a bnd Resource object which contains the content of a
+ * descriptor.
+ */
+ Map<String, Resource> m_resources = new HashMap<String, Resource>();
+
+ /**
+ * Sets a Bnd directive
+ * @param attributeName the directive name (can start with a "-")
+ * @param attributeValue the directive value
+ * @return ourself
+ */
+ public BundleGenerator set(String attributeName, String attributeValue)
+ {
+ m_directives.put(attributeName, attributeValue);
+ return this;
+ }
+
+ /**
+ * Adds a resource file.
+ * @throws IOException
+ */
+ public BundleGenerator add(String path, URL content) throws IOException {
+ m_resources.put(path, createResource(content));
+ return this;
+ }
+
+ /**
+ * Sets a specific class loader, which will be used to get the classpath where to collect
+ * the bundle classes. By default, the class loader used is the BundleGenerator class loader.
+ * @param cl the class loader that will be used to get the bundle classpath
+ * @return ourself
+ */
+ public BundleGenerator setClassLoader(ClassLoader cl)
+ {
+ m_classLoader = cl;
+ return this;
+ }
+
+ /**
+ * Builds the target bundle.
+ */
+ public InputStream buildWithBnd() throws IOException {
+ URL bundleURL = buildBundleURL();
+ return new BufferedInputStream(bundleURL.openStream());
+ }
+
+ /**
+ * Generates the output bundle
+ * @return the bundle URL, as a String
+ */
+ private URL buildBundleURL()
+ {
+ try
+ {
+ // Check if the system tmp dir exists
+
+ File tmp = new File(System.getProperty("java.io.tmpdir"));
+ if (!tmp.exists())
+ {
+ if (! tmp.mkdirs())
+ {
+ throw new IOException("Could not create temporary directory: " + tmp);
+ }
+ }
+
+ String classpath = getClassPath();
+
+ // Create the bundle output file
+
+ File output = File.createTempFile("TinyBundle", ".jar");
+ output.deleteOnExit();
+
+ // Create the bnd directive file
+
+ File directives = File.createTempFile("TinyBundle", ".bnd");
+ directives.deleteOnExit();
+
+ // Write the directives into the bnd file.
+
+ PrintWriter pw = new PrintWriter(new FileWriter(directives));
+ try
+ {
+ for (Object key : m_directives.keySet())
+ {
+ Object value = m_directives.get(key);
+ if (key.toString().startsWith("-"))
+ {
+ pw.println(key.toString() + " " + value.toString());
+ }
+ else
+ {
+ pw.println(key.toString() + ": " + value.toString());
+ }
+ }
+ }
+
+ finally
+ {
+ pw.close();
+ }
+
+ // Launch Bnd in order to generate our tiny test bundle.
+
+ buildWithBnd(classpath, output);
+
+ // Return the URL of the generated bundle, as a String.
+
+ return output.toURI().toURL();
+ }
+
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Unexpected exception while generating DM test bundle", t);
+ }
+ }
+
+ /**
+ * Invoke Bnd builder for generating the target tiny bundle.
+ */
+ private void buildWithBnd(String classpath, File output)
+ throws Exception
+ {
+ Builder builder = new Builder();
+ builder.setProperty(Analyzer.FAIL_OK, "true");
+ builder.setProperties(m_directives);
+ builder.setClasspath(new String[] { classpath });
+ Jar jar = builder.build();
+ jar.setName(output.getName());
+ for (Map.Entry<String, Resource> e : m_resources.entrySet()) {
+ jar.putResource(e.getKey(), e.getValue());
+ }
+ jar.write(output);
+ builder.close();
+ }
+
+ /**
+ * Gets the bundle classpath, where the bundle classes will be collected.
+ */
+ private String getClassPath()
+ {
+ try
+ {
+ File tmp = new File(BundleGenerator.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
+ return tmp.getPath();
+ }
+ catch (URISyntaxException e)
+ {
+ e.printStackTrace();
+ return "generated/.";
+ }
+ }
+
+ /**
+ * Creates a bnd resource object.
+ * @throws IOException
+ */
+ private Resource createResource(URL content) throws IOException {
+ try (BufferedInputStream in = new BufferedInputStream(content.openStream())) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+ int b;
+ while ((b = in.read()) != -1) {
+ out.write(b);
+ }
+ return new EmbeddedResource(out.toByteArray(), 0);
+ }
+ }
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularFactoryTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularFactoryTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularFactoryTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularFactoryTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,47 @@
+/*
+ * 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.scr.integration;
+
+import org.apache.felix.scr.integration.components.circularFactory.FactoryClient;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+
+import junit.framework.TestCase;
+
+public class CircularFactoryTest extends ComponentTestBase
+{
+ public CircularFactoryTest()
+ {
+ super("/resource/integration_test_circularFactory.xml", "circularFactory");
+ }
+
+ @Test
+ public void testCircularFactory() throws Exception
+ {
+ ServiceReference<FactoryClient> sr = bundle.getBundleContext().getServiceReference( FactoryClient.class );
+ FactoryClient fc = bundle.getBundleContext().getService( sr );
+
+ for ( String message: log.foundWarnings() )
+ {
+ TestCase.fail( "unexpected warning or error logged: " + message );
+ }
+
+ }
+
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularReferenceTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularReferenceTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularReferenceTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/CircularReferenceTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,281 @@
+/*
+ * 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.scr.integration;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.Collection;
+import java.util.Map;
+
+import org.apache.felix.scr.integration.components.circular.A;
+import org.apache.felix.scr.integration.components.circular.B;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
+import org.osgi.service.log.LogService;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev: 1616385 $ $Date: 2014-08-07 04:11:27 +0200 (Thu, 07 Aug 2014) $
+ */
+public class CircularReferenceTest extends ComponentTestBase
+{
+ public CircularReferenceTest()
+ {
+ super("/resource/integration_test_circular.xml", "circular");
+ ignoredWarnings = new String[] {
+ "\\[.*\\] Circular reference detected, getService returning null",
+ "FrameworkEvent: ERROR\\norg.osgi.framework.ServiceException: Service factory returned null.",
+ "FrameworkEvent: ERROR\\norg.osgi.framework.ServiceException: ServiceFactory.getService\\(\\) resulted in a cycle.",
+ "\\[.*\\] Cannot create component instance due to failure to bind reference b",
+ "\\[.*\\] Failed creating the component instance; see log for reason",
+ "\\[.*\\] Could not get service from ref \\[org.apache.felix.scr.integration.components.circular.A\\]",
+ "\\[.*\\] Could not get service from ref \\[org.apache.felix.scr.integration.components.circular.B\\]",
+ };
+ //DS_LOGLEVEL = "debug";
+ }
+
+ /**
+ * A and B have mandatory dependencies on each other. Neither should start.
+ * @throws InterruptedException
+ * @throws InvocationTargetException
+ */
+ @Test
+ public void test_A11_B11()
+ {
+ String componentNameA = "1.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.UNSATISFIED_REFERENCE );
+
+ String componentNameB = "1.B.1.1.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.UNSATISFIED_REFERENCE );
+ }
+
+ /**
+ * A > 1.1 > B > 0..n > A Both should start (A first), but B should not have an A reference.
+ * @throws InvalidSyntaxException
+ */
+ @Test
+ public void test_A11_B0n_immediate_A_first() throws InvalidSyntaxException
+ {
+ String componentNameA = "2.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+
+ String componentNameB = "2.B.0.n.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+ }
+ /**
+ * A > 1.1 > B > 0..n > A Both should start (B first), and B should have an A reference.
+ * @throws InvalidSyntaxException
+ */
+ @Test
+ public void test_A11_B0n_immediate_B_first() throws InvalidSyntaxException
+ {
+ String componentNameA = "3.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+
+ String componentNameB = "3.B.0.n.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+ }
+ /**
+ * A > 1.1 > B > 0..n > A Both should start, but B should not have an A reference.
+ */
+ @Test
+ public void test_A11_B0n_delayed_A_first() throws InvalidSyntaxException
+ {
+ String componentNameA = "4.1.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
+
+ String componentNameB = "4.1.B.0.n.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
+
+ delay();
+
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ delay(); //async binding of a to b after circular ref detected
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+ }
+ /**
+ * A > 1.1 > B > 0..n > A Both should start, but B should not have an A reference.
+ */
+ @Test
+ public void test_A11_B0n_delayed_B_first() throws Exception
+ {
+ String componentNameA = "4.2.A.1.1.dynamic";
+ ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
+
+ String componentNameB = "4.2.B.0.n.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED);
+
+ ServiceReference[] serviceReferencesB = bundleContext.getServiceReferences( B.class.getName(), "(service.pid=" + componentNameB + ")" );
+ TestCase.assertEquals( 1, serviceReferencesB.length );
+ ServiceReference serviceReferenceB = serviceReferencesB[0];
+ Object serviceB = bundleContext.getService( serviceReferenceB );
+ assertNotNull( serviceB );
+
+ ServiceReference[] serviceReferencesA = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
+ TestCase.assertEquals( 1, serviceReferencesA.length );
+ ServiceReference serviceReferenceA = serviceReferencesA[0];
+ Object serviceA = bundleContext.getService( serviceReferenceA );
+ assertNotNull( serviceA );
+
+ delay();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+
+
+ //disabling (removing the A service registration) and re-enabling will
+ //result in a service event to B, so B will bind A.
+ disableAndCheck(componentA);
+ delay();
+ enableAndCheck(componentA.description);
+ delay();
+
+ //new component.id, refetch configuration.
+ componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+
+ }
+ /**
+ * A > 1.1 > B > 0..1 > A Both should start (A first), but B should not have an A reference.
+ * @throws InvalidSyntaxException
+ */
+ @Test
+ public void test_A11_B01_immediate_A_first() throws InvalidSyntaxException
+ {
+ String componentNameA = "5.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+
+ String componentNameB = "5.B.0.1.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+ }
+ /**
+ * A > 1.1 > B > 0..1 > A Both should start (B first), and B should have an A reference.
+ * @throws InvalidSyntaxException
+ */
+ @Test
+ public void test_A11_B01_immediate_B_first() throws InvalidSyntaxException
+ {
+ String componentNameA = "6.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+
+ String componentNameB = "6.B.0.1.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.ACTIVE );
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+ }
+ /**
+ * A > 1.1 > B > 0..1 > A Both should start, but B should not have an A reference.
+ */
+ @Test
+ public void test_A11_B01_delayed_A_first() throws InvalidSyntaxException
+ {
+ String componentNameA = "7.1.A.1.1.dynamic";
+ final ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
+
+ String componentNameB = "7.1.B.0.1.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
+
+ ServiceReference[] serviceReferences = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
+ TestCase.assertEquals( 1, serviceReferences.length );
+ ServiceReference serviceReference = serviceReferences[0];
+ Object service = bundleContext.getService( serviceReference );
+ assertNotNull( service );
+
+ delay();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+ }
+ /**
+ * A > 1.1 > B > 0..1 > A Both should start, but B should not have an A reference.
+ */
+ @Test
+ public void test_A11_B01_delayed_B_first() throws Exception
+ {
+ String componentNameA = "7.2.A.1.1.dynamic";
+ ComponentConfigurationDTO componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.SATISFIED );
+
+ String componentNameB = "7.2.B.0.1.dynamic";
+ final ComponentConfigurationDTO componentB = findComponentConfigurationByName( componentNameB, ComponentConfigurationDTO.SATISFIED );
+
+ ServiceReference[] serviceReferencesB = bundleContext.getServiceReferences( B.class.getName(), "(service.pid=" + componentNameB + ")" );
+ TestCase.assertEquals( 1, serviceReferencesB.length );
+ ServiceReference serviceReferenceB = serviceReferencesB[0];
+ Object serviceB = bundleContext.getService( serviceReferenceB );
+ assertNotNull( serviceB );
+
+ ServiceReference[] serviceReferencesA = bundleContext.getServiceReferences( A.class.getName(), "(service.pid=" + componentNameA + ")" );
+ TestCase.assertEquals( 1, serviceReferencesA.length );
+ ServiceReference serviceReferenceA = serviceReferencesA[0];
+ Object serviceA = bundleContext.getService( serviceReferenceA );
+ assertNotNull( serviceA );
+
+
+ delay();
+ A a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ B b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+
+
+ //disabling (removing the A service registration) and re-enabling will
+ //result in a service event to B, so B will bind A.
+ disableAndCheck(componentA);
+ delay();
+ enableAndCheck(componentA.description);
+ delay();
+
+ //new component.id, refetch configuration.
+ componentA = findComponentConfigurationByName( componentNameA, ComponentConfigurationDTO.ACTIVE );
+ a = getServiceFromConfiguration(componentA, A.class);
+ assertEquals( 1, a.getBs().size());
+ b = getServiceFromConfiguration(componentB, B.class);
+ assertEquals( 1, b.getAs().size() );
+
+ }
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentActivationTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentActivationTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentActivationTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentActivationTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,228 @@
+/*
+ * 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.scr.integration;
+
+
+import org.apache.felix.scr.integration.components.ActivatorComponent;
+import org.apache.felix.scr.integration.components.SimpleServiceImpl;
+import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+
+import junit.framework.TestCase;
+
+
+public class ComponentActivationTest extends ComponentTestBase
+{
+ public ComponentActivationTest()
+ {
+ super("/resource/integration_test_activation_components.xml");
+ ignoredWarnings = new String[] {
+ ".*Component deactivation threw an exception\\njava.lang.IllegalStateException: ServiceFactory\\.ungetService\\(\\) resulted in a cycle.*",
+ ".*The myDeactivate method has thrown an exception\\njava.lang.IllegalStateException: Service already unregistered\\.",
+ "\\[ActivatorComponent.bind.multiple.static.greedy\\(-1\\)\\] Component deactivation threw an exception\\njava.lang.NullPointerException",
+ "\\[ActivatorComponent.activate.fail.*\\] The myActivate method has thrown an exception\\njava.lang.IllegalStateException: myActivate fails",
+ "\\[ActivatorComponent.deactivate.fail.*\\] The myDeactivate method has thrown an exception\\njava.lang.IllegalStateException: myDeactivate fails",
+ "\\[ActivatorComponent.activate.missing.*\\] activate method \\[nonExistingActivate\\] not found; Component will fail",
+ "\\[ActivatorComponent.activate.missing.*\\] Failed creating the component instance\\; see log for reason",
+ "\\[ActivatorComponent.activate.fail.*\\] The myActivate method has thrown an exception",
+ "\\[ActivatorComponent.activate.fail.*\\] Failed creating the component instance; see log for reason",
+ "\\[ActivatorComponent.deactivate.missing.*\\] deactivate method \\[nonExistingDeactivate\\] not found; Component will fail"
+ };
+ }
+
+ @Test
+ public void test_activator_not_declared() throws Exception
+ {
+ final String componentname = "ActivatorComponent.no.decl";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ disableAndCheck( cc );
+ }
+
+
+ @Test //Changed to expect SATISFIED rather than unsatisfied
+ public void test_activate_missing() throws Exception
+ {
+ final String componentname = "ActivatorComponent.activate.missing";
+
+ // activate must fail, so state remains SATISFIED
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
+
+ disableAndCheck( cc );
+ }
+
+
+ @Test
+ public void test_deactivate_missing() throws Exception
+ {
+ final String componentname = "ActivatorComponent.deactivate.missing";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ disableAndCheck( cc );
+ }
+
+
+ @Test
+ public void test_activator_declared() throws Exception
+ {
+ final String componentname = "ActivatorComponent.decl";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ disableAndCheck( cc );
+ }
+
+
+ @Test // Failure to activate does not mean the state should change to unsatisfied.
+ public void test_activate_fail() throws Exception
+ {
+ final String componentname = "ActivatorComponent.activate.fail";
+
+ // activate must fail, so state remains SATISFIED
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
+
+ disableAndCheck( cc );
+ }
+
+
+ @Test
+ public void test_deactivate_fail() throws Exception
+ {
+ final String componentname = "ActivatorComponent.deactivate.fail";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ disableAndCheck( cc );
+ }
+
+
+ @Test
+ public void test_activate_register_service() throws Exception
+ {
+ final String componentname = "ActivatorComponent.activate.with.bind";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ ActivatorComponent ac = ActivatorComponent.getInstance();
+ TestCase.assertNotNull( ac.getSimpleService() );
+
+ disableAndCheck( cc );
+
+ TestCase.assertNull( ac.getSimpleService() );
+ }
+
+
+ @Test
+ public void test_activate_register_service_delayed() throws Exception
+ {
+ final String componentname = "ActivatorComponent.activate.delayed.with.bind";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
+
+ getServiceFromConfiguration(cc, ActivatorComponent.class);
+
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ disableAndCheck( cc );
+ }
+
+ @Test
+ public void test_activate_service_factory_register_service() throws Exception
+ {
+ final String componentname = "ActivatorComponent.activate.service.factory.with.bind";
+
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.SATISFIED);
+
+ getServiceFromConfiguration(cc, ActivatorComponent.class);
+
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
+
+ disableAndCheck( cc );
+ }
+
+ @Test
+ public void test_activate_register_service_single_static_dependency() throws Exception
+ {
+ final String componentname = "ActivatorComponent.bind.single.static";
+
+ testRequiredDependency( componentname );
+ }
+
+ @Test
+ public void test_activate_register_service_multiple_static_reluctant_dependency() throws Exception
+ {
+ final String componentname = "ActivatorComponent.bind.multiple.static.reluctant";
+
+ testRequiredDependency( componentname );
+ }
+
+ @Test
+ public void test_activate_register_service_multiple_static_greedy_dependency() throws Exception
+ {
+ final String componentname = "ActivatorComponent.bind.multiple.static.greedy";
+
+ testRequiredDependency( componentname );
+ }
+
+ @Test
+ public void test_activate_register_service_single_dynamic_dependency() throws Exception
+ {
+ final String componentname = "ActivatorComponent.bind.single.dynamic";
+
+ testRequiredDependency( componentname );
+ }
+
+ @Test
+ public void test_activate_register_service_multiple_dynamic_dependency() throws Exception
+ {
+ final String componentname = "ActivatorComponent.bind.multiple.dynamic";
+
+ testRequiredDependency( componentname );
+ }
+
+
+ private void testRequiredDependency(final String componentname) throws Exception
+ {
+ ComponentConfigurationDTO cc = getDisabledConfigurationAndEnable(componentname, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
+
+ SimpleServiceImpl ss = SimpleServiceImpl.create( bundleContext, "foo" );
+
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.SATISFIED);
+
+ ServiceReference<ActivatorComponent> ref = bundleContext.getServiceReference( ActivatorComponent.class );
+
+ ss.drop();
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
+
+
+ TestCase.assertNull(bundleContext.getServiceReference( ActivatorComponent.class ));
+ ss = SimpleServiceImpl.create( bundleContext, "foo" );
+ ref = bundleContext.getServiceReference( ActivatorComponent.class );
+ ActivatorComponent ac = bundleContext.getService( ref );
+ TestCase.assertNotNull( ac.getSimpleService() );
+
+ findComponentConfigurationByName(componentname, ComponentConfigurationDTO.ACTIVE);
+ disableAndCheck( cc );
+ ss.drop();
+ }
+
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConcurrencyTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConcurrencyTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConcurrencyTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConcurrencyTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,63 @@
+/*
+ * 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.scr.integration;
+
+import org.junit.Test;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.log.LogService;
+
+public class ComponentConcurrencyTest extends ComponentTestBase
+{
+ public ComponentConcurrencyTest()
+ {
+ super("/resource/integration_test_component_concurrency.xml", "concurrency");
+ restrictedLogging = true;
+
+ ignoredWarnings = new String[] {
+ "ComponentConcurrencyTest is currently failing and is disabled \\(ask to mailing list about it\\).",
+ "\\[org.apache.felix.scr.integration.components.concurrency.*\\] Cannot create component instance due to failure to bind reference c",
+ "FrameworkEvent: ERROR\norg.osgi.framework.ServiceException: Service factory returned null.",
+ "\\[org.apache.felix.scr.integration.components.concurrency.A.*\\] Could not get service from ref \\[org.apache.felix.scr.integration.components.concurrency.*\\]",
+ "\\[org.apache.felix.scr.integration.components.concurrency.B.*\\] Failed creating the component instance; see log for reason",
+ "\\[org.apache.felix.scr.integration.components.concurrency.A.*\\] DependencyManager : invokeBindMethod : Service not available from service registry for ServiceReference \\[org.apache.felix.scr.integration.components.concurrency.B\\] for reference b"
+ };
+ //DS_LOGLEVEL = "warn";
+ }
+
+ protected static void delay(int secs)
+ {
+ try
+ {
+ Thread.sleep(secs * 1000);
+ }
+ catch (InterruptedException ie)
+ {
+ }
+ }
+
+ @Test
+ public void test_concurrent_component_activation_using_componentFactories() throws Exception
+ {
+ // Currently, this test fails with all sort of exceptions.
+ // for now, let's make this test fail. and post on the mailing list to see if someone could take a look.
+
+ if (true) {
+ log.log(LogService.LOG_WARNING, "ComponentConcurrencyTest is currently failing and is disabled (ask to mailing list about it).");
+ return;
+ }
+ ComponentConfigurationDTO ccA = getDisabledConfigurationAndEnable( "org.apache.felix.scr.integration.components.concurrency.AFactory", ComponentConfigurationDTO.ACTIVE );
+ ComponentConfigurationDTO ccC = getDisabledConfigurationAndEnable( "org.apache.felix.scr.integration.components.concurrency.CFactory", ComponentConfigurationDTO.ACTIVE );
+
+ delay( 10 );
+ disableAndCheck(ccA);
+ disableAndCheck(ccC);
+ }
+}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java
URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java?rev=1689973&view=auto
==============================================================================
--- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java (added)
+++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds.itest/src/org/apache/felix/scr/integration/ComponentConfigurationPidTest.java Wed Jul 8 22:10:14 2015
@@ -0,0 +1,89 @@
+/*
+ * 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.scr.integration;
+
+
+import org.apache.felix.scr.integration.components.SimpleComponent;
+import org.junit.Test;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
+
+import junit.framework.TestCase;
+
+
+public class ComponentConfigurationPidTest extends ComponentTestBase
+{
+ public ComponentConfigurationPidTest()
+ {
+ super("/resource/integration_test_simple_components_configuration_pid.xml");
+ }
+
+ @Test
+ public void test_configurationpid_use_other_pid() throws Exception
+ {
+ final String pid = "ConfigurationPid.otherPid";
+ final String name = "ConfigurationPid.componentName";
+ deleteConfig( pid );
+ delay();
+ TestCase.assertNull( SimpleComponent.INSTANCE );
+
+ getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
+
+ TestCase.assertNull( SimpleComponent.INSTANCE );
+
+ configure( pid );
+ delay();
+
+ findComponentConfigurationByName( name, ComponentConfigurationDTO.ACTIVE);
+ TestCase.assertNotNull( SimpleComponent.INSTANCE );
+ TestCase.assertEquals( PROP_NAME, SimpleComponent.INSTANCE.getProperty( PROP_NAME ) );
+
+ deleteConfig( pid );
+ delay();
+
+ ComponentDescriptionDTO cd = checkConfigurationCount(name, 0, -1);
+ TestCase.assertNull( SimpleComponent.INSTANCE );
+
+ disableAndCheck( cd );
+ TestCase.assertNull( SimpleComponent.INSTANCE );
+ }
+
+ @Test
+ public void test_configurationpid_must_not_use_name_as_pid() throws Exception
+ {
+ final String name = "ConfigurationPid.componentName";
+ final String pid = name;
+ deleteConfig( pid );
+ delay();
+
+ getConfigurationsDisabledThenEnable(name, 0, ComponentConfigurationDTO.UNSATISFIED_REFERENCE);
+ TestCase.assertNull( SimpleComponent.INSTANCE );
+
+ configure( pid );
+ delay();
+
+ ComponentDescriptionDTO cd = checkConfigurationCount(name, 0, -1);
+ TestCase.assertNull( SimpleComponent.INSTANCE );
+
+ deleteConfig( pid );
+ delay();
+
+ disableAndCheck( cd );
+ }
+}