FELIX-4216 Allow @Property without name in constructors

Added tests.

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1520080 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java
new file mode 100644
index 0000000..da37d32
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithBundleContextAndProperty.java
@@ -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;

+    }

+

+}

diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java
new file mode 100644
index 0000000..32e2c41
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithDefaultValueProperty.java
@@ -0,0 +1,51 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.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;

+    }

+

+}

diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java
new file mode 100644
index 0000000..cca6bfe
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithNamedProperty.java
@@ -0,0 +1,51 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.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;

+    }

+

+}

diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java
new file mode 100644
index 0000000..eb25b5b
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithTwoProperties.java
@@ -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;

+    }

+

+}

diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java
new file mode 100644
index 0000000..cf79b0d
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/main/java/org/apache/felix/ipojo/runtime/core/components/constructor/CheckServiceProviderWithUnnamedProperty.java
@@ -0,0 +1,51 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.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;

+    }

+

+}

diff --git a/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java
new file mode 100644
index 0000000..e6bf206
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/core/TestConstructorInjectionOfProperties.java
@@ -0,0 +1,120 @@
+/*

+ * Licensed to the Apache Software Foundation (ASF) under one

+ * or more contributor license agreements.  See the NOTICE file

+ * distributed with this work for additional information

+ * regarding copyright ownership.  The ASF licenses this file

+ * to you under the Apache License, Version 2.0 (the

+ * "License"); you may not use this file except in compliance

+ * with the License.  You may obtain a copy of the License at

+ *

+ *   http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing,

+ * software distributed under the License is distributed on an

+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

+ * KIND, either express or implied.  See the License for the

+ * specific language governing permissions and limitations

+ * under the License.

+ */

+package org.apache.felix.ipojo.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);

+    }

+

+}