FELIX-924 configuration policy configurable
FELIX-925 activate and deactivate method names are configurable
FELIX-929 name attributes of component and reference elements are optional
FELIX-930 Add support for DS 1.1 XML schema and namespace

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@784693 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/ComponentMetadataTest.java b/scr/src/test/java/org/apache/felix/scr/impl/ComponentMetadataTest.java
index 2e79705..3d2bad8 100644
--- a/scr/src/test/java/org/apache/felix/scr/impl/ComponentMetadataTest.java
+++ b/scr/src/test/java/org/apache/felix/scr/impl/ComponentMetadataTest.java
@@ -27,7 +27,7 @@
 public class ComponentMetadataTest extends TestCase
 {
 
-    private TestLogger logger = new TestLogger();
+    private MockLogger logger = new MockLogger();
 
 
     // test various combinations of component metadata with respect to
@@ -243,27 +243,230 @@
     }
 
 
-    public void testReference()
+    public void test_component_no_name_ds10()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata( Boolean.TRUE, null );
+        cm1.setName( null );
+        try
+        {
+            cm1.validate( logger );
+            fail( "Expected validation failure for DS 1.0 component without name" );
+        }
+        catch ( ComponentException ce )
+        {
+            // expected
+        }
+    }
+
+
+    public void test_component_no_name_ds11()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata11( Boolean.TRUE, null );
+        cm1.setName( null );
+        cm1.validate( logger );
+        assertEquals( "Expected name to equal implementation class name", cm1.getImplementationClassName(), cm1
+            .getName() );
+    }
+
+
+    public void test_component_activate_ds10()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata( Boolean.TRUE, null );
+        cm1.validate( logger );
+        assertEquals( "Activate method name", "activate", cm1.getActivate() );
+
+        final ComponentMetadata cm2 = createComponentMetadata( Boolean.TRUE, null );
+        cm2.setActivate( "someMethod" );
+        cm2.validate( logger );
+        assertEquals( "Activate method name", "activate", cm2.getActivate() );
+    }
+
+
+    public void test_component_activate_ds11()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata11( Boolean.TRUE, null );
+        cm1.validate( logger );
+        assertEquals( "Activate method name", "activate", cm1.getActivate() );
+
+        final ComponentMetadata cm2 = createComponentMetadata11( Boolean.TRUE, null );
+        cm2.setActivate( "someMethod" );
+        cm2.validate( logger );
+        assertEquals( "Activate method name", "someMethod", cm2.getActivate() );
+    }
+
+
+    public void test_component_deactivate_ds10()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata( Boolean.TRUE, null );
+        cm1.validate( logger );
+        assertEquals( "Deactivate method name", "deactivate", cm1.getDeactivate() );
+
+        final ComponentMetadata cm2 = createComponentMetadata( Boolean.TRUE, null );
+        cm2.setActivate( "someMethod" );
+        cm2.validate( logger );
+        assertEquals( "Deactivate method name", "deactivate", cm2.getDeactivate() );
+    }
+
+
+    public void test_component_deactivate_ds11()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata11( Boolean.TRUE, null );
+        cm1.validate( logger );
+        assertEquals( "Deactivate method name", "deactivate", cm1.getDeactivate() );
+
+        final ComponentMetadata cm2 = createComponentMetadata11( Boolean.TRUE, null );
+        cm2.setDeactivate( "someMethod" );
+        cm2.validate( logger );
+        assertEquals( "Deactivate method name", "someMethod", cm2.getDeactivate() );
+    }
+
+
+    public void test_component_configuration_policy_ds10()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata( Boolean.TRUE, null );
+        cm1.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm1
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm2 = createComponentMetadata( Boolean.TRUE, null );
+        cm2.setConfigurationPolicy( ComponentMetadata.CONFIGURATION_POLICY_IGNORE );
+        cm2.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm2
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm3 = createComponentMetadata( Boolean.TRUE, null );
+        cm3.setConfigurationPolicy( ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL );
+        cm3.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm3
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm4 = createComponentMetadata( Boolean.TRUE, null );
+        cm4.setConfigurationPolicy( ComponentMetadata.CONFIGURATION_POLICY_REQUIRE );
+        cm4.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm4
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm5 = createComponentMetadata( Boolean.TRUE, null );
+        cm5.setConfigurationPolicy( "undefined" );
+        cm5.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm5
+            .getConfigurationPolicy() );
+    }
+
+
+    public void test_component_configuration_policy_ds11()
+    {
+        final ComponentMetadata cm1 = createComponentMetadata11( Boolean.TRUE, null );
+        cm1.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm1
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm2 = createComponentMetadata11( Boolean.TRUE, null );
+        cm2.setConfigurationPolicy( ComponentMetadata.CONFIGURATION_POLICY_IGNORE );
+        cm2.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_IGNORE, cm2
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm3 = createComponentMetadata11( Boolean.TRUE, null );
+        cm3.setConfigurationPolicy( ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL );
+        cm3.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm3
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm4 = createComponentMetadata11( Boolean.TRUE, null );
+        cm4.setConfigurationPolicy( ComponentMetadata.CONFIGURATION_POLICY_REQUIRE );
+        cm4.validate( logger );
+        assertEquals( "Configuration policy", ComponentMetadata.CONFIGURATION_POLICY_REQUIRE, cm4
+            .getConfigurationPolicy() );
+
+        final ComponentMetadata cm5 = createComponentMetadata11( Boolean.TRUE, null );
+        cm5.setConfigurationPolicy( "undefined" );
+        try
+        {
+            cm5.validate( logger );
+            fail( "Expected validation failure due to undefined configuration policy" );
+        }
+        catch ( ComponentException ce )
+        {
+            // expected due to undefned configuration policy
+        }
+    }
+
+
+    public void test_reference_valid()
     {
         // two references, should validate
         final ComponentMetadata cm1 = createComponentMetadata( Boolean.TRUE, null );
         cm1.addDependency( createReferenceMetadata( "name1" ) );
         cm1.addDependency( createReferenceMetadata( "name2" ) );
         cm1.validate( logger );
+    }
 
-        // two references, must warn
+
+    public void test_reference_duplicate_name()
+    {
+        // two references with same name, must warn
         final ComponentMetadata cm2 = createComponentMetadata( Boolean.TRUE, null );
         cm2.addDependency( createReferenceMetadata( "name1" ) );
         cm2.addDependency( createReferenceMetadata( "name1" ) );
         cm2.validate( logger );
-        assertTrue( "Expected warning for duplicate reference name", logger.lastMessage != null
-            && logger.lastMessage.indexOf( "Detected duplicate reference name" ) >= 0 );
+        assertTrue( "Expected warning for duplicate reference name", logger
+            .messageContains( "Detected duplicate reference name" ) );
     }
 
 
+    public void test_reference_no_name_ds10()
+    {
+        // un-named reference, illegal for pre DS 1.1
+        final ComponentMetadata cm3 = createComponentMetadata( Boolean.TRUE, null );
+        cm3.addDependency( createReferenceMetadata( null ) );
+        try
+        {
+            cm3.validate( logger );
+            fail( "Expect validation failure for DS 1.0 reference without name" );
+        }
+        catch ( ComponentException ce )
+        {
+            // expected
+        }
+    }
+
+
+    public void test_reference_no_name_ds11()
+    {
+        // un-named reference, illegal for DS 1.1
+        final ComponentMetadata cm4 = createComponentMetadata11( Boolean.TRUE, null );
+        final ReferenceMetadata rm4 = createReferenceMetadata( null );
+        cm4.addDependency( rm4 );
+        cm4.validate( logger );
+        assertEquals( "Reference name defaults to interface", rm4.getInterface(), rm4.getName() );
+    }
+
+
+    //---------- Helper methods
+
+    // Creates DS 1.0 Component Metadata
     private ComponentMetadata createComponentMetadata( Boolean immediate, String factory )
     {
-        ComponentMetadata meta = new ComponentMetadata();
+        ComponentMetadata meta = new ComponentMetadata( XmlHandler.DS_VERSION_1_0 );
+        meta.setName( "place.holder" );
+        meta.setImplementationClassName( "place.holder.implementation" );
+        if ( immediate != null )
+        {
+            meta.setImmediate( immediate.booleanValue() );
+        }
+        if ( factory != null )
+        {
+            meta.setFactoryIdentifier( factory );
+        }
+        return meta;
+    }
+
+
+    // Creates DS 1.1 Component Metadata
+    private ComponentMetadata createComponentMetadata11( Boolean immediate, String factory )
+    {
+        ComponentMetadata meta = new ComponentMetadata( XmlHandler.DS_VERSION_1_1 );
         meta.setName( "place.holder" );
         meta.setImplementationClassName( "place.holder.implementation" );
         if ( immediate != null )
@@ -297,15 +500,4 @@
         meta.setInterface( "place.holder" );
         return meta;
     }
-
-    private static class TestLogger implements Logger
-    {
-        String lastMessage;
-
-
-        public void log( int level, String message, ComponentMetadata metadata, Throwable ex )
-        {
-            lastMessage = message;
-        }
-    }
 }
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/MockBundle.java b/scr/src/test/java/org/apache/felix/scr/impl/MockBundle.java
new file mode 100644
index 0000000..ddc18eb
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/impl/MockBundle.java
@@ -0,0 +1,166 @@
+/*
+ * 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.scr.impl;
+
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+
+public class MockBundle implements Bundle
+{
+
+    public Enumeration findEntries( String arg0, String arg1, boolean arg2 )
+    {
+        return null;
+    }
+
+
+    public BundleContext getBundleContext()
+    {
+        return null;
+    }
+
+
+    public long getBundleId()
+    {
+        return 0;
+    }
+
+
+    public URL getEntry( String name )
+    {
+        return getClass().getClassLoader().getResource( name );
+    }
+
+
+    public Enumeration getEntryPaths( String arg0 )
+    {
+        return null;
+    }
+
+
+    public Dictionary getHeaders()
+    {
+        return null;
+    }
+
+
+    public Dictionary getHeaders( String arg0 )
+    {
+        return null;
+    }
+
+
+    public long getLastModified()
+    {
+        return 0;
+    }
+
+
+    public String getLocation()
+    {
+        return "test:mockbundle";
+    }
+
+
+    public ServiceReference[] getRegisteredServices()
+    {
+        return null;
+    }
+
+
+    public URL getResource( String arg0 )
+    {
+        return null;
+    }
+
+
+    public Enumeration getResources( String arg0 )
+    {
+        return null;
+    }
+
+
+    public ServiceReference[] getServicesInUse()
+    {
+        return null;
+    }
+
+
+    public int getState()
+    {
+        return 0;
+    }
+
+
+    public String getSymbolicName()
+    {
+        return null;
+    }
+
+
+    public boolean hasPermission( Object arg0 )
+    {
+        return false;
+    }
+
+
+    public Class loadClass( String arg0 )
+    {
+        return null;
+    }
+
+
+    public void start()
+    {
+
+    }
+
+
+    public void stop()
+    {
+
+    }
+
+
+    public void uninstall()
+    {
+
+    }
+
+
+    public void update()
+    {
+
+    }
+
+
+    public void update( InputStream arg0 )
+    {
+
+    }
+
+}
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/MockLogger.java b/scr/src/test/java/org/apache/felix/scr/impl/MockLogger.java
new file mode 100644
index 0000000..3bf9061
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/impl/MockLogger.java
@@ -0,0 +1,37 @@
+/*
+ * 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.scr.impl;
+
+
+public class MockLogger implements Logger
+{
+    String lastMessage;
+
+
+    public void log( int level, String message, ComponentMetadata metadata, Throwable ex )
+    {
+        lastMessage = message;
+    }
+
+
+    public boolean messageContains( String value )
+    {
+        return lastMessage != null && lastMessage.indexOf( value ) >= 0;
+    }
+}
\ No newline at end of file
diff --git a/scr/src/test/java/org/apache/felix/scr/impl/XmlHandlerTest.java b/scr/src/test/java/org/apache/felix/scr/impl/XmlHandlerTest.java
new file mode 100644
index 0000000..c823a70
--- /dev/null
+++ b/scr/src/test/java/org/apache/felix/scr/impl/XmlHandlerTest.java
@@ -0,0 +1,239 @@
+/*
+ * 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.scr.impl;
+
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.felix.scr.impl.parser.KXml2SAXParser;
+import org.osgi.service.component.ComponentException;
+import org.xmlpull.v1.XmlPullParserException;
+
+
+public class XmlHandlerTest extends TestCase
+{
+    private MockLogger logger;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        logger = new MockLogger();
+    }
+
+
+    public void test_component_attributes_11() throws Exception
+    {
+        final List metadataList10 = readMetadata( "/components_activate_10.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList10.size() );
+
+        final ComponentMetadata cm10 = ( ComponentMetadata ) metadataList10.get( 0 );
+        cm10.validate( logger );
+        assertEquals( "DS Version 1.0", XmlHandler.DS_VERSION_1_0, cm10.getNamespaceCode() );
+        assertEquals( "Expected Activate Method not set", "activate", cm10.getActivate() );
+        assertEquals( "Expected Deactivate Method not set", "deactivate", cm10.getDeactivate() );
+        assertEquals( "Expected Configuration Policy not set", ComponentMetadata.CONFIGURATION_POLICY_OPTIONAL, cm10
+            .getConfigurationPolicy() );
+
+        final List metadataList11 = readMetadata( "/components_activate_11.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList11.size() );
+        final ComponentMetadata cm11 = ( ComponentMetadata ) metadataList11.get( 0 );
+        cm11.validate( logger );
+        assertEquals( "DS Version 1.1", XmlHandler.DS_VERSION_1_1, cm11.getNamespaceCode() );
+        assertEquals( "Expected Activate Method set", "myactivate", cm11.getActivate() );
+        assertEquals( "Expected Deactivate Method set", "mydeactivate", cm11.getDeactivate() );
+        assertEquals( "Expected Configuration Policy set", ComponentMetadata.CONFIGURATION_POLICY_IGNORE, cm11
+            .getConfigurationPolicy() );
+    }
+
+
+    public void test_component_no_name() throws Exception
+    {
+        final List metadataList10 = readMetadata( "/components_anonymous_10.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList10.size() );
+        final ComponentMetadata cm10 = ( ComponentMetadata ) metadataList10.get( 0 );
+        try
+        {
+            cm10.validate( logger );
+            fail( "Expected validation failure for component without name" );
+        }
+        catch ( ComponentException ce )
+        {
+            // expected !!
+        }
+
+        final List metadataList11 = readMetadata( "/components_anonymous_11.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList11.size() );
+        final ComponentMetadata cm11 = ( ComponentMetadata ) metadataList11.get( 0 );
+        cm11.validate( logger );
+        assertEquals( "Expected name equals class", cm11.getImplementationClassName(), cm11.getName() );
+    }
+
+
+    public void test_reference_no_name() throws Exception
+    {
+        final List metadataList10 = readMetadata( "/components_anonymous_10.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList10.size() );
+        final ComponentMetadata cm10 = ( ComponentMetadata ) metadataList10.get( 0 );
+        try
+        {
+            cm10.validate( logger );
+            fail( "Expected validation failure for component without name" );
+        }
+        catch ( ComponentException ce )
+        {
+            // expected !!
+        }
+
+        final List metadataList11 = readMetadata( "/components_anonymous_11.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList11.size() );
+        final ComponentMetadata cm11 = ( ComponentMetadata ) metadataList11.get( 0 );
+        cm11.validate( logger );
+        assertEquals( "Expected name equals class", cm11.getImplementationClassName(), cm11.getName() );
+    }
+
+
+    public void test_all_elements_10() throws Exception
+    {
+        final List metadataList10 = readMetadata( "/components_all_elements_10.xml" );
+        assertEquals( "Component Descriptors", 1, metadataList10.size() );
+        final ComponentMetadata cm10 = ( ComponentMetadata ) metadataList10.get( 0 );
+
+        // dont validate this, we test the raw reading
+
+        // ds namespace
+        assertEquals( "ds name space", XmlHandler.DS_VERSION_1_0, cm10.getNamespaceCode() );
+
+        // base component attributes
+        assertEquals( "component name", true, cm10.isEnabled() );
+        assertEquals( "component name", "components.all.name", cm10.getName() );
+        assertEquals( "component name", "components.all.factory", cm10.getFactoryIdentifier() );
+        assertEquals( "component name", true, cm10.isFactory() );
+        assertEquals( "component name", true, cm10.isImmediate() );
+
+        // ds 1.1 elements
+        assertEquals( "activate method", "myactivate", cm10.getActivate() );
+        assertEquals( "deactivate method", "mydeactivate", cm10.getDeactivate() );
+        assertEquals( "configuration policy", "ignore", cm10.getConfigurationPolicy() );
+
+        // from the implementation element
+        assertEquals( "component name", "components.all.impl", cm10.getImplementationClassName() );
+
+        // property setting
+        final PropertyMetadata prop = getPropertyMetadata( cm10, "prop" );
+        assertNotNull( "prop exists", prop );
+        assertEquals( "prop type", "Integer", prop.getType() );
+        assertEquals( "prop value", 1234, ( ( Integer ) prop.getValue() ).intValue() );
+
+        final PropertyMetadata file_property = getPropertyMetadata( cm10, "file.property" );
+        assertNotNull( "file.property exists", file_property );
+        assertEquals( "file.property type", "String", file_property.getType() );
+        assertEquals( "file.property value", "Property from File", file_property.getValue() );
+
+        // service setup
+        final ServiceMetadata sm = cm10.getServiceMetadata();
+        assertNotNull( "service", sm );
+        assertEquals( "servicefactory", true, sm.isServiceFactory() );
+        assertEquals( "1 interface", 1, sm.getProvides().length );
+        assertEquals( "service interface", "components.all.service", sm.getProvides()[0] );
+
+        // references - basic
+        final ReferenceMetadata rm = getReference( cm10, "ref.name" );
+        assertNotNull( "refeference ref.name", rm );
+        assertEquals( "ref.name name", "ref.name", rm.getName() );
+        assertEquals( "ref.name interface", "ref.service", rm.getInterface() );
+        assertEquals( "ref.name cardinality", "0..n", rm.getCardinality() );
+        assertEquals( "ref.name policy", "dynamic", rm.getPolicy() );
+        assertEquals( "ref.name target", "ref.target", rm.getTarget() );
+        assertEquals( "ref.name target prop name", "ref.name.target", rm.getTargetPropertyName() );
+        assertEquals( "ref.name bind method", "ref_bind", rm.getBind() );
+        assertEquals( "ref.name undbind method", "ref_unbind", rm.getUnbind() );
+
+        // references - cardinality side properties (isOptional, isMultiple)
+        final ReferenceMetadata rm01 = getReference( cm10, "ref.01" );
+        assertNotNull( "refeference ref.01", rm01 );
+        assertEquals( "ref.01 cardinality", "0..1", rm01.getCardinality() );
+        final ReferenceMetadata rm11 = getReference( cm10, "ref.11" );
+        assertNotNull( "refeference ref.11", rm11 );
+        assertEquals( "ref.11 cardinality", "1..1", rm11.getCardinality() );
+        final ReferenceMetadata rm0n = getReference( cm10, "ref.0n" );
+        assertNotNull( "refeference ref.0n", rm0n );
+        assertEquals( "ref.0n cardinality", "0..n", rm0n.getCardinality() );
+        final ReferenceMetadata rm1n = getReference( cm10, "ref.1n" );
+        assertNotNull( "refeference ref.1n", rm1n );
+        assertEquals( "ref.1n cardinality", "1..n", rm1n.getCardinality() );
+    }
+
+
+    //---------- helper
+
+    private List readMetadata( String filename ) throws IOException, ComponentException, XmlPullParserException,
+        Exception
+    {
+        BufferedReader in = new BufferedReader( new InputStreamReader( getClass().getResourceAsStream( filename ),
+            "UTF-8" ) );
+        final KXml2SAXParser parser = new KXml2SAXParser( in );
+
+        XmlHandler handler = new XmlHandler( new MockBundle(), logger );
+        parser.parseXML( handler );
+
+        return handler.getComponentMetadataList();
+    }
+
+
+    private ReferenceMetadata getReference( final ComponentMetadata cm, final String name )
+    {
+        List rmlist = cm.getDependencies();
+        for ( Iterator rmi = rmlist.iterator(); rmi.hasNext(); )
+        {
+            ReferenceMetadata rm = ( ReferenceMetadata ) rmi.next();
+            if ( name.equals( rm.getName() ) )
+            {
+                return rm;
+            }
+        }
+
+        // none found
+        return null;
+    }
+
+
+    private PropertyMetadata getPropertyMetadata( final ComponentMetadata cm, final String name )
+    {
+        List pmlist = cm.getPropertyMetaData();
+        for ( Iterator pmi = pmlist.iterator(); pmi.hasNext(); )
+        {
+            PropertyMetadata pm = ( PropertyMetadata ) pmi.next();
+            if ( name.equals( pm.getName() ) )
+            {
+                return pm;
+            }
+        }
+
+        // none found
+        return null;
+    }
+}
diff --git a/scr/src/test/resources/components_activate_10.xml b/scr/src/test/resources/components_activate_10.xml
new file mode 100644
index 0000000..2c754b5
--- /dev/null
+++ b/scr/src/test/resources/components_activate_10.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<components>
+    <scr:component name="components.activate.10"
+        activate="myactivate" deactivate="mydeactivate"
+        configuration-policy="ignore" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+        <implementation class="components.activate.10" />
+    </scr:component>
+</components>
diff --git a/scr/src/test/resources/components_activate_11.xml b/scr/src/test/resources/components_activate_11.xml
new file mode 100644
index 0000000..b046ea6
--- /dev/null
+++ b/scr/src/test/resources/components_activate_11.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<components>
+    <scr:component name="components.activate.11"
+        activate="myactivate" deactivate="mydeactivate"
+        configuration-policy="ignore" xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+        <implementation class="components.activate.11" />
+    </scr:component>
+</components>
diff --git a/scr/src/test/resources/components_all_elements_10.properties b/scr/src/test/resources/components_all_elements_10.properties
new file mode 100644
index 0000000..da7d322
--- /dev/null
+++ b/scr/src/test/resources/components_all_elements_10.properties
@@ -0,0 +1,20 @@
+# 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.
+#
+# Sample properties file for the metadate load test
+
+file.property = Property from File
\ No newline at end of file
diff --git a/scr/src/test/resources/components_all_elements_10.xml b/scr/src/test/resources/components_all_elements_10.xml
new file mode 100644
index 0000000..0587053
--- /dev/null
+++ b/scr/src/test/resources/components_all_elements_10.xml
@@ -0,0 +1,95 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<!-- 
+
+    This file has a component descriptor with values for all elements
+    and attributes defined in the Declarative Services XML Schema for
+    the Declarative Services Specification 1.0.
+    
+    The goal of this file is to test the XML parsing whether all elements
+    are read and stored in the metadata objects and fields. Semantic
+    correctness according to the specificiation is not tested.
+ -->
+
+<components>
+    <!--
+        component element with
+        * DS 1.0 namespace (sets the ds namespace code)
+        * DS 1.0 attributes
+        * DS 1.1 attributes (must be read)
+    -->
+    <scr:component
+        xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0"
+        
+        enabled="true"
+        name="components.all.name"
+        factory="components.all.factory"
+        immediate="true"
+        
+        activate="myactivate"
+        deactivate="mydeactivate"
+        configuration-policy="ignore"
+        >
+
+        <implementation class="components.all.impl" />
+
+        <property
+            name="prop"
+            value="1234"
+            type="Integer"
+        />
+
+        <properties
+            entry="components_all_elements_10.properties"
+        />
+
+        <service
+            servicefactory="true"
+        >
+            <provide
+                interface="components.all.service"
+            />
+        </service>
+
+        <!-- Basic reference testing reading -->
+        <reference
+            name="ref.name"
+            interface="ref.service"
+            cardinality="0..n"
+            policy="dynamic"
+            target="ref.target"
+            bind="ref_bind"
+            unbind="ref_unbind"
+        />
+        
+        <!--
+            references testing the setting of secondary properties
+            isStatic, isMultiple and isOptional
+        -->
+        <reference name="ref.01" cardinality="0..1" />
+        <reference name="ref.11" cardinality="1..1" />
+        <reference name="ref.0n" cardinality="0..n" />
+        <reference name="ref.1n" cardinality="1..n" />
+        <reference name="ref.static" policy="static" />
+        <reference name="ref.dynamic" policy="dynamic" />
+
+    </scr:component>
+</components>
diff --git a/scr/src/test/resources/components_anonymous_10.xml b/scr/src/test/resources/components_anonymous_10.xml
new file mode 100644
index 0000000..0627e5a
--- /dev/null
+++ b/scr/src/test/resources/components_anonymous_10.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+    <scr:component enabled="true" immediate="true">
+        <implementation class="components.anonymous.10" />
+    </scr:component>
+</components>
diff --git a/scr/src/test/resources/components_anonymous_11.xml b/scr/src/test/resources/components_anonymous_11.xml
new file mode 100644
index 0000000..5254df9
--- /dev/null
+++ b/scr/src/test/resources/components_anonymous_11.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+    <scr:component enabled="true" immediate="true">
+        <implementation class="components.anonymous.11" />
+    </scr:component>
+</components>
diff --git a/scr/src/test/resources/reference_anonymous_10.xml b/scr/src/test/resources/reference_anonymous_10.xml
new file mode 100644
index 0000000..c1d68ea
--- /dev/null
+++ b/scr/src/test/resources/reference_anonymous_10.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
+    <scr:component enabled="true" immediate="true"
+        name="reference.anonymous.10">
+        <implementation class="reference.anonymous.10" />
+        <reference interface="ref.anon" />
+    </scr:component>
+</components>
diff --git a/scr/src/test/resources/reference_anonymous_11.xml b/scr/src/test/resources/reference_anonymous_11.xml
new file mode 100644
index 0000000..11a5bf4
--- /dev/null
+++ b/scr/src/test/resources/reference_anonymous_11.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0">
+    <scr:component enabled="true" immediate="true"
+        name="reference.anonymous.10">
+        <implementation class="reference.anonymous.10" />
+        <reference interface="ref.anon" />
+    </scr:component>
+</components>