FELIX-3648 Fail validation if an updated method is declared in a DS 1.0 or DS 1.1 namespaced declaration.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1380117 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
index c683f3a..87fd62f 100644
--- a/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
+++ b/scr/src/main/java/org/apache/felix/scr/impl/metadata/ReferenceMetadata.java
@@ -22,7 +22,6 @@
import java.util.TreeSet;
import org.apache.felix.scr.impl.helper.Logger;
-import org.osgi.service.log.LogService;
/**
* Information associated to a dependency
@@ -494,11 +493,8 @@
// updated method is only supported in namespace xxx and later
if ( m_updated != null && !componentMetadata.isDS11Felix() )
{
- logger
- .log( LogService.LOG_WARNING,
- "Ignoring updated method definition, DS 1.1-felix or later namespace required", componentMetadata,
- null );
- m_updated = null;
+ // FELIX-3648 validation must fail (instead of just ignore)
+ throw componentMetadata.validationFailure( "updated method declaration requires DS 1.2 or later namespace " );
}
m_validated = true;
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java b/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
index e8fd9e1..8912571 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/metadata/ComponentMetadataTest.java
@@ -474,12 +474,8 @@
final ComponentMetadata cm3 = createComponentMetadata( Boolean.TRUE, null );
cm3.addDependency( rm3 );
- // validates fine (though logging a warning) and sets field to null
- cm3.validate( logger );
-
- assertTrue( "Expected warning for unsupported updated method name",
- logger.messageContains( "Ignoring updated method definition" ) );
- assertNull( rm3.getUpdated() );
+ // according to DS 1.2 must fail validation (FELIX-3648)
+ failDS10Validation( cm3, "updated", logger );
}
@@ -491,12 +487,8 @@
final ComponentMetadata cm3 = createComponentMetadata11( Boolean.TRUE, null );
cm3.addDependency( rm3 );
- // validates fine (though logging a warning) and sets field to null
- cm3.validate( logger );
-
- assertTrue( "Expected warning for unsupported updated method name",
- logger.messageContains( "Ignoring updated method definition" ) );
- assertNull( rm3.getUpdated() );
+ // according to DS 1.2 must fail validation (FELIX-3648)
+ failDS10Validation( cm3, "updated", logger );
}
@@ -515,6 +507,21 @@
}
+ public void test_reference_updated_ds12()
+ {
+ // updated method accepted for DS 1.2
+ final ReferenceMetadata rm3 = createReferenceMetadata( "test" );
+ rm3.setUpdated( "my_updated_method" );
+ final ComponentMetadata cm3 = createComponentMetadata( XmlHandler.DS_VERSION_1_2, Boolean.TRUE, null );
+ cm3.addDependency( rm3 );
+
+ // validates fine and logs no message
+ cm3.validate( logger );
+
+ assertEquals( "my_updated_method", rm3.getUpdated() );
+ }
+
+
public void test_duplicate_implementation_ds10()
{
final ComponentMetadata cm = createComponentMetadata( Boolean.TRUE, null );
@@ -710,7 +717,7 @@
{
// expected
}
-
+
cm = createComponentMetadata12( null, null );
try
{
@@ -730,16 +737,16 @@
doTest_get_configuration_pid_method(XmlHandler.DS_VERSION_1_1);
doTest_get_configuration_pid_method(XmlHandler.DS_VERSION_1_2);
}
-
+
private void doTest_get_configuration_pid_method(int specVersion)
- {
+ {
// Make sure that getConfigurationPid returns the default component name (implementation class name).
// We only do this kind of test if spec is greater than ds 1.0, because in ds 1.0, the component name is mandatory.
if (specVersion > XmlHandler.DS_VERSION_1_0)
{
ComponentMetadata cm = new ComponentMetadata( specVersion );
try
- {
+ {
cm.setImplementationClassName("implementation.class");
cm.setName( null );
cm.validate( logger );
@@ -750,14 +757,14 @@
}
String pid = cm.getConfigurationPid();
assertNotNull( "Expect non-null configuration pid when component name is not specified", pid );
- assertEquals( "Expect configuration-pid to be equals to component implementation",
+ assertEquals( "Expect configuration-pid to be equals to component implementation",
"implementation.class", cm.getConfigurationPid() );
}
-
+
// Make sure that getConfigurationPid returns the name of the component, if specified
ComponentMetadata cm = new ComponentMetadata( specVersion );
try
- {
+ {
cm.setImplementationClassName("implementation.class");
cm.setName("my.component.name");
cm.validate( logger );
@@ -768,7 +775,7 @@
}
String pid = cm.getConfigurationPid();
assertNotNull( "Expect non-null configuration pid when component name is specified", pid );
- assertEquals( "Expect configuration-pid to be equals to component name",
+ assertEquals( "Expect configuration-pid to be equals to component name",
"my.component.name", cm.getConfigurationPid() );
}