Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/config/ConfiguredComponentHolderTest.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,232 @@ +/* + * 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.impl.config; + + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.felix.scr.impl.TargetedPID; +import org.apache.felix.scr.impl.helper.ComponentMethods; +import org.apache.felix.scr.impl.manager.SingleComponentManager; +import org.apache.felix.scr.impl.metadata.ComponentMetadata; +import org.apache.felix.scr.impl.metadata.DSVersion; +import org.apache.felix.scr.impl.metadata.XmlHandler; + + +public class ConfiguredComponentHolderTest extends TestCase +{ + + public void test_none() + { + // setup a holder + final String name = "test.none"; + final ComponentMetadata cm = createComponentMetadata( name ); + final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder( cm ); + + holder.enableComponents(false); + // assert single component and no map + final SingleComponentManager cmgr = getSingleManager( holder ); + assertNotNull( "Expect single component manager", cmgr ); + assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).size()); + } + + + public void test_singleton() + { + // setup a holder + final String name = "test.singleton"; + final ComponentMetadata cm = createComponentMetadata( name ); + final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder( cm ); + + holder.enableComponents(false); + // assert single component and no map + final SingleComponentManager cmgr = getSingleManager( holder ); + assertNotNull( "Expect single component manager", cmgr ); + assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).size()); + + // configure with the singleton configuration + final Dictionary config = new Hashtable(); + config.put( "value", name ); + TargetedPID targetedPid = new TargetedPID(name); + holder.configurationUpdated( targetedPid, null, config, 0 ); + + // assert single component and no map + final SingleComponentManager cmgrAfterConfig = getSingleManager( holder ); + assertNotNull( "Expect single component manager", cmgrAfterConfig ); + assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).size()); + +// // assert configuration of single component + final Map componentConfig = ( ( MockImmediateComponentManager ) cmgrAfterConfig ).getConfiguration(); + assertEquals( "Expect exact configuration set", config, componentConfig ); + + // unconfigure singleton + holder.configurationDeleted( targetedPid, null ); + + // assert single component and no map + final SingleComponentManager cmgrAfterUnconfig = getSingleManager( holder ); + assertNotNull( "Expect single component manager", cmgrAfterUnconfig ); + assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).size()); + + // assert no configuration of single component +//TODO multipids fix, correct assertion assertFalse( "Expect no configuration", cmgrAfterUnconfig.hasConfiguration() ); + } + + + public void test_factory() + { + // setup a holder + final String name = "test.factory"; + final ComponentMetadata cm = createComponentMetadata( name ); + final TestingConfiguredComponentHolder holder = new TestingConfiguredComponentHolder( cm ); + + holder.enableComponents(false); + + // assert single component and no map + final SingleComponentManager cmgr = getSingleManager( holder ); + assertNotNull( "Expect single component manager", cmgr ); + assertEquals( "Expect no other component manager list", 1, getComponentManagers( holder ).size()); + + // configure with configuration + final String pid1 = "test.factory.0001"; + final Dictionary config1 = new Hashtable(); + config1.put( "value", pid1 ); + TargetedPID targetedFactoryPid = new TargetedPID(name); + TargetedPID targetedPid1 = new TargetedPID(pid1); + holder.configurationUpdated( targetedPid1, targetedFactoryPid, config1, 0 ); + + // assert single component and single-entry map + final SingleComponentManager cmgrAfterConfig = getSingleManager( holder ); + final List<SingleComponentManager> cmgrsAfterConfig = getComponentManagers( holder ); + assertNotNull( "Expect single component manager", cmgrAfterConfig ); + assertNotNull( "Expect component manager list", cmgrsAfterConfig ); + assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfig.size() ); + + // add another configuration + final String pid2 = "test.factory.0002"; + final Dictionary config2 = new Hashtable(); + config1.put( "value", pid2 ); + TargetedPID targetedPid2 = new TargetedPID(pid2); + holder.configurationUpdated( targetedPid2, targetedFactoryPid, config2, 1 ); + + final List<SingleComponentManager> cmgrsAfterConfig2 = getComponentManagers( holder ); + assertNotNull( "Expect component manager list", cmgrsAfterConfig2 ); + assertEquals( "Expect two component manager in list", 2, cmgrsAfterConfig2.size() ); + + // remove second configuration + holder.configurationDeleted( targetedPid2, targetedFactoryPid ); + + final List<SingleComponentManager> cmgrsAfterUnConfig2 = getComponentManagers( holder ); + assertNotNull( "Expect component manager list", cmgrsAfterUnConfig2 ); +//TODO Multipids fix correct assertion assertEquals( "Expect one component manager in list", 1, cmgrsAfterUnConfig2.size() ); + + // add second config again and remove first config -> replace singleton component + holder.configurationUpdated( targetedPid2, targetedFactoryPid, config2, 2 ); + holder.configurationDeleted( targetedPid1, targetedFactoryPid ); + + // assert single component and single-entry map + final List<SingleComponentManager> cmgrsAfterConfigUnconfig = getComponentManagers( holder ); + assertNotNull( "Expect component manager list", cmgrsAfterConfigUnconfig ); +//TODO Multipids fix correct assertion assertEquals( "Expect one component manager in list", 1, cmgrsAfterConfigUnconfig.size() ); + + // remove second configuration (leaving no configurations) + holder.configurationDeleted( targetedPid2, targetedFactoryPid ); + + // assert single component and single-entry map + final List<SingleComponentManager> cmgrsAfterAllUnconfig = getComponentManagers( holder ); + assertNotNull( "Expect single component manager", cmgrsAfterAllUnconfig ); +//TODO Multipids fix correct assertion assertEquals( "Expect no component manager list", 1, cmgrsAfterAllUnconfig.size() ); + + } + + + private static ComponentMetadata createComponentMetadata( String name ) + { + final ComponentMetadata metadata = new ComponentMetadata( DSVersion.DS11 ); + metadata.setName( name ); + metadata.setImplementationClassName(Object.class.getName()); + metadata.validate(null); + + return metadata; + } + + + private static SingleComponentManager getSingleManager( ConfigurableComponentHolder holder ) + { + List<SingleComponentManager> managers = getComponentManagers(holder); + assertEquals(1, managers.size()); + return managers.get(0); + } + + + private static List<SingleComponentManager> getComponentManagers( ConfigurableComponentHolder holder ) + { + return holder.getComponentManagers(); + } + + private static class TestingConfiguredComponentHolder extends ConfigurableComponentHolder + { + TestingConfiguredComponentHolder( ComponentMetadata metadata ) + { + super( null, metadata ); + } + + + protected SingleComponentManager createComponentManager(boolean factoryConfiguration) + { + return new MockImmediateComponentManager( this ); + } + } + + private static class MockImmediateComponentManager<S> extends SingleComponentManager<S> + { + + private Map<String, Object> m_configuration; + + + public MockImmediateComponentManager( ComponentContainer container ) + { + super( container, new ComponentMethods() ); + } + + + Map<String, Object> getConfiguration() + { + return m_configuration; + } + + + public boolean hasConfiguration() + { + return m_configuration != null; + } + + + public void reconfigure( Map<String, Object> configuration, boolean configurationDeleted ) + { + this.m_configuration = configuration; + } + } +}
Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/ActivateMethodTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/ActivateMethodTest.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/ActivateMethodTest.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/ActivateMethodTest.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,422 @@ +/* + * 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.impl.helper; + + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import org.apache.felix.scr.impl.BundleComponentActivator; +import org.apache.felix.scr.impl.config.ComponentContainer; +import org.apache.felix.scr.impl.manager.SingleComponentManager; +import org.apache.felix.scr.impl.metadata.ComponentMetadata; +import org.apache.felix.scr.impl.metadata.DSVersion; +import org.apache.felix.scr.impl.metadata.instances.AcceptMethod; +import org.apache.felix.scr.impl.metadata.instances.BaseObject; +import org.apache.felix.scr.impl.metadata.instances.Level1Object; +import org.apache.felix.scr.impl.metadata.instances.Level3Object; +import org.apache.felix.scr.impl.metadata.instances2.Level2Object; +import org.easymock.EasyMock; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; + +import junit.framework.TestCase; + + +public class ActivateMethodTest extends TestCase +{ + + private static final Class ACCEPT_METHOD_CLASS = AcceptMethod.class; + + private ComponentContext m_ctx; + + BaseObject base = new BaseObject(); + + Level1Object level1 = new Level1Object(); + + Level2Object level2 = new Level2Object(); + + Level3Object level3 = new Level3Object(); + + protected void setUp() throws Exception + { + super.setUp(); + Bundle bundle = ( Bundle ) EasyMock.createNiceMock( Bundle.class ); + BundleContext context = ( BundleContext ) EasyMock.createNiceMock( BundleContext.class ); + EasyMock.expect( context.getBundle() ).andReturn( bundle ).anyTimes(); + + m_ctx = (ComponentContext) EasyMock.createNiceMock(ComponentContext.class); + EasyMock.expect( m_ctx.getProperties() ).andReturn( new Hashtable() ).anyTimes(); + EasyMock.expect( m_ctx.getBundleContext() ).andReturn( context ).anyTimes(); + EasyMock.replay( new Object[] + { m_ctx, context } ); + + } + + + public void test_private_no_arg() throws Exception + { + checkMethod( base, "activate_no_arg" ); + + // activate_no_arg is private to BaseObject and must not be + // accessible from extensions + ensureMethodNotFoundMethod( level1, "activate_no_arg" ); + ensureMethodNotFoundMethod( level2, "activate_no_arg" ); + ensureMethodNotFoundMethod( level3, "activate_no_arg" ); + } + + + public void test_protected_activate_comp() throws Exception + { + // activate_comp is protected in BaseObject and must be accessible + // in all instances + checkMethod( base, "activate_comp" ); + checkMethod( level1, "activate_comp" ); + checkMethod( level2, "activate_comp" ); + checkMethod( level3, "activate_comp" ); + } + + + public void test_private_activate_level1_bundle() throws Exception + { + // activate_level1_bundle is private in Level1Object and must be + // accessible in Level1Object only + ensureMethodNotFoundMethod( base, "activate_level1_bundle" ); + checkMethod( level1, "activate_level1_bundle" ); + ensureMethodNotFoundMethod( level2, "activate_level1_bundle" ); + ensureMethodNotFoundMethod( level3, "activate_level1_bundle" ); + } + + + public void test_protected_activate_level1_map() throws Exception + { + // activate_level1_map is protected in Level1Object and must be + // accessible in Level1Object and extensions but not in BaseObject + ensureMethodNotFoundMethod( base, "activate_level1_map" ); + checkMethod( level1, "activate_level1_map" ); + checkMethod( level2, "activate_level1_map" ); + checkMethod( level3, "activate_level1_map" ); + } + + + public void test_private_activate_comp_map() throws Exception + { + // private_activate_comp_map is private in Level2Object and must be + // accessible in Level2Object only + ensureMethodNotFoundMethod( base, "activate_comp_map" ); + ensureMethodNotFoundMethod( level1, "activate_comp_map" ); + checkMethod( level2, "activate_comp_map" ); + checkMethod( level3, "activate_comp_map" ); + } + + + public void test_public_activate_collision() throws Exception + { + // activate_collision is private in Level2Object and must be + // accessible in Level2Object only. + // also the method is available taking no arguments and a single + // map argument which takes precedence and which we expect + ensureMethodNotFoundMethod( base, "activate_collision" ); + ensureMethodNotFoundMethod( level1, "activate_collision" ); + checkMethod( level2, "activate_collision" ); + checkMethod( level3, "activate_collision" ); + } + + + public void test_package_activate_comp_bundle() throws Exception + { + // activate_comp_bundle is package private and thus visible in + // base and level1 but not in level 2 (different package) and + // level 3 (inheritance through different package) + + checkMethod( base, "activate_comp_bundle" ); + checkMethod( level1, "activate_comp_bundle" ); + ensureMethodNotFoundMethod( level2, "activate_comp_bundle" ); + ensureMethodNotFoundMethod( level3, "activate_comp_bundle" ); + } + + + public void test_getPackage() throws Exception + { + Class dpc = getClass().getClassLoader().loadClass( "DefaultPackageClass" ); + assertEquals( "", BaseMethod.getPackageName( dpc ) ); + + assertEquals( "org.apache.felix.scr.impl.metadata.instances", BaseMethod.getPackageName( base.getClass() ) ); + } + + + public void test_accept() throws Exception + { + // public visible unless returning non-void + assertMethod( true, "public_void", false, false ); + assertMethod( false, "public_string", false, false ); + + // protected visible unless returning non-void + assertMethod( true, "protected_void", false, false ); + assertMethod( false, "protected_string", false, false ); + + // private not visible + assertMethod( false, "private_void", false, false ); + assertMethod( false, "private_string", false, false ); + + // private visible unless returning non-void + assertMethod( true, "private_void", true, false ); + assertMethod( false, "private_string", true, false ); + assertMethod( true, "private_void", true, true ); + assertMethod( false, "private_string", true, true ); + + // private not visible, accept package is ignored + assertMethod( false, "private_void", false, true ); + assertMethod( false, "private_string", false, true ); + + // package not visible + assertMethod( false, "package_void", false, false ); + assertMethod( false, "package_string", false, false ); + + // package visible unless returning non-void + assertMethod( true, "package_void", false, true ); + assertMethod( false, "package_string", false, true ); + assertMethod( true, "package_void", true, true ); + assertMethod( false, "package_string", true, true ); + + // package not visible, accept private is ignored + assertMethod( false, "package_void", true, false ); + assertMethod( false, "package_string", true, false ); + } + + + public void test_suitable_method_selection() throws Exception + { + // this would be the protected BaseObject.activate_suitable + checkMethod( base, "activate_suitable" ); + checkMethod( level1, "activate_suitable" ); + + // this would be the private Level2Object.activate_suitable + checkMethod( level2, "activate_suitable" ); + + // this must fail to find a method, since Level2Object's activate_suitable + // is private and terminates the search for Level3Object + ensureMethodNotFoundMethod( level3, "activate_suitable" ); + } + + public void test_unsuitable_method_selection() throws Exception + { + //check that finding an unsuitable method does not prevent finding + // a lower precedence suitable method. + + checkMethod( level2, "activate_comp_unsuitable" ); + + checkMethod( level3, "activate_comp_unsuitable" ); + } + + public void test_precedence() throws Exception + { + //All tested methods are only in base. They differ in arguments and visibility. + //R4.2 compendium 112.5.8 + //private method, arg ComponentContext + checkMethod( base, "activate_precedence_1", "activate_precedence_1_comp" ); + //package method, arg BundleContext + checkMethod( level1, "activate_precedence_1", "activate_precedence_1_bundleContext" ); + //protected method, arg Map + checkMethod( level2, "activate_precedence_1", "activate_precedence_1_map" ); + + //private method, arg Map + checkMethod( base, "activate_precedence_2", "activate_precedence_2_map" ); + //package method, args ComponentContext and Map + checkMethod( level1, "activate_precedence_2", "activate_precedence_2_comp_bundleContext" ); + //protected method, no args + checkMethod( level2, "activate_precedence_2", "activate_precedence_2_empty" ); + } + + //---------- internal + + /** + * Checks whether a method with the given name can be found for the + * activate/deactivate method parameter list and whether the method returns + * its name when called. + * + * @param obj + * @param methodName + */ + private void checkMethod( BaseObject obj, String methodName ) + { + checkMethod( obj, methodName, methodName, DSVersion.DS11 ); + } + + /** + * Checks whether a method with the given name can be found for the + * activate/deactivate method parameter list and whether the method returns + * the expected description when called. + * + * @param obj + * @param methodName + * @param methodDesc + */ + private void checkMethod( BaseObject obj, String methodName, String methodDesc ) + { + checkMethod(obj, methodName, methodDesc, DSVersion.DS11); + } + + + /** + * Checks whether a method with the given name can be found for the + * activate/deactivate method parameter list and whether the method returns + * the expected description when called. + * + * @param obj + * @param methodName + * @param methodDesc + * @param version DSVersion tested + */ + private void checkMethod( BaseObject obj, String methodName, String methodDesc, DSVersion version ) + { + ComponentContainer<?> container = newContainer(); + SingleComponentManager<?> icm = new SingleComponentManager( container, new ComponentMethods() ); + ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), version, false, false ); + am.invoke( obj, new ActivatorParameter( m_ctx, -1 ), null, icm ); + Method m = am.getMethod(); + assertNotNull( m ); + assertEquals( methodName, m.getName() ); + assertEquals( methodDesc, obj.getCalledMethod() ); + } + + + private ComponentContainer newContainer() + { + final ComponentMetadata metadata = newMetadata(); + ComponentContainer container = new ComponentContainer() { + + public BundleComponentActivator getActivator() + { + return null; + } + + public ComponentMetadata getComponentMetadata() + { + return metadata; + } + + public void disposed(SingleComponentManager component) + { + } + + }; + return container; + } + + + private ComponentMetadata newMetadata() { + ComponentMetadata metadata = new ComponentMetadata( DSVersion.DS11 ); + metadata.setName("foo"); + metadata.setImplementationClassName(Object.class.getName()); + metadata.validate(null); + return metadata; + } + + + /** + * Ensures no method with the given name accepting any of the + * activate/deactive method parameters can be found. + * + * @param obj + * @param methodName + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + private void ensureMethodNotFoundMethod( BaseObject obj, String methodName ) + { + ensureMethodNotFoundMethod(obj, methodName, DSVersion.DS11); + } + + + /** + * Ensures no method with the given name accepting any of the + * activate/deactive method parameters can be found. + * + * @param obj + * @param methodName + * @param version DS version tested + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + private void ensureMethodNotFoundMethod( BaseObject obj, String methodName, DSVersion version ) + { + ComponentContainer container = newContainer(); + SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() ); + ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), version, false, false ); + am.invoke( obj, new ActivatorParameter( m_ctx, -1 ), null, icm ); + Method m = am.getMethod(); + assertNull( m ); + assertNull( obj.getCalledMethod() ); + } + + + private void assertMethod( boolean expected, String methodName, boolean acceptPrivate, boolean acceptPackage ) + throws NoSuchMethodException + { + Method method = ACCEPT_METHOD_CLASS.getDeclaredMethod( methodName, null ); + boolean accepted = BaseMethod.accept( method, acceptPrivate, acceptPackage, false ); + assertEquals( expected, accepted ); + } + + private static @interface Ann{} + private static class Sort + { + public void a(Ann ann) {}; + public void a(int c) {}; + public void a(Integer c) {}; + public void a(BundleContext c) {}; + public void a(Map m) {}; + public void a() {}; + public void a(ComponentContext cc) {}; + public void a(ComponentContext cc, BundleContext c) {}; + public void b() {}; + + } + public void testMethodSorting() throws Exception + { + ActivateMethod am = new ActivateMethod( "a", true, Sort.class, DSVersion.DS11, false, false ); + List<Method> ms = am.getSortedMethods(Sort.class); + assertEquals(8, ms.size()); + assertEquals(1, ms.get(0).getParameterTypes().length); + assertEquals(ComponentContext.class, ms.get(0).getParameterTypes()[0]); + assertEquals(1, ms.get(1).getParameterTypes().length); + assertEquals(BundleContext.class, ms.get(1).getParameterTypes()[0]); + assertEquals(1, ms.get(2).getParameterTypes().length); + assertEquals(Ann.class, ms.get(2).getParameterTypes()[0]); + assertEquals(1, ms.get(3).getParameterTypes().length); + assertEquals(Map.class, ms.get(3).getParameterTypes()[0]); + assertEquals(1, ms.get(4).getParameterTypes().length); + assertEquals(int.class, ms.get(4).getParameterTypes()[0]); + assertEquals(1, ms.get(5).getParameterTypes().length); + assertEquals(Integer.class, ms.get(5).getParameterTypes()[0]); + assertEquals(2, ms.get(6).getParameterTypes().length); + assertEquals(0, ms.get(7).getParameterTypes().length); + } + + public void test_13_annos() throws Exception + { + checkMethod(base, "activate_13_2_annotations", "activate_13_2_annotations", DSVersion.DS13 ); + } + +} Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/AnnotationTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/AnnotationTest.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/AnnotationTest.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/AnnotationTest.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,512 @@ +/* + * 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.impl.helper; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.easymock.EasyMock; +import org.osgi.framework.Bundle; + +import junit.framework.TestCase; + +public class AnnotationTest extends TestCase +{ + + public void testNameFixup() throws Exception + { + assertEquals("foo", Annotations.fixup("foo")); + assertEquals("foo", Annotations.fixup("$foo")); + assertEquals("foo", Annotations.fixup("foo$")); + assertEquals("$foo", Annotations.fixup("$$foo")); + assertEquals("foobar", Annotations.fixup("foo$bar")); + assertEquals("foo$bar", Annotations.fixup("foo$$bar")); + assertEquals("foo.", Annotations.fixup("foo_")); + assertEquals("foo_", Annotations.fixup("foo__")); + assertEquals(".foo", Annotations.fixup("_foo")); + assertEquals("_foo", Annotations.fixup("__foo")); + assertEquals("foo.bar", Annotations.fixup("foo_bar")); + assertEquals("foo_bar", Annotations.fixup("foo__bar")); + assertEquals("foo$", Annotations.fixup("foo$$$")); + assertEquals("foo_.", Annotations.fixup("foo___")); + assertEquals("foo..bar", Annotations.fixup("foo$_$_bar")); + } + + public enum E1 {a, b, c} + public @interface A1 { + boolean bool(); + byte byt(); + Class<?> clas(); + E1 e1(); + double doubl(); + float floa(); + int integer(); + long lon(); + short shor(); + String string(); + } + + private Bundle mockBundle() throws ClassNotFoundException + { + Bundle b = EasyMock.createMock(Bundle.class); + EasyMock.expect(b.loadClass(String.class.getName())).andReturn((Class) String.class).anyTimes(); + EasyMock.expect(b.loadClass(Integer.class.getName())).andReturn((Class) Integer.class).anyTimes(); + EasyMock.replay(b); + return b; + } + + public void testA1() throws Exception + { + Map<String, Object> values = allValues(); + + Object o = Annotations.toObject( A1.class, values, mockBundle(), false); + assertTrue("expected an A1", o instanceof A1); + + A1 a = (A1) o; + checkA1(a); + } + + private void checkA1(A1 a) + { + assertEquals(true, a.bool()); + assertEquals((byte)12, a.byt()); + assertEquals(String.class, a.clas()); + assertEquals(E1.a, a.e1()); + assertEquals(3.14d, a.doubl()); + assertEquals(500f, a.floa()); + assertEquals(3, a.integer()); + assertEquals(12345678l, a.lon()); + assertEquals((short)3, a.shor()); + assertEquals("3", a.string()); + } + + public void testA1FromArray() throws Exception + { + Map<String, Object> values = arrayValues(); + + Object o = Annotations.toObject( A1.class, values, mockBundle(), false); + assertTrue("expected an A1", o instanceof A1); + + A1 a = (A1) o; + assertEquals(true, a.bool()); + assertEquals((byte)12, a.byt()); + assertEquals(String.class, a.clas()); + assertEquals(E1.a, a.e1()); + assertEquals(3.14d, a.doubl()); + assertEquals(500f, a.floa()); + assertEquals(3, a.integer()); + assertEquals(12345678l, a.lon()); + assertEquals((short)3, a.shor()); + assertEquals(null, a.string()); + } + + private Map<String, Object> allValues() + { + Map<String, Object> values = new HashMap(); + 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; + } + + public void testA1NoValues() throws Exception + { + Map<String, Object> values = new HashMap<String, Object>(); + + Object o = Annotations.toObject( A1.class, values, mockBundle(), false); + assertTrue("expected an A1", o instanceof A1); + + A1 a = (A1) o; + assertEquals(false, a.bool()); + assertEquals((byte)0, a.byt()); + assertEquals(null, a.clas()); + assertEquals(null, a.e1()); + assertEquals(0d, a.doubl()); + assertEquals(0f, a.floa()); + assertEquals(0, a.integer()); + assertEquals(0l, a.lon()); + assertEquals((short)0, a.shor()); + assertEquals(null, a.string()); + } + + public @interface A2 { + boolean bool() default true; + byte byt() default 5; + Class<?> clas() default Integer.class; + E1 e1() default E1.b; + double doubl() default -2; + float floa() default -4; + int integer() default -5; + long lon() default Long.MIN_VALUE; + short shor() default -8; + String string() default "default"; + } + + public void testA2AllValues() throws Exception + { + Map<String, Object> values = allValues(); + + Object o = Annotations.toObject( A2.class, values, mockBundle(), false); + assertTrue("expected an A2", o instanceof A2); + + A2 a = (A2) o; + assertEquals(true, a.bool()); + assertEquals((byte)12, a.byt()); + assertEquals(String.class, a.clas()); + assertEquals(E1.a, a.e1()); + assertEquals(3.14d, a.doubl()); + assertEquals(500f, a.floa()); + assertEquals(3, a.integer()); + assertEquals(12345678l, a.lon()); + assertEquals((short)3, a.shor()); + assertEquals("3", a.string()); + } + + public @interface A1Arrays { + boolean[] bool(); + byte[] byt(); + Class<?>[] clas(); + E1[] e1(); + double[] doubl(); + float[] floa(); + int[] integer(); + long[] lon(); + short[] shor(); + String[] string(); + } + + public void testA1ArraysNoValues() throws Exception + { + Map<String, Object> values = new HashMap<String, Object>(); + + Object o = Annotations.toObject( A1Arrays.class, values, mockBundle(), false); + assertTrue("expected an A1Arrays", o instanceof A1Arrays); + + A1Arrays a = (A1Arrays) o; + assertEquals(null, a.bool()); + assertEquals(null, a.byt()); + assertEquals(null, a.clas()); + assertEquals(null, a.e1()); + assertEquals(null, a.doubl()); + assertEquals(null, a.floa()); + assertEquals(null, a.integer()); + assertEquals(null, a.lon()); + assertEquals(null, a.shor()); + assertEquals(null, a.string()); + } + + public void testA1Array() throws Exception + { + Map<String, Object> values = allValues(); + + Object o = Annotations.toObject( A1Arrays.class, values, mockBundle(), false); + assertTrue("expected an A1Arrays", o instanceof A1Arrays); + + A1Arrays a = (A1Arrays) o; + 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 assertArrayEquals(Object a, Object b) + { + assertTrue(a.getClass().isArray()); + assertTrue(b.getClass().isArray()); + assertEquals("wrong length", Array.getLength(a), Array.getLength(b)); + assertEquals("wrong type", a.getClass().getComponentType(), b.getClass().getComponentType()); + for (int i = 0; i < Array.getLength(a); i++) + { + assertEquals("different value at " + i, Array.get(a, i), Array.get(b, i)); + } + + } + + private Map<String, Object> arrayValues() + { + Map<String, Object> values = new HashMap(); + 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; + } + + public void testA1ArrayFromArray() throws Exception + { + Map<String, Object> values = arrayValues(); + + doA1ArrayTest(values); + } + + public void testA1ArrayFromCollection() throws Exception + { + Map<String, Object> values = arrayValues(); + Map<String, Object> collectionValues = new HashMap<String, Object>(); + for (Map.Entry<String, Object> entry: values.entrySet()) + { + collectionValues.put(entry.getKey(), toList(entry.getValue())); + } + + doA1ArrayTest(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 doA1ArrayTest(Map<String, Object> values) throws ClassNotFoundException + { + Object o = Annotations.toObject( A1Arrays.class, values, mockBundle(), false); + assertTrue("expected an A1Arrays", o instanceof A1Arrays); + + A1Arrays a = (A1Arrays) o; + 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()); + assertArrayEquals(new String[] {}, a.string()); + } + + public @interface B1 { + boolean bool(); + byte byt(); + Class<?> clas(); + E1 e1(); + double doubl(); + float floa(); + int integer(); + long lon(); + short shor(); + String string(); + A1 a1(); + A1[] a1array(); + } + + public void testB1() throws Exception + { + Map<String, Object> values = b1Values(); + + Object o = Annotations.toObject( B1.class, values, mockBundle(), true); + assertTrue("expected an B1 " + o, o instanceof B1); + B1 b = (B1) o; + checkB1(b); + } + + private void checkB1(B1 b) + { + checkA1(b.a1()); + assertEquals(3, b.a1array().length); + checkA1(b.a1array()[0]); + checkA1(b.a1array()[1]); + checkA1(b.a1array()[2]); + } + + private Map<String, Object> b1Values() + { + Map<String, Object> a1Values = allValues(); + Map<String, Object> values = allValues(); + nest(values, "a1", 0, a1Values); + nest(values, "a1array", 0, a1Values); + nest(values, "a1array", 1, a1Values); + nest(values, "a1array", 2, a1Values); + return values; + } + + private void nest(Map<String, Object> values, String key, int i, + Map<String, Object> a1Values) + { + for (Map.Entry<String, Object> entry: a1Values.entrySet()) + { + values.put(key + "." + i + "." + entry.getKey(), entry.getValue()); + } + } + + public @interface C1 { + boolean bool(); + byte byt(); + Class<?> clas(); + E1 e1(); + double doubl(); + float floa(); + int integer(); + long lon(); + short shor(); + String string(); + B1 b1(); + B1[] b1array(); + } + + public void testC1() throws Exception + { + Map<String, Object> values = c1Values(); + + Object o = Annotations.toObject( C1.class, values, mockBundle(), true); + assertTrue("expected an B1 " + o, o instanceof C1); + C1 c = (C1) o; + checkB1(c.b1()); + assertEquals(3, c.b1array().length); + checkB1(c.b1array()[0]); + checkB1(c.b1array()[1]); + checkB1(c.b1array()[2]); + + } + + private Map<String, Object> c1Values() + { + Map<String, Object> b1Values = b1Values(); + Map<String, Object> values = allValues(); + nest(values, "b1", 0, b1Values); + nest(values, "b1array", 0, b1Values); + nest(values, "b1array", 1, b1Values); + nest(values, "b1array", 2, b1Values); + return values; + } + + public interface I0 { + boolean bool(); + byte byt(); + Class<?> clas(); + E1 e1(); + } + public interface AI1 extends I0 { + double doubl(); + float floa(); + int integer(); + long lon(); + short shor(); + String string(); + } + + public interface BI1 extends I0 { + double doubl(); + float floa(); + int integer(); + long lon(); + short shor(); + String string(); + AI1 a1(); + AI1[] a1array(); + } + + public interface CI1 extends I0 { + double doubl(); + float floa(); + int integer(); + long lon(); + short shor(); + String string(); + BI1 b1(); + BI1[] b1array(); + } + + public void testAI1() throws Exception + { + Map<String, Object> values = allValues(); + + Object o = Annotations.toObject( AI1.class, values, mockBundle(), true); + assertTrue("expected an AI1", o instanceof AI1); + + AI1 a = (AI1) o; + checkAI1(a); + } + + private void checkAI1(AI1 a) + { + assertEquals(true, a.bool()); + assertEquals((byte)12, a.byt()); + assertEquals(String.class, a.clas()); + assertEquals(E1.a, a.e1()); + assertEquals(3.14d, a.doubl()); + assertEquals(500f, a.floa()); + assertEquals(3, a.integer()); + assertEquals(12345678l, a.lon()); + assertEquals((short)3, a.shor()); + assertEquals("3", a.string()); + } + + public void testBI1() throws Exception + { + Map<String, Object> values = b1Values(); + + Object o = Annotations.toObject( BI1.class, values, mockBundle(), true); + assertTrue("expected an B1 " + o, o instanceof BI1); + BI1 b = (BI1) o; + checkBI1(b); + } + + private void checkBI1(BI1 b) + { + checkAI1(b.a1()); + assertEquals(3, b.a1array().length); + checkAI1(b.a1array()[0]); + checkAI1(b.a1array()[1]); + checkAI1(b.a1array()[2]); + } + + public void testCI1() throws Exception + { + Map<String, Object> values = c1Values(); + + Object o = Annotations.toObject( CI1.class, values, mockBundle(), true); + assertTrue("expected an B1 " + o, o instanceof CI1); + CI1 c = (CI1) o; + checkBI1(c.b1()); + assertEquals(3, c.b1array().length); + checkBI1(c.b1array()[0]); + checkBI1(c.b1array()[1]); + checkBI1(c.b1array()[2]); + + } + +} Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/BindMethodTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/BindMethodTest.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/BindMethodTest.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/helper/BindMethodTest.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,493 @@ +/* + * 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.impl.helper; + + +import junit.framework.TestCase; + +import org.apache.felix.scr.impl.BundleComponentActivator; +import org.apache.felix.scr.impl.MockBundle; +import org.apache.felix.scr.impl.config.ComponentContainer; +import org.apache.felix.scr.impl.manager.ComponentContextImpl; +import org.apache.felix.scr.impl.manager.RefPair; +import org.apache.felix.scr.impl.manager.SingleComponentManager; +import org.apache.felix.scr.impl.manager.SingleRefPair; +import org.apache.felix.scr.impl.manager.components.FakeService; +import org.apache.felix.scr.impl.manager.components.T1; +import org.apache.felix.scr.impl.manager.components.T1MapSR; +import org.apache.felix.scr.impl.manager.components.T1a; +import org.apache.felix.scr.impl.manager.components.T3; +import org.apache.felix.scr.impl.manager.components2.T2; +import org.apache.felix.scr.impl.metadata.ComponentMetadata; +import org.apache.felix.scr.impl.metadata.DSVersion; +import org.apache.felix.scr.impl.metadata.ReferenceMetadata; +import org.easymock.EasyMock; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceReference; + + +public class BindMethodTest extends TestCase +{ + + private ServiceReference m_serviceReference; + private FakeService m_serviceInstance; + private BundleContext m_context; + + + @Override + public void setUp() + { + m_serviceReference = EasyMock.createNiceMock( ServiceReference.class ); + m_serviceInstance = EasyMock.createNiceMock( FakeService.class ); + m_context = EasyMock.createNiceMock( BundleContext.class ); + + EasyMock.expect( m_context.getService( m_serviceReference ) ).andReturn( m_serviceInstance ) + .anyTimes(); + + EasyMock.expect( m_serviceReference.getPropertyKeys() ).andReturn( new String[] + { Constants.SERVICE_ID } ).anyTimes(); + EasyMock.expect( m_serviceReference.getProperty( Constants.SERVICE_ID ) ).andReturn( "Fake Service" ) + .anyTimes(); + EasyMock.replay( new Object[] + { m_serviceReference, m_context } ); + } + + + public void test_Unexistent() + { + testMethod( "unexistent", new T1(), DSVersion.DS10, null ); + testMethod( "unexistent", new T1(), DSVersion.DS11, null ); + testMethod( "unexistent", new T2(), DSVersion.DS10, null ); + testMethod( "unexistent", new T2(), DSVersion.DS11, null ); + testMethod( "unexistent", new T3(), DSVersion.DS10, null ); + testMethod( "unexistent", new T3(), DSVersion.DS11, null ); + } + + + public void test_privateT1() + { + testMethod( "privateT1", new T1(), DSVersion.DS10, null ); + testMethod( "privateT1", new T1(), DSVersion.DS11, null ); + testMethod( "privateT1", new T2(), DSVersion.DS10, null ); + testMethod( "privateT1", new T2(), DSVersion.DS11, null ); + testMethod( "privateT1", new T3(), DSVersion.DS10, null ); + testMethod( "privateT1", new T3(), DSVersion.DS11, null ); + } + + + public void test_privateT1SR() + { + testMethod( "privateT1SR", new T1(), DSVersion.DS10, null ); + testMethod( "privateT1SR", new T1(), DSVersion.DS11, "privateT1SR" ); + testMethod( "privateT1SR", new T2(), DSVersion.DS10, null ); + testMethod( "privateT1SR", new T2(), DSVersion.DS11, null ); + } + + + public void test_privateT1SI() + { + testMethod( "privateT1SI", new T1(), DSVersion.DS10, null ); + testMethod( "privateT1SI", new T1(), DSVersion.DS11, "privateT1SI" ); + testMethod( "privateT1SI", new T2(), DSVersion.DS10, null ); + testMethod( "privateT1SI", new T2(), DSVersion.DS11, null ); + } + + + public void test_privateT1SIMap() + { + testMethod( "privateT1SIMap", new T1(), DSVersion.DS10, null ); + testMethod( "privateT1SIMap", new T1(), DSVersion.DS11, "privateT1SIMap" ); + testMethod( "privateT1SIMap", new T2(), DSVersion.DS10, null ); + testMethod( "privateT1SIMap", new T2(), DSVersion.DS11, null ); + } + + + public void test_privateT1SSI() + { + testMethod( "privateT1SSI", new T1(), DSVersion.DS10, null ); + testMethod( "privateT1SSI", new T1(), DSVersion.DS11, "privateT1SSI" ); + testMethod( "privateT1SSI", new T2(), DSVersion.DS10, null ); + testMethod( "privateT1SSI", new T2(), DSVersion.DS11, null ); + } + + + public void test_privateT1SSIMap() + { + testMethod( "privateT1SSIMap", new T1(), DSVersion.DS10, null ); + testMethod( "privateT1SSIMap", new T1(), DSVersion.DS11, "privateT1SSIMap" ); + testMethod( "privateT1SSIMap", new T2(), DSVersion.DS10, null ); + testMethod( "privateT1SSIMap", new T2(), DSVersion.DS11, null ); + } + + + public void test_privateT2() + { + testMethod( "privateT2", new T1(), DSVersion.DS10, null ); + testMethod( "privateT2", new T1(), DSVersion.DS11, null ); + testMethod( "privateT2", new T2(), DSVersion.DS10, null ); + testMethod( "privateT2", new T2(), DSVersion.DS11, null ); + } + + + public void test_privateT2SR() + { + testMethod( "privateT2SR", new T1(), DSVersion.DS10, null ); + testMethod( "privateT2SR", new T1(), DSVersion.DS11, null ); + testMethod( "privateT2SR", new T2(), DSVersion.DS10, null ); + testMethod( "privateT2SR", new T2(), DSVersion.DS11, "privateT2SR" ); + } + + + public void test_privateT2SI() + { + testMethod( "privateT2SI", new T1(), DSVersion.DS10, null ); + testMethod( "privateT2SI", new T1(), DSVersion.DS11, null ); + testMethod( "privateT2SI", new T2(), DSVersion.DS10, null ); + testMethod( "privateT2SI", new T2(), DSVersion.DS11, "privateT2SI" ); + } + + + public void test_privateT2SIMap() + { + testMethod( "privateT2SIMap", new T1(), DSVersion.DS10, null ); + testMethod( "privateT2SIMap", new T1(), DSVersion.DS11, null ); + testMethod( "privateT2SIMap", new T2(), DSVersion.DS10, null ); + testMethod( "privateT2SIMap", new T2(), DSVersion.DS11, "privateT2SIMap" ); + } + + + public void test_privateT2SSI() + { + testMethod( "privateT2SSI", new T1(), DSVersion.DS10, null ); + testMethod( "privateT2SSI", new T1(), DSVersion.DS11, null ); + testMethod( "privateT2SSI", new T2(), DSVersion.DS10, null ); + testMethod( "privateT2SSI", new T2(), DSVersion.DS11, "privateT2SSI" ); + } + + + public void test_privateT2SSIMap() + { + testMethod( "privateT2SSIMap", new T1(), DSVersion.DS10, null ); + testMethod( "privateT2SSIMap", new T1(), DSVersion.DS11, null ); + testMethod( "privateT2SSIMap", new T2(), DSVersion.DS10, null ); + testMethod( "privateT2SSIMap", new T2(), DSVersion.DS11, "privateT2SSIMap" ); + } + + + public void test_packageT1() + { + testMethod( "packageT1", new T1(), DSVersion.DS10, null ); + testMethod( "packageT1", new T1(), DSVersion.DS11, null ); + testMethod( "packageT1", new T2(), DSVersion.DS10, null ); + testMethod( "packageT1", new T2(), DSVersion.DS11, null ); + testMethod( "packageT1", new T3(), DSVersion.DS10, null ); + testMethod( "packageT1", new T3(), DSVersion.DS11, null ); + testMethod( "packageT1", new T1a(), DSVersion.DS10, null ); + testMethod( "packageT1", new T1a(), DSVersion.DS11, null ); + } + + + public void test_packageT1SR() + { + testMethod( "packageT1SR", new T1(), DSVersion.DS10, null ); + testMethod( "packageT1SR", new T1(), DSVersion.DS11, "packageT1SR" ); + testMethod( "packageT1SR", new T2(), DSVersion.DS10, null ); + testMethod( "packageT1SR", new T2(), DSVersion.DS11, null ); + testMethod( "packageT1SR", new T3(), DSVersion.DS10, null ); + testMethod( "packageT1SR", new T3(), DSVersion.DS11, null ); + testMethod( "packageT1SR", new T1a(), DSVersion.DS10, null ); + testMethod( "packageT1SR", new T1a(), DSVersion.DS11, "packageT1SR" ); + } + + + public void test_packageT1SI() + { + testMethod( "packageT1SI", new T1(), DSVersion.DS10, null ); + testMethod( "packageT1SI", new T1(), DSVersion.DS11, "packageT1SI" ); + testMethod( "packageT1SI", new T2(), DSVersion.DS10, null ); + testMethod( "packageT1SI", new T2(), DSVersion.DS11, null ); + testMethod( "packageT1SI", new T3(), DSVersion.DS10, null ); + testMethod( "packageT1SI", new T3(), DSVersion.DS11, null ); + testMethod( "packageT1SI", new T1a(), DSVersion.DS10, null ); + testMethod( "packageT1SI", new T1a(), DSVersion.DS11, "packageT1SI" ); + } + + + public void test_packageT1SIMap() + { + testMethod( "packageT1SIMap", new T1(), DSVersion.DS10, null ); + testMethod( "packageT1SIMap", new T1(), DSVersion.DS11, "packageT1SIMap" ); + testMethod( "packageT1SIMap", new T2(), DSVersion.DS10, null ); + testMethod( "packageT1SIMap", new T2(), DSVersion.DS11, null ); + testMethod( "packageT1SIMap", new T3(), DSVersion.DS10, null ); + testMethod( "packageT1SIMap", new T3(), DSVersion.DS11, null ); + testMethod( "packageT1SIMap", new T1a(), DSVersion.DS10, null ); + testMethod( "packageT1SIMap", new T1a(), DSVersion.DS11, "packageT1SIMap" ); + } + + + public void test_packageT1SSI() + { + testMethod( "packageT1SSI", new T1(), DSVersion.DS10, null ); + testMethod( "packageT1SSI", new T1(), DSVersion.DS11, "packageT1SSI" ); + testMethod( "packageT1SSI", new T2(), DSVersion.DS10, null ); + testMethod( "packageT1SSI", new T2(), DSVersion.DS11, null ); + testMethod( "packageT1SSI", new T3(), DSVersion.DS10, null ); + testMethod( "packageT1SSI", new T3(), DSVersion.DS11, null ); + testMethod( "packageT1SSI", new T1a(), DSVersion.DS10, null ); + testMethod( "packageT1SSI", new T1a(), DSVersion.DS11, "packageT1SSI" ); + } + + + public void test_packageT1SSIMap() + { + testMethod( "packageT1SSIMap", new T1(), DSVersion.DS10, null ); + testMethod( "packageT1SSIMap", new T1(), DSVersion.DS11, "packageT1SSIMap" ); + testMethod( "packageT1SSIMap", new T2(), DSVersion.DS10, null ); + testMethod( "packageT1SSIMap", new T2(), DSVersion.DS11, null ); + testMethod( "packageT1SSIMap", new T3(), DSVersion.DS10, null ); + testMethod( "packageT1SSIMap", new T3(), DSVersion.DS11, null ); + testMethod( "packageT1SSIMap", new T1a(), DSVersion.DS10, null ); + testMethod( "packageT1SSIMap", new T1a(), DSVersion.DS11, "packageT1SSIMap" ); + } + + + public void test_packageT2() + { + testMethod( "packageT2", new T1(), DSVersion.DS10, null ); + testMethod( "packageT2", new T1(), DSVersion.DS11, null ); + testMethod( "packageT2", new T2(), DSVersion.DS10, null ); + testMethod( "packageT2", new T2(), DSVersion.DS11, null ); + } + + + public void test_packageT2SR() + { + testMethod( "packageT2SR", new T1(), DSVersion.DS10, null ); + testMethod( "packageT2SR", new T1(), DSVersion.DS11, null ); + testMethod( "packageT2SR", new T2(), DSVersion.DS10, null ); + testMethod( "packageT2SR", new T2(), DSVersion.DS11, "packageT2SR" ); + } + + + public void test_packageT2SI() + { + testMethod( "packageT2SI", new T1(), DSVersion.DS10, null ); + testMethod( "packageT2SI", new T1(), DSVersion.DS11, null ); + testMethod( "packageT2SI", new T2(), DSVersion.DS10, null ); + testMethod( "packageT2SI", new T2(), DSVersion.DS11, "packageT2SI" ); + } + + + public void test_packageT2SIMap() + { + testMethod( "packageT2SIMap", new T1(), DSVersion.DS10, null ); + testMethod( "packageT2SIMap", new T1(), DSVersion.DS11, null ); + testMethod( "packageT2SIMap", new T2(), DSVersion.DS10, null ); + testMethod( "packageT2SIMap", new T2(), DSVersion.DS11, "packageT2SIMap" ); + } + + + public void test_packageT2SSI() + { + testMethod( "packageT2SSI", new T1(), DSVersion.DS10, null ); + testMethod( "packageT2SSI", new T1(), DSVersion.DS11, null ); + testMethod( "packageT2SSI", new T2(), DSVersion.DS10, null ); + testMethod( "packageT2SSI", new T2(), DSVersion.DS11, "packageT2SSI" ); + } + + + public void test_packageT2SSIMap() + { + testMethod( "packageT2SSIMap", new T1(), DSVersion.DS10, null ); + testMethod( "packageT2SSIMap", new T1(), DSVersion.DS11, null ); + testMethod( "packageT2SSIMap", new T2(), DSVersion.DS10, null ); + testMethod( "packageT2SSIMap", new T2(), DSVersion.DS11, "packageT2SSIMap" ); + } + + + public void test_protectedT1() + { + testMethod( "protectedT1", new T1(), DSVersion.DS10, null ); + testMethod( "protectedT1", new T1(), DSVersion.DS11, null ); + testMethod( "protectedT1", new T2(), DSVersion.DS10, null ); + testMethod( "protectedT1", new T2(), DSVersion.DS11, null ); + } + + + public void test_protectedT1SR() + { + testMethod( "protectedT1SR", new T1(), DSVersion.DS10, "protectedT1SR" ); + testMethod( "protectedT1SR", new T1(), DSVersion.DS11, "protectedT1SR" ); + testMethod( "protectedT1SR", new T2(), DSVersion.DS10, "protectedT1SR" ); + testMethod( "protectedT1SR", new T2(), DSVersion.DS11, "protectedT1SR" ); + } + + + public void test_protectedT1SI() + { + testMethod( "protectedT1SI", new T1(), DSVersion.DS10, "protectedT1SI" ); + testMethod( "protectedT1SI", new T1(), DSVersion.DS11, "protectedT1SI" ); + testMethod( "protectedT1SI", new T2(), DSVersion.DS10, "protectedT1SI" ); + testMethod( "protectedT1SI", new T2(), DSVersion.DS11, "protectedT1SI" ); + } + + + public void test_protectedT1SSI() + { + testMethod( "protectedT1SSI", new T1(), DSVersion.DS10, "protectedT1SSI" ); + testMethod( "protectedT1SSI", new T1(), DSVersion.DS11, "protectedT1SSI" ); + testMethod( "protectedT1SSI", new T2(), DSVersion.DS10, "protectedT1SSI" ); + testMethod( "protectedT1SSI", new T2(), DSVersion.DS11, "protectedT1SSI" ); + } + + + public void test_publicT1() + { + testMethod( "publicT1", new T1(), DSVersion.DS10, null ); + testMethod( "publicT1", new T1(), DSVersion.DS11, null ); + testMethod( "publicT1", new T2(), DSVersion.DS10, null ); + testMethod( "publicT1", new T2(), DSVersion.DS11, null ); + } + + + public void test_publicT1SR() + { + testMethod( "publicT1SR", new T1(), DSVersion.DS10, "publicT1SR" ); + testMethod( "publicT1SR", new T1(), DSVersion.DS11, "publicT1SR" ); + testMethod( "publicT1SR", new T2(), DSVersion.DS10, "publicT1SR" ); + testMethod( "publicT1SR", new T2(), DSVersion.DS11, "publicT1SR" ); + } + + + public void test_publicT1SI() + { + testMethod( "publicT1SI", new T1(), DSVersion.DS10, "publicT1SI" ); + testMethod( "publicT1SI", new T1(), DSVersion.DS11, "publicT1SI" ); + testMethod( "publicT1SI", new T2(), DSVersion.DS10, "publicT1SI" ); + testMethod( "publicT1SI", new T2(), DSVersion.DS11, "publicT1SI" ); + } + + + public void test_publicT1SIMap() + { + testMethod( "publicT1SIMap", new T1(), DSVersion.DS10, null ); + testMethod( "publicT1SIMap", new T1(), DSVersion.DS11, "publicT1SIMap" ); + testMethod( "publicT1SIMap", new T2(), DSVersion.DS10, null ); + testMethod( "publicT1SIMap", new T2(), DSVersion.DS11, "publicT1SIMap" ); + } + + + public void test_publicT1SSI() + { + testMethod( "publicT1SSI", new T1(), DSVersion.DS10, "publicT1SSI" ); + testMethod( "publicT1SSI", new T1(), DSVersion.DS11, "publicT1SSI" ); + testMethod( "publicT1SSI", new T2(), DSVersion.DS10, "publicT1SSI" ); + testMethod( "publicT1SSI", new T2(), DSVersion.DS11, "publicT1SSI" ); + } + + + public void test_publicT1SSIMap() + { + testMethod( "publicT1SSIMap", new T1(), DSVersion.DS10, null ); + testMethod( "publicT1SSIMap", new T1(), DSVersion.DS11, "publicT1SSIMap" ); + testMethod( "publicT1SSIMap", new T2(), DSVersion.DS10, null ); + testMethod( "publicT1SSIMap", new T2(), DSVersion.DS11, "publicT1SSIMap" ); + } + + + public void test_suitable() + { + // T1 should use its own public implementation + testMethod( "suitable", new T1(), DSVersion.DS10, "suitableT1" ); + testMethod( "suitable", new T1(), DSVersion.DS11, "suitableT1" ); + + // T2's private implementation is only visible for DS 1.1 + testMethod( "suitable", new T2(), DSVersion.DS10, null ); + testMethod( "suitable", new T2(), DSVersion.DS11, "suitableT2" ); + + // T3 extends T2 and cannot see T2's private method + testMethod( "suitable", new T3(), DSVersion.DS10, null ); + testMethod( "suitable", new T3(), DSVersion.DS11, null ); + + // T1a extends T1 and uses T1's public method + testMethod( "suitable", new T1a(), DSVersion.DS10, "suitableT1" ); + testMethod( "suitable", new T1a(), DSVersion.DS11, "suitableT1" ); + } + + public void test_13() + { + //single map param + testMethod( "packageT1Map", new T1(), DSVersion.DS12, null); + testMethod( "packageT1Map", new T1(), DSVersion.DS13, "packageT1Map"); + + //map, sr + testMethod( "packageT1MapSR", new T1MapSR(), DSVersion.DS12, null); + testMethod( "packageT1MapSR", new T1MapSR(), DSVersion.DS13, "packageT1MapSR"); + } + + + private void testMethod( final String methodName, final T1 component, final DSVersion dsVersion, + final String expectCallPerformed ) + { + ComponentContainer container = newContainer(); + SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() ); + BindMethod bm = new BindMethod( methodName, component.getClass(), + FakeService.class.getName(), dsVersion, false, ReferenceMetadata.ReferenceScope.bundle ); + RefPair refPair = new SingleRefPair( m_serviceReference ); + ComponentContextImpl<T1> cc = new ComponentContextImpl(icm, new MockBundle()); + assertTrue( bm.getServiceObject( cc, refPair, m_context, icm ) ); + BindParameters bp = new BindParameters(cc, refPair); + bm.invoke( component, bp, null, icm ); + assertEquals( expectCallPerformed, component.callPerformed ); + } + + private ComponentContainer newContainer() + { + final ComponentMetadata metadata = newMetadata(); + ComponentContainer container = new ComponentContainer() { + + public BundleComponentActivator getActivator() + { + return null; + } + + public ComponentMetadata getComponentMetadata() + { + return metadata; + } + + public void disposed(SingleComponentManager component) + { + } + + }; + return container; + } + + private ComponentMetadata newMetadata() { + ComponentMetadata metadata = new ComponentMetadata( DSVersion.DS11 ); + metadata.setName("foo"); + metadata.setImplementationClassName(Object.class.getName()); + metadata.validate(null); + return metadata; + } + +} Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/AbstractComponentManagerTest.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,56 @@ +/* + * 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.impl.manager; + +import java.util.Hashtable; +import java.util.Map; + +import junit.framework.TestCase; + +public class AbstractComponentManagerTest extends TestCase +{ + + public void test_copyTo_withoutExclusions() + { + final Hashtable<String, String> ht = new Hashtable<String, String>(); + ht.put( "p1", "v1" ); + ht.put( "p.2", "v2" ); + ht.put( ".p3", "v3" ); + final Map<String, Object> dict = AbstractComponentManager.copyToMap( ht, true ); + assertNotNull( "Copy result is not null", dict ); + assertEquals( "Number of items", 3, dict.size() ); + assertEquals( "Value for key p1", "v1", dict.get( "p1" ) ); + assertEquals( "Value for key p.2", "v2", dict.get( "p.2" ) ); + assertEquals( "Value for key .p3", "v3", dict.get( ".p3" ) ); + } + + public void test_copyTo_excludingStartingWithDot() + { + final Hashtable<String, String> ht = new Hashtable<String, String>(); + ht.put( "p1", "v1" ); + ht.put( "p.2", "v2" ); + ht.put( ".p3", "v3" ); + final Map<String, Object> dict = AbstractComponentManager.copyToMap( ht, false ); + assertNotNull( "Copy result is not null", dict ); + assertEquals( "Number of items", 2, dict.size() ); + assertEquals( "Value for key p1", "v1", dict.get( "p1" ) ); + assertEquals( "Value for key p.2", "v2", dict.get( "p.2" ) ); + } + +} Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/RegistrationManagerTest.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/RegistrationManagerTest.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/RegistrationManagerTest.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/RegistrationManagerTest.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,145 @@ +/* + * 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.impl.manager; + +import static org.junit.Assert.fail; + +import java.util.ArrayList; +import java.util.concurrent.CountDownLatch; + +import org.apache.felix.scr.impl.manager.RegistrationManager.RegState; +import org.junit.Test; + + +public class RegistrationManagerTest +{ + + private volatile boolean fail; + + private int n = 10; + private ArrayList<Thread> threads = new ArrayList<Thread>(); + + private TRM trm = new TRM(); + + @Test + public void testRegistrationManager( ) throws Exception + { + + for (int setup = 0; setup < 1 << n; setup++ ) + { + runTest(setup); + if (fail) + { + fail("failed at " + setup); + } + } + } + + private void runTest(int setup) throws InterruptedException + { + final CountDownLatch done = new CountDownLatch( n ); + for (int i = 0; i < n; i++) + { + boolean b = ((setup >>> i) & 1) == 0; + final RegState change = b? RegState.registered: RegState.unregistered; + new Thread(new Runnable() { + + public void run() + { + trm.changeRegistration( change, null ); + } + + }).start(); + done.countDown(); + } + done.await(); + } + + + private class TRM extends RegistrationManager<Object> + { + + @Override + Object register(String[] services) + { + try + { + Thread.sleep( 1 ); + } + catch ( InterruptedException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return new Object(); + } + + @Override + void unregister(Object serviceRegistration) + { + try + { + Thread.sleep( 1 ); + } + catch ( InterruptedException e ) + { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Override + void log(int level, String message, Object[] arguments, Throwable ex) + { + if ( arguments.length == 1 && (arguments[0] instanceof ArrayList)) + { + ArrayList<RegState> opqueue = ( ArrayList<org.apache.felix.scr.impl.manager.RegistrationManager.RegState> ) arguments[0]; +// System.out.println("opqueue: " + opqueue); + if (opqueue.size() > 1) + { + for (int i = 1; i < opqueue.size(); i++) + { + if (opqueue.get( i -1 ) == opqueue.get(i)) + { + fail = true; + System.out.println("opqueue: " + opqueue); + return; + } + } + } + } + + } + + @Override + long getTimeout() + { + // TODO Auto-generated method stub + return 10; + } + + @Override + void reportTimeout() + { + // TODO Auto-generated method stub + + } + + } +} Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/FakeService.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/FakeService.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/FakeService.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/FakeService.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.scr.impl.manager.components; + + +public interface FakeService extends SuperFakeService +{ + +} \ No newline at end of file Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/SuperFakeService.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/SuperFakeService.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/SuperFakeService.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/SuperFakeService.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,24 @@ +/* + * 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.impl.manager.components; + +public interface SuperFakeService +{ + +} \ No newline at end of file Added: felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/T1.java URL: http://svn.apache.org/viewvc/felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/T1.java?rev=1689973&view=auto ============================================================================== --- felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/T1.java (added) +++ felix/sandbox/pderop/dependencymanager.ds/org.apache.felix.dependencymanager.ds/test/org/apache/felix/scr/impl/manager/components/T1.java Wed Jul 8 22:10:14 2015 @@ -0,0 +1,402 @@ +/* + * 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.impl.manager.components; + + +import java.util.Map; + +import org.osgi.framework.ServiceReference; + + +public class T1 +{ + + public String callPerformed = null; + + + private void privateT1() + { + callPerformed = "privateT1"; + } + + + private void privateT1SR( ServiceReference sr ) + { + if ( sr != null ) + { + callPerformed = "privateT1SR"; + } + else + { + callPerformed = "privateT1SR with null param"; + } + } + + + private void privateT1SI( FakeService si ) + { + if ( si != null ) + { + callPerformed = "privateT1SI"; + } + else + { + callPerformed = "privateT1SI with null param"; + } + } + + + private void privateT1SIMap( FakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "privateT1SIMap"; + } + else if ( si == null ) + { + callPerformed = "privateT1SIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "privateT1SIMap with null props"; + } + else + { + callPerformed = "privateT1SIMap with empty props"; + } + } + + + private void privateT1SSI( SuperFakeService si ) + { + if ( si != null ) + { + callPerformed = "privateT1SSI"; + } + else + { + callPerformed = "privateT1SSI with null param"; + } + } + + + private void privateT1SSIMap( SuperFakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "privateT1SSIMap"; + } + else if ( si == null ) + { + callPerformed = "privateT1SSIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "privateT1SSIMap with null props"; + } + else + { + callPerformed = "privateT1SSIMap with empty props"; + } + } + + + void packageT1() + { + callPerformed = "packageT1"; + } + + + void packageT1SR( ServiceReference sr ) + { + if ( sr != null ) + { + callPerformed = "packageT1SR"; + } + else + { + callPerformed = "packageT1SR with null param"; + } + } + + + void packageT1SI( FakeService si ) + { + if ( si != null ) + { + callPerformed = "packageT1SI"; + } + else + { + callPerformed = "packageT1SI with null param"; + } + } + + + void packageT1SIMap( FakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "packageT1SIMap"; + } + else if ( si == null ) + { + callPerformed = "packageT1SIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "packageT1SIMap with null props"; + } + else + { + callPerformed = "packageT1SIMap with empty props"; + } + } + + + void packageT1SSI( SuperFakeService si ) + { + if ( si != null ) + { + callPerformed = "packageT1SSI"; + } + else + { + callPerformed = "packageT1SSI with null param"; + } + } + + + void packageT1SSIMap( SuperFakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "packageT1SSIMap"; + } + else if ( si == null ) + { + callPerformed = "packageT1SSIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "packageT1SSIMap with null props"; + } + else + { + callPerformed = "packageT1SSIMap with empty props"; + } + } + + + protected void protectedT1() + { + callPerformed = "protectedT1"; + } + + + protected void protectedT1SR( ServiceReference sr ) + { + if ( sr != null ) + { + callPerformed = "protectedT1SR"; + } + else + { + callPerformed = "protectedT1SR with null param"; + } + } + + + protected void protectedT1SI( FakeService si ) + { + if ( si != null ) + { + callPerformed = "protectedT1SI"; + } + else + { + callPerformed = "protectedT1SI with null param"; + } + } + + + protected void protectedT1SIMap( FakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "protectedT1SIMap"; + } + else if ( si == null ) + { + callPerformed = "protectedT1SIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "protectedT1SIMap with null props"; + } + else + { + callPerformed = "protectedT1SIMap with empty props"; + } + } + + + protected void protectedT1SSI( SuperFakeService si ) + { + if ( si != null ) + { + callPerformed = "protectedT1SSI"; + } + else + { + callPerformed = "protectedT1SSI with null param"; + } + } + + + protected void protectedT1SSIMap( SuperFakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "protectedT1SSIMap"; + } + else if ( si == null ) + { + callPerformed = "protectedT1SSIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "protectedT1SSIMap with null props"; + } + else + { + callPerformed = "protectedT1SSIMap with empty props"; + } + } + + + public void publicT1() + { + callPerformed = "publicT1"; + } + + + public void publicT1SR( ServiceReference sr ) + { + if ( sr != null ) + { + callPerformed = "publicT1SR"; + } + else + { + callPerformed = "publicT1SR with null param"; + } + } + + + public void publicT1SI( FakeService si ) + { + if ( si != null ) + { + callPerformed = "publicT1SI"; + } + else + { + callPerformed = "publicT1SI with null param"; + } + } + + + public void publicT1SIMap( FakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "publicT1SIMap"; + } + else if ( si == null ) + { + callPerformed = "publicT1SIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "publicT1SIMap with null props"; + } + else + { + callPerformed = "publicT1SIMap with empty props"; + } + } + + + public void publicT1SSI( SuperFakeService si ) + { + if ( si != null ) + { + callPerformed = "publicT1SSI"; + } + else + { + callPerformed = "publicT1SSI with null param"; + } + } + + + public void publicT1SSIMap( SuperFakeService si, Map props ) + { + if ( si != null && props != null && props.size() > 0 ) + { + callPerformed = "publicT1SSIMap"; + } + else if ( si == null ) + { + callPerformed = "publicT1SSIMap with null service instance"; + } + else if ( props == null ) + { + callPerformed = "publicT1SSIMap with null props"; + } + else + { + callPerformed = "publicT1SSIMap with empty props"; + } + } + + + public void suitable( ServiceReference sr ) + { + callPerformed = "suitableT1"; + } + + void packageT1Map(Map props) + { + if ( props != null && !props.isEmpty()) + { + callPerformed = "packageT1Map"; + } + else if ( props == null) + { + callPerformed = "packageT1Map with null props"; + } + else + { + callPerformed = "packageT1Map with empty props"; + } + } + +} \ No newline at end of file
