This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git

commit f480c674a8adf58ebb04c9cef4354ac74da6252e
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sun Jun 16 09:55:27 2019 +0200

    CAMEL-13650: Properties component - loadProperties to return properties in 
order
---
 .../properties/DefaultPropertiesResolver.java      |  1 +
 .../component/properties/PropertiesComponent.java  |  1 +
 .../org/apache/camel/util}/OrderedProperties.java  |  4 +-
 .../apache/camel/util/OrderedPropertiesTest.java   | 74 ++++++++++++++++++++++
 .../src/test/resources/application.properties      | 21 ++++++
 5 files changed, 98 insertions(+), 3 deletions(-)

diff --git 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
index f110cab..1e164ff 100644
--- 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
+++ 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/DefaultPropertiesResolver.java
@@ -30,6 +30,7 @@ import java.util.Properties;
 import org.apache.camel.CamelContext;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.util.IOHelper;
+import org.apache.camel.util.OrderedProperties;
 
 /**
  * Default {@link org.apache.camel.component.properties.PropertiesResolver} 
which can resolve properties
diff --git 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
index 61a7716..4ddea23 100644
--- 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
+++ 
b/components/camel-properties/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
@@ -37,6 +37,7 @@ import org.apache.camel.support.DefaultComponent;
 import org.apache.camel.support.LRUCacheFactory;
 import org.apache.camel.util.FilePathResolver;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.OrderedProperties;
 
 /**
  * The <a href="http://camel.apache.org/properties";>Properties Component</a> 
allows you to use property placeholders when defining Endpoint URIs
diff --git 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/OrderedProperties.java
 b/core/camel-util/src/main/java/org/apache/camel/util/OrderedProperties.java
similarity index 97%
rename from 
components/camel-properties/src/main/java/org/apache/camel/component/properties/OrderedProperties.java
rename to 
core/camel-util/src/main/java/org/apache/camel/util/OrderedProperties.java
index 5356084..a793ec4 100644
--- 
a/components/camel-properties/src/main/java/org/apache/camel/component/properties/OrderedProperties.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/OrderedProperties.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.properties;
+package org.apache.camel.util;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -34,8 +34,6 @@ import java.util.Vector;
  */
 public final class OrderedProperties extends Properties {
 
-    // TODO: Move to camel-util
-
     private final Map<String, String> map = new LinkedHashMap<>();
 
     public OrderedProperties() {
diff --git 
a/core/camel-util/src/test/java/org/apache/camel/util/OrderedPropertiesTest.java
 
b/core/camel-util/src/test/java/org/apache/camel/util/OrderedPropertiesTest.java
new file mode 100644
index 0000000..8d80ffa
--- /dev/null
+++ 
b/core/camel-util/src/test/java/org/apache/camel/util/OrderedPropertiesTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.camel.util;
+
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OrderedPropertiesTest extends Assert {
+
+    @Test
+    public void testOrdered() throws Exception {
+        Properties prop = new OrderedProperties();
+        prop.setProperty("c", "CCC");
+        prop.setProperty("d", "DDD");
+        prop.setProperty("e", "EEE");
+        prop.setProperty("b", "BBB");
+        prop.setProperty("a", "AAA");
+
+        assertEquals(5, prop.size());
+
+        Iterator it = prop.keySet().iterator();
+        assertEquals("c", it.next());
+        assertEquals("d", it.next());
+        assertEquals("e", it.next());
+        assertEquals("b", it.next());
+        assertEquals("a", it.next());
+
+        it = prop.values().iterator();
+        assertEquals("CCC", it.next());
+        assertEquals("DDD", it.next());
+        assertEquals("EEE", it.next());
+        assertEquals("BBB", it.next());
+        assertEquals("AAA", it.next());
+    }
+
+    @Test
+    public void testOrderedLoad() throws Exception {
+        Properties prop = new OrderedProperties();
+        
prop.load(OrderedPropertiesTest.class.getResourceAsStream("/application.properties"));
+
+        assertEquals(4, prop.size());
+
+        Iterator it = prop.keySet().iterator();
+        assertEquals("hello", it.next());
+        assertEquals("camel.component.seda.concurrent-consumers", it.next());
+        assertEquals("camel.component.seda.queueSize", it.next());
+        assertEquals("camel.component.direct.timeout", it.next());
+
+        // should be ordered values
+        it = prop.values().iterator();
+        assertEquals("World", it.next());
+        assertEquals("2", it.next());
+        assertEquals("500", it.next());
+        assertEquals("1234", it.next());
+    }
+
+}
diff --git a/core/camel-util/src/test/resources/application.properties 
b/core/camel-util/src/test/resources/application.properties
new file mode 100644
index 0000000..8d8fba7
--- /dev/null
+++ b/core/camel-util/src/test/resources/application.properties
@@ -0,0 +1,21 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+hello=World
+
+camel.component.seda.concurrent-consumers=2
+camel.component.seda.queueSize=500
+camel.component.direct.timeout=1234
\ No newline at end of file

Reply via email to