Author: clement
Date: Sun Aug 25 17:45:40 2013
New Revision: 1517347
URL: http://svn.apache.org/r1517347
Log:
Fix FELIX-4204
Modified:
felix/trunk/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
Modified:
felix/trunk/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java?rev=1517347&r1=1517346&r2=1517347&view=diff
==============================================================================
---
felix/trunk/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
(original)
+++
felix/trunk/ipojo/runtime/core-it/ipojo-core-bad-configuration-test/src/test/java/org/apache/felix/ipojo/runtime/bad/test/TestBadServiceDependencies.java
Sun Aug 25 17:45:40 2013
@@ -131,6 +131,41 @@ public class TestBadServiceDependencies
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 @@ public class TestBadServiceDependencies
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());
+ }
+ }
}
Modified:
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=1517347&r1=1517346&r2=1517347&view=diff
==============================================================================
---
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
(original)
+++
felix/trunk/ipojo/runtime/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
Sun Aug 25 17:45:40 2013
@@ -567,7 +567,7 @@ public class DependencyHandler extends P
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");
}