INT-878 The sub-elements of <header-enricher/> now support a "type" attribute.

This commit is contained in:
Mark Fisher
2009-11-25 19:28:55 +00:00
parent 63b657b52a
commit 641675bbe4
4 changed files with 79 additions and 13 deletions

View File

@@ -38,6 +38,10 @@
<correlation-id value="ABC"/>
</header-enricher>
<header-enricher input-channel="correlationIdValueWithTypeInput">
<correlation-id value="123" type="java.lang.Long"/>
</header-enricher>
<header-enricher input-channel="correlationIdRefInput">
<correlation-id ref="testCorrelationId"/>
</header-enricher>
@@ -70,4 +74,12 @@
<header name="testHeader2" expression="headers.testHeader1 + 'bar'"/>
</header-enricher>
<header-enricher input-channel="expressionWithDateTypeInput">
<header name="currentDate" expression="new java.util.Date()" type="java.util.Date"/>
</header-enricher>
<header-enricher input-channel="expressionWithLongTypeInput">
<header name="number" expression="12345" type="java.lang.Long"/>
</header-enricher>
</beans:beans>

View File

@@ -18,6 +18,9 @@ package org.springframework.integration.config.xml;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -80,6 +83,17 @@ public class HeaderEnricherTests {
assertEquals("ABC", result.getHeaders().getCorrelationId());
}
@Test
public void correlationIdValueWithType() {
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
gateway.setRequestChannel(context.getBean("correlationIdValueWithTypeInput", MessageChannel.class));
Message<?> result = gateway.sendAndReceiveMessage("test");
assertNotNull(result);
Object correlationId = result.getHeaders().getCorrelationId();
assertEquals(Long.class, correlationId.getClass());
assertEquals(new Long(123), correlationId);
}
@Test
public void correlationIdRef() {
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
@@ -135,6 +149,28 @@ public class HeaderEnricherTests {
assertEquals("foobar", result.getHeaders().get("testHeader2"));
}
@Test
public void expressionWithDateType() {
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
gateway.setRequestChannel(context.getBean("expressionWithDateTypeInput", MessageChannel.class));
Message<?> result = gateway.sendAndReceiveMessage("test");
assertNotNull(result);
Object headerValue = result.getHeaders().get("currentDate");
assertEquals(Date.class, headerValue.getClass());
Date date = (Date) headerValue;
assertTrue(new Date().getTime() - date.getTime() < 1000);
}
@Test
public void expressionWithLongType() {
SimpleMessagingGateway gateway = new SimpleMessagingGateway();
gateway.setRequestChannel(context.getBean("expressionWithLongTypeInput", MessageChannel.class));
Message<?> result = gateway.sendAndReceiveMessage("test");
assertNotNull(result);
assertEquals(Long.class, result.getHeaders().get("number").getClass());
assertEquals(new Long(12345), result.getHeaders().get("number"));
}
public static class TestBean {