You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by dj...@apache.org on 2014/07/16 21:55:58 UTC

svn commit: r1611157 - in /felix/trunk/scr/src: main/java/org/apache/felix/scr/impl/metadata/ test/java/org/apache/felix/scr/integration/ test/resources/

Author: djencks
Date: Wed Jul 16 19:55:57 2014
New Revision: 1611157

URL: http://svn.apache.org/r1611157
Log:
[FELIX-4563] Turn xml reference target attributes into properties, with a test

Added:
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java   (with props)
    felix/trunk/scr/src/test/resources/integration_test_target_properties.xml   (with props)
Modified:
    felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java
    felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java

Modified: felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java?rev=1611157&r1=1611156&r2=1611157&view=diff
==============================================================================
--- felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java (original)
+++ felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/metadata/XmlHandler.java Wed Jul 16 19:55:57 2014
@@ -390,8 +390,15 @@ public class XmlHandler implements KXml2
                         ref.setScope( attributes.getAttribute( "scope" ) );
                     }
 
-                    //if
-                    ref.setTarget( attributes.getAttribute( "target" ) );
+                    if ( attributes.getAttribute( "target" ) != null)
+                    {
+                        ref.setTarget( attributes.getAttribute( "target" ) );
+                        PropertyMetadata prop = new PropertyMetadata();
+                        prop.setName( (ref.getName() == null? ref.getInterface(): ref.getName()) + ".target");
+                        prop.setValue( attributes.getAttribute( "target" ) );
+                        m_currentComponent.addProperty( prop );
+                                               
+                    }
                     ref.setBind( attributes.getAttribute( "bind" ) );
                     ref.setUpdated( attributes.getAttribute( "updated" ) );
                     ref.setUnbind( attributes.getAttribute( "unbind" ) );

Modified: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java?rev=1611157&r1=1611156&r2=1611157&view=diff
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java (original)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/ComponentTestBase.java Wed Jul 16 19:55:57 2014
@@ -187,6 +187,7 @@ public abstract class ComponentTestBase
 
         );
         final Option vmOption = ( paxRunnerVmOption != null ) ? CoreOptions.vmOption( paxRunnerVmOption ) : null;
+        NONSTANDARD_COMPONENT_FACTORY_BEHAVIOR = false;
         return OptionUtils.combine( base, vmOption );
     }
 

Added: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java?rev=1611157&view=auto
==============================================================================
--- felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java (added)
+++ felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java Wed Jul 16 19:55:57 2014
@@ -0,0 +1,121 @@
+/*
+ * 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.integration;
+
+import java.util.Hashtable;
+
+import junit.framework.TestCase;
+
+import org.apache.felix.scr.integration.components.SimpleComponent;
+import org.apache.felix.scr.integration.components.SimpleServiceImpl;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentConstants;
+import org.osgi.service.component.ComponentFactory;
+import org.osgi.service.component.ComponentInstance;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+
+@RunWith(JUnit4TestRunner.class)
+public class TargetPropertyTest extends ComponentTestBase
+{
+
+    static
+    {
+        // uncomment to enable debugging of this test class
+//         paxRunnerVmOption = DEBUG_VM_OPTION;
+
+        descriptorFile = "/integration_test_target_properties.xml";
+    }
+
+    @Test
+    public void test_1() throws Exception
+    {
+        String pid = "components.target.properties.1";
+        singleTest( pid, "foo" );
+    }
+
+    @Test
+    public void test_1_2() throws Exception
+    {
+        String pid = "components.target.properties.1.2";
+        singleTest( pid, "foo" );
+    }
+
+    @Test
+    public void test_1_3() throws Exception
+    {
+        String pid = "components.target.properties.1.3";
+        singleTest( pid, "foo" );
+    }
+
+    @Test
+    public void test_2() throws Exception
+    {
+        String pid = "components.target.properties.2";
+        singleTest( pid, "foo" );
+    }
+
+    @Test
+    public void test_3() throws Exception
+    {
+        String pid = "components.target.properties.3";
+        singleTest( pid, "bar" );
+    }
+
+
+    private void singleTest(String pid, String expected) throws Exception
+    {
+        final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, expected );
+        final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "baz" );
+
+		getDisabledConfigurationAndEnable(pid, ComponentConfigurationDTO.ACTIVE);
+        checkTarget(expected, srv1);
+        
+        //configuration not setting target property does not change it
+        configure( pid );
+        delay();//all cm event to complete
+        checkTarget(expected, srv1);
+        
+        // update configuration to target srv2
+        theConfig.put("one.target", "(value=baz)");
+        configure( pid );
+        delay();
+        checkTarget("baz", srv2);
+        
+        //update configuration removing target property
+        theConfig.remove("one.target");
+        configure( pid );
+        delay();//all cm event to complete
+        checkTarget(expected, srv1);
+        
+    }
+
+    void checkTarget(String expected, final SimpleServiceImpl srv1)
+    {
+        final SimpleComponent comp10 = SimpleComponent.INSTANCE;
+        TestCase.assertNotNull( comp10 );
+        TestCase.assertEquals("(value=" + expected + ")", comp10.getProperty("one.target"));
+        TestCase.assertEquals( srv1, comp10.m_singleRef );
+    }
+
+
+}

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/TargetPropertyTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/scr/src/test/resources/integration_test_target_properties.xml
URL: http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_target_properties.xml?rev=1611157&view=auto
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_target_properties.xml (added)
+++ felix/trunk/scr/src/test/resources/integration_test_target_properties.xml Wed Jul 16 19:55:57 2014
@@ -0,0 +1,133 @@
+<?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.target.properties.1"
+            xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
+            immediate="true"
+            enabled="false"
+            configuration-policy="optional"
+            activate="activate"
+            modified="modified">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.SimpleComponent" />
+        </service>
+        <reference
+            name="one"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(value=foo)"
+        />
+    </scr:component>
+
+    <scr:component name="components.target.properties.2"
+            xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
+            immediate="true"
+            enabled="false"
+            configuration-policy="optional"
+            activate="activate"
+            modified="modified">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.SimpleComponent" />
+        </service>
+        <property name="one.target" value="(value=bar)" />
+        <reference
+            name="one"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(value=foo)"
+        />
+    </scr:component>
+
+    <scr:component name="components.target.properties.3"
+            xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
+            immediate="true"
+            enabled="false"
+            configuration-policy="optional"
+            activate="activate"
+            modified="modified">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.SimpleComponent" />
+        </service>
+        <reference
+            name="one"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(value=foo)"
+        />
+        <property name="one.target" value="(value=bar)" />
+    </scr:component>
+
+    <scr:component name="components.target.properties.1.2"
+            xmlns:scr="http://www.osgi.org/xmlns/scr/v1.2.0"
+            immediate="true"
+            enabled="false"
+            configuration-policy="optional"
+            activate="activate"
+            modified="modified">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.SimpleComponent" />
+        </service>
+        <reference
+            name="one"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(value=foo)"
+        />
+    </scr:component>
+
+    <scr:component name="components.target.properties.1.3"
+            xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0"
+            immediate="true"
+            enabled="false"
+            configuration-policy="optional"
+            activate="activate"
+            modified="modified">
+        <implementation class="org.apache.felix.scr.integration.components.SimpleComponent" />
+        <service>
+            <provide interface="org.apache.felix.scr.integration.components.SimpleComponent" />
+        </service>
+        <reference
+            name="one"
+            interface="org.apache.felix.scr.integration.components.SimpleService"
+            cardinality="0..1"
+            policy="dynamic"
+            bind="setSimpleService"
+            unbind="unsetSimpleService"
+            target="(value=foo)"
+        />
+    </scr:component>
+
+</components>

Propchange: felix/trunk/scr/src/test/resources/integration_test_target_properties.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: felix/trunk/scr/src/test/resources/integration_test_target_properties.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: felix/trunk/scr/src/test/resources/integration_test_target_properties.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml