You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2010/05/18 16:44:06 UTC

svn commit: r945681 - in /qpid/trunk/qpid/java/broker/src: main/java/org/apache/qpid/server/configuration/plugins/ test/java/org/apache/qpid/server/configuration/plugins/

Author: ritchiem
Date: Tue May 18 14:44:06 2010
New Revision: 945681

URL: http://svn.apache.org/viewvc?rev=945681&view=rev
Log:
QPID-2581 : Update ConfigurationPlugin to correctly handle attributes in configuration.
Added work around for the fact that we use a Composite Configuration that turns an XML attribute key of '[@attribute]' in to '@attribute]'. Added test for to this conversion.

This makes the Plugin Configuration interface consistent so if we swap our configuration format. The key style of '[@attribute]' will work as expected.

Added:
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/
    qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java?rev=945681&r1=945680&r2=945681&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/configuration/plugins/ConfigurationPlugin.java Tue May 18 14:44:06 2010
@@ -94,7 +94,7 @@ public abstract class ConfigurationPlugi
 
             //Trim any element properties
             elementNameIndex = element.indexOf("[");
-            if (elementNameIndex != -1)
+            if (elementNameIndex > 0)
             {
                 element = element.substring(0,elementNameIndex).trim();
             }
@@ -106,6 +106,18 @@ public abstract class ConfigurationPlugi
         //Remove the items we already expect in the configuration
         for (String tag : getElementsProcessed())
         {
+
+            // Work round the issue with Commons configuration.
+            // With an XMLConfiguration the key will be [@property]
+            // but with a CompositeConfiguration it will be @property].
+            // Hide this issue from our users so when/if we change the
+            // configuration they don't have to. 
+            int bracketIndex = tag.indexOf("[");
+            if (bracketIndex != -1)
+            {                
+                tag = tag.substring(bracketIndex + 1, tag.length());
+            }
+
             elements.remove(tag);
         }
 
@@ -116,7 +128,7 @@ public abstract class ConfigurationPlugi
                 _logger.info("Elements to lookup:" + path);
                 for (String tag : elements)
                 {
-                    _logger.info(tag);
+                    _logger.info("Tag:'"+tag+"'");
                 }
             }
         }

Added: qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java?rev=945681&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java (added)
+++ qpid/trunk/qpid/java/broker/src/test/java/org/apache/qpid/server/configuration/plugins/ConfigurationPluginTest.java Tue May 18 14:44:06 2010
@@ -0,0 +1,94 @@
+/*
+ *
+ * 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.qpid.server.configuration.plugins;
+
+import junit.framework.TestCase;
+import org.apache.commons.configuration.CompositeConfiguration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+
+/**
+ * Test that verifies that given a configuration the
+ * Plugin manager
+ */
+public class ConfigurationPluginTest extends TestCase
+{
+
+    class ConfigPlugin extends ConfigurationPlugin
+    {
+        @Override
+        public String[] getElementsProcessed()
+        {
+                return new String[]{"[@property]", "name"};
+        }
+
+        public String getName()
+        {
+            return _configuration.getString("name");
+        }
+
+        public String getProperty()
+        {
+            return _configuration.getString("[@property]");
+        }
+
+
+    }
+
+    Configuration _configuration;
+
+    public void setUp()
+    {
+        XMLConfiguration xmlconfig = new XMLConfiguration();
+        xmlconfig.addProperty("base.element[@property]","property");
+        xmlconfig.addProperty("base.element.name","name");
+
+        //Use a composite configuration as this is what our broker code uses.
+        CompositeConfiguration composite  = new CompositeConfiguration();
+        composite.addConfiguration(xmlconfig);
+
+        _configuration = composite;
+    }
+
+
+    public void testValuesRetreived()
+    {
+       ConfigPlugin plugin = new ConfigPlugin();
+
+        try
+        {
+            plugin.setConfiguration("base.element", _configuration.subset("base.element"));
+        }
+        catch (ConfigurationException e)
+        {
+            e.printStackTrace();
+            fail(e.toString());
+        }
+
+        assertEquals("Name not correct","name",plugin.getName());
+        assertEquals("Property not correct","property",plugin.getProperty());
+    }
+
+
+
+
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org