You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2013/09/04 19:33:04 UTC

svn commit: r1520080 - in /felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src: main/java/org/apache/felix/ipojo/runtime/core/components/constructor/ test/java/org/apache/felix/ipojo/runtime/core/

Author: clement
Date: Wed Sep  4 17:33:04 2013
New Revision: 1520080

URL: http://svn.apache.org/r1520080
Log:
FELIX-4216 Allow @Property without name in constructors

Added tests.

Added:
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java
    felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java?rev=1520080&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java Wed Sep  4 17:33:04 2013
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.components.constructor;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.osgi.framework.BundleContext;
+
+import java.util.Properties;
+
+@Component(immediate = true)
+@Provides
+public class CheckServiceProviderWithBundleContextAndProperty implements CheckService {
+
+
+    private final String message;
+    private final BundleContext context;
+
+    public CheckServiceProviderWithBundleContextAndProperty(BundleContext context, @Property String message) {
+        this.message = message;
+        this.context = context;
+    }
+
+    public boolean check() {
+        return message != null;
+    }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("message", message);
+        props.put("context", context);
+        
+        return props;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java?rev=1520080&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java Wed Sep  4 17:33:04 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.components.constructor;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+
+import java.util.Properties;
+
+@Component(immediate = true)
+@Provides
+public class CheckServiceProviderWithDefaultValueProperty implements CheckService {
+
+
+    private final String message;
+
+    public CheckServiceProviderWithDefaultValueProperty(@Property(value = "message") String message) {
+        this.message = message;
+    }
+
+
+    public boolean check() {
+        return message != null;
+    }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("message", message);
+        
+        return props;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java?rev=1520080&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java Wed Sep  4 17:33:04 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.components.constructor;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+
+import java.util.Properties;
+
+@Component(immediate = true)
+@Provides
+public class CheckServiceProviderWithNamedProperty implements CheckService {
+
+
+    private final String message;
+
+    public CheckServiceProviderWithNamedProperty(@Property(name = "message") String message) {
+        this.message = message;
+    }
+
+
+    public boolean check() {
+        return message != null;
+    }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("message", message);
+        
+        return props;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java?rev=1520080&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java Wed Sep  4 17:33:04 2013
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.components.constructor;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+
+import java.util.Properties;
+
+@Component(immediate = true)
+@Provides
+public class CheckServiceProviderWithTwoProperties implements CheckService {
+
+
+    private final String message;
+    private final String product;
+
+    public CheckServiceProviderWithTwoProperties(@Property String message, @Property(value="ipojo") String product) {
+        this.message = message;
+        this.product = product;
+    }
+
+
+    public boolean check() {
+        return message != null;
+    }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("message", message);
+        props.put("product", product);
+        
+        return props;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java?rev=1520080&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java Wed Sep  4 17:33:04 2013
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core.components.constructor;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.annotations.Property;
+import org.apache.felix.ipojo.annotations.Provides;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+
+import java.util.Properties;
+
+@Component(immediate = true)
+@Provides
+public class CheckServiceProviderWithUnnamedProperty implements CheckService {
+
+
+    private final String message;
+
+    public CheckServiceProviderWithUnnamedProperty(@Property String message) {
+        this.message = message;
+    }
+
+
+    public boolean check() {
+        return message != null;
+    }
+
+    public Properties getProps() {
+        Properties props = new Properties();
+        props.put("message", message);
+        
+        return props;
+    }
+
+}

Added: felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java?rev=1520080&view=auto
==============================================================================
--- felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java (added)
+++ felix/trunk/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java Wed Sep  4 17:33:04 2013
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.felix.ipojo.runtime.core;
+
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.runtime.core.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.services.FooService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Properties;
+
+import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
+
+
+public class TestConstructorInjectionOfProperties extends Common {
+
+
+    @Test
+    public void testInjectionOfNamedProperty() {
+        Dictionary<String, String> conf = new Hashtable<String, String>();
+        conf.put("message", "message");
+        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" +
+                ".components.constructor.CheckServiceProviderWithNamedProperty", conf);
+
+        ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(),
+                "(instance.name=" + instance.getInstanceName() +")",
+                1000);
+
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertEquals(cs.getProps().getProperty("message"), "message");
+    }
+
+    @Test
+    public void testInjectionOfUnnamedProperty() {
+        Dictionary<String, String> conf = new Hashtable<String, String>();
+        conf.put("message", "message");
+
+        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" +
+                ".components.constructor.CheckServiceProviderWithUnnamedProperty", conf);
+
+        ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(),
+                "(instance.name=" + instance.getInstanceName() +")",
+                1000);
+
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertEquals(cs.getProps().getProperty("message"), "message");
+    }
+
+    @Test
+    public void testInjectionOfPropertyWithDefaultValue() {
+        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" +
+                ".components.constructor.CheckServiceProviderWithDefaultValueProperty");
+
+        ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(),
+                "(instance.name=" + instance.getInstanceName() +")",
+                1000);
+
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertEquals(cs.getProps().getProperty("message"), "message");
+    }
+
+    @Test
+    public void testInjectionOfTwoProperties() {
+        Dictionary<String, String> conf = new Hashtable<String, String>();
+        conf.put("message", "message");
+
+        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" +
+                ".components.constructor.CheckServiceProviderWithTwoProperties", conf);
+
+        ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(),
+                "(instance.name=" + instance.getInstanceName() +")",
+                1000);
+
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertEquals(cs.getProps().getProperty("message"), "message");
+        assertEquals(cs.getProps().getProperty("product"), "ipojo");
+    }
+
+    @Test
+    public void testInjectionOfAPropertyAndBundleContext() {
+        Dictionary<String, String> conf = new Hashtable<String, String>();
+        conf.put("message", "message");
+
+        ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core" +
+                ".components.constructor.CheckServiceProviderWithBundleContextAndProperty", conf);
+
+        ServiceReference ref = osgiHelper.waitForService(CheckService.class.getName(),
+                "(instance.name=" + instance.getInstanceName() +")",
+                1000);
+
+        CheckService cs = (CheckService) osgiHelper.getServiceObject(ref);
+        assertEquals(cs.getProps().getProperty("message"), "message");
+        assertNotNull(cs.getProps().get("context"));
+        assertTrue(cs.getProps().get("context") instanceof BundleContext);
+    }
+
+}