Added timestamp and methods to retrieve attribute and property names.

This commit is contained in:
Mark Fisher
2008-01-16 22:09:54 +00:00
parent 2ffae06824
commit 8225cb1405
2 changed files with 82 additions and 0 deletions

View File

@@ -17,8 +17,10 @@
package org.springframework.integration.message;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -36,6 +38,8 @@ public class MessageHeader {
private String replyChannelName;
private Date timestamp = new Date();
private Date expiration;
private int sequenceNumber = 1;
@@ -67,6 +71,10 @@ public class MessageHeader {
return this.sequenceNumber;
}
public Date getTimestamp() {
return this.timestamp;
}
/**
* Set the expiration date for this message or <code>null</code> to
* indicate 'never expire'. The default is <code>null</code>.
@@ -103,6 +111,14 @@ public class MessageHeader {
this.properties.setProperty(key, value);
}
public Set<String> getPropertyNames() {
Set<String> propertyNames = new HashSet<String>();
for (Object key : this.properties.keySet()) {
propertyNames.add((String) key);
}
return propertyNames;
}
public Object getAttribute(String key) {
return this.attributes.get(key);
}
@@ -111,4 +127,8 @@ public class MessageHeader {
this.attributes.put(key, value);
}
public Set<String> getAttributeNames() {
return this.attributes.keySet();
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2002-2007 the original author or authors.
*
* Licensed 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.springframework.integration.message;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import org.junit.Test;
/**
* @author Mark Fisher
*/
public class MessageHeaderTests {
@Test
public void testTimestamp() {
MessageHeader header = new MessageHeader();
assertNotNull(header.getTimestamp());
}
@Test
public void testAttributes() {
MessageHeader header = new MessageHeader();
Integer integer = new Integer(123);
header.setAttribute("test", integer);
assertEquals(integer, header.getAttribute("test"));
assertNull(header.getAttribute("nosuchattribute"));
Set<String> names = header.getAttributeNames();
assertEquals(1, names.size());
assertTrue(names.contains("test"));
}
@Test
public void testProperties() {
MessageHeader header = new MessageHeader();
header.setProperty("foo", "bar");
assertEquals("bar", header.getProperty("foo"));
assertNull(header.getProperty("nosuchproperty"));
Set<String> names = header.getPropertyNames();
assertEquals(1, names.size());
assertTrue(names.contains("foo"));
}
}