CAMEL-7109: Message attachments should preserve order using linked map. Thanks to Ronald Dehuysser for patch.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c4d27c5c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c4d27c5c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c4d27c5c Branch: refs/heads/camel-2.11.x Commit: c4d27c5c5c4d09803c85ddc90e38ad3cace52f0b Parents: 2e9d121 Author: Claus Ibsen <davscl...@apache.org> Authored: Tue Jan 7 10:29:45 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Tue Jan 7 10:30:26 2014 +0100 ---------------------------------------------------------------------- .../org/apache/camel/impl/DefaultMessage.java | 4 +- .../apache/camel/impl/DefaultMessageTest.java | 39 ++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c4d27c5c/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java index da60279..ebc8c25 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultMessage.java @@ -16,7 +16,7 @@ */ package org.apache.camel.impl; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; import javax.activation.DataHandler; @@ -205,7 +205,7 @@ public class DefaultMessage extends MessageSupport { * @return return a newly constructed Map */ protected Map<String, DataHandler> createAttachments() { - Map<String, DataHandler> map = new HashMap<String, DataHandler>(); + Map<String, DataHandler> map = new LinkedHashMap<String, DataHandler>(); populateInitialAttachments(map); return map; } http://git-wip-us.apache.org/repos/asf/camel/blob/c4d27c5c/camel-core/src/test/java/org/apache/camel/impl/DefaultMessageTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultMessageTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultMessageTest.java new file mode 100644 index 0000000..59b4cdc --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultMessageTest.java @@ -0,0 +1,39 @@ +/** + * 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.impl; + +import java.util.LinkedHashMap; +import java.util.Map; +import javax.activation.DataHandler; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; + +public class DefaultMessageTest { + + @Test + public void testAttachmentsAreSorted() { + DefaultMessage message = new DefaultMessage(); + + Map<String, DataHandler> attachments = message.createAttachments(); + + assertThat(attachments, instanceOf(LinkedHashMap.class)); + } + +}