Fix FELIX-4204
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1517347 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java b/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
index ae5a1eb..03133fe 100644
--- a/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
+++ b/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
@@ -131,6 +131,41 @@
return elem;
}
+ private Element getMissingCallbackType() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ // iPOJO cannot determine the specification of this type of dependency.
+ Element dependency = new Element("requires", "");
+ dependency.addAttribute(new Attribute("field", "fs"));
+ Element callback = new Element("callback", "");
+ // callback.addAttribute(new Attribute("type", "bind")); --> Type missing.
+ callback.addAttribute(new Attribute("method", "refBind"));
+ dependency.addElement(callback);
+ elem.addElement(dependency);
+
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+ private Element getMissingCallbackMethod() {
+ Element elem = new Element("component", "");
+ elem.addAttribute(new Attribute("classname", clazz));
+
+ // iPOJO cannot determine the specification of this type of dependency.
+ Element dependency = new Element("requires", "");
+ dependency.addAttribute(new Attribute("field", "fs"));
+ Element callback = new Element("callback", "");
+ callback.addAttribute(new Attribute("type", "bind"));
+ // callback.addAttribute(new Attribute("method", "refBind")); --> Method missing.
+ dependency.addElement(callback);
+ elem.addElement(dependency);
+
+ elem.addElement(manipulation);
+ return elem;
+ }
+
+
private Element getManipulationForComponent() {
// On KF we must cast the result.
String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
@@ -289,4 +324,47 @@
fail("Unexpected exception when creating an instance : " + e.getMessage());
}
}
+
+ /**
+ * Check that a component using a service dependency with a callback without its type is rejected.
+ * The type is either 'bind' or 'unbind'.
+ */
+ @Test
+ public void testDependencyWithACallbackWithoutType() {
+ try {
+ ComponentFactory cf = new ComponentFactory(osgiHelper.getContext(), getMissingCallbackType());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with a bad type must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
+
+ /**
+ * Check that a component using a service dependency with a callback without its method is rejected.
+ */
+ @Test
+ public void testDependencyWithACallbackWithoutMethod() {
+ try {
+ ComponentFactory cf = new ComponentFactory(osgiHelper.getContext(), getMissingCallbackMethod());
+ cf.start();
+ ComponentInstance ci = cf.createComponentInstance(props);
+ ci.dispose();
+ cf.stop();
+ fail("A service requirement with a bad type must be rejected " + cf);
+ } catch (ConfigurationException e) {
+ // OK
+ } catch (UnacceptableConfiguration e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ } catch (MissingHandlerException e) {
+ fail("Unexpected exception when creating an instance : " + e.getMessage());
+ }
+ }
}
diff --git a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
index b362473..a75eb7e 100644
--- a/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
+++ b/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
@@ -567,7 +567,7 @@
private void addCallbacksToDependency(Element dependencyElement, Dependency dep) throws ConfigurationException {
Element[] cbs = dependencyElement.getElements("Callback");
for (int j = 0; cbs != null && j < cbs.length; j++) {
- if (!cbs[j].containsAttribute("method") && cbs[j].containsAttribute("type")) {
+ if (!cbs[j].containsAttribute("method") || !cbs[j].containsAttribute("type")) {
throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method " +
"and a type (bind or unbind) attribute");
}