Check FELIX-4380
(https://issues.apache.org/jira/browse/FELIX-4380)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1558378 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/DependencyUsingSpecification.java b/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/DependencyUsingSpecification.java
new file mode 100644
index 0000000..42d6bb9
--- /dev/null
+++ b/ipojo/runtime/core-it/ipojo-core-annotations-test/src/main/java/org/apache/felix/ipojo/runtime/core/test/components/DependencyUsingSpecification.java
@@ -0,0 +1,55 @@
+/*
+ * 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.test.components;
+
+import org.apache.felix.ipojo.annotations.*;
+import org.apache.felix.ipojo.runtime.core.test.services.BarService;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
+import org.apache.felix.ipojo.runtime.core.test.services.FooService;
+
+import java.util.*;
+import java.util.Properties;
+
+@Component
+@Provides
+public class DependencyUsingSpecification implements CheckService {
+
+ private boolean bound = false;
+
+ @Unbind
+ public synchronized void unbindBar() {
+ bound = false;
+ }
+
+ @Bind(specification = BarService.class, optional = true)
+ public synchronized void bindBar() {
+ bound = true;
+ }
+
+ @Override
+ public boolean check() {
+ return bound;
+ }
+
+ @Override
+ public Properties getProps() {
+ return null;
+ }
+}
diff --git a/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java b/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java
index aa3be4d..6ef8078 100644
--- a/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java
+++ b/ipojo/runtime/core-it/ipojo-core-annotations-test/src/test/java/org/apache/felix/ipojo/runtime/core/test/annotations/TestDependency.java
@@ -19,10 +19,16 @@
package org.apache.felix.ipojo.runtime.core.test.annotations;
+import org.apache.felix.ipojo.ComponentInstance;
import org.apache.felix.ipojo.metadata.Element;
+import org.apache.felix.ipojo.runtime.core.test.services.CheckService;
import org.junit.Test;
+import org.osgi.framework.ServiceReference;
+import org.ow2.chameleon.testing.helpers.IPOJOHelper;
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.*;
public class TestDependency extends Common {
@@ -30,7 +36,8 @@
@Test
public void testDependencyDeclaration() {
- Element meta = ipojoHelper.getMetadata(getTestBundle(), "org.apache.felix.ipojo.runtime.core.test.components.Dependency");
+ Element meta = IPOJOHelper.getMetadata(getTestBundle(),
+ "org.apache.felix.ipojo.runtime.core.test.components.Dependency");
Element[] deps = meta.getElements("requires");
// Check fs
@@ -106,6 +113,32 @@
assertEquals("Check not proxied", "false", dep.getAttribute("proxy"));
}
+ /**
+ * Reproduce https://issues.apache.org/jira/browse/FELIX-4380.
+ */
+ @Test
+ public void testDependencyUsingSpecification() {
+ ComponentInstance instance = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" +
+ ".components.DependencyUsingSpecification");
+
+ ServiceReference ref = ipojoHelper.getServiceReferenceByName(CheckService.class.getName(),
+ instance.getInstanceName());
+
+ assertNotNull(ref);
+
+ CheckService svc = (CheckService) osgiHelper.getServiceObject(ref);
+ assertFalse(svc.check());
+
+ // The following instantiation exposes the BarService required by instance.
+ ComponentInstance bar = ipojoHelper.createComponentInstance("org.apache.felix.ipojo.runtime.core.test" +
+ ".components.ProvidesSimple");
+
+ assertTrue(svc.check());
+
+ bar.dispose();
+ assertFalse(svc.check());
+ }
+
private Element getDependencyById(Element[] deps, String name) {
for (int i = 0; i < deps.length; i++) {
String na = deps[i].getAttribute("id");