INT-2405 fix MessageProcessor for <header-value>

1. MethodInvokingHeaderValueMessageProcessor => MessageProcessingHeaderValueMessageProcessor because now he uses MessageProcessor
2. polishing HeaderEnricherParserSupport
3. GroovyHeaderEnricherTests: add check to HeaderValueMessageProcessor for Groovy scripts.
4. build.gradle: add dependency to 'spring-integration-test' for 'spring-integration-groovy'.
This commit is contained in:
Artem Bilan
2012-01-17 15:19:38 +02:00
committed by Mark Fisher
parent a55cb2c18b
commit 920e2f2f50
5 changed files with 53 additions and 18 deletions

View File

@@ -22,7 +22,7 @@
<int:channel id="inputB"/>
<int:header-enricher input-channel="inputB" output-channel="outputB">
<int:header-enricher id="headerEnricherWithInlineGroovyScript" input-channel="inputB" output-channel="outputB">
<int:header name="TEST_HEADER">
<int-groovy:script>
<![CDATA[

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2012 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.
@@ -17,6 +17,10 @@
package org.springframework.integration.groovy.config;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import org.hamcrest.Matchers;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -24,12 +28,18 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.groovy.GroovyScriptExecutingMessageProcessor;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.transformer.HeaderEnricher;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
* @since 2.0
*/
@ContextConfiguration
@@ -48,14 +58,26 @@ public class GroovyHeaderEnricherTests {
@Autowired
private QueueChannel outputB;
@Autowired
private EventDrivenConsumer headerEnricherWithInlineGroovyScript;
@Test
public void referencedScript() throws Exception{
inputA.send(new GenericMessage<String>("Hello"));
assertEquals("groovy", outputA.receive(1000).getHeaders().get("TEST_HEADER"));
}
@SuppressWarnings("unchecked")
@Test
public void inlineScript() throws Exception{
Map<String, HeaderEnricher.HeaderValueMessageProcessor> headers =
TestUtils.getPropertyValue(headerEnricherWithInlineGroovyScript, "handler.transformer.headersToAdd", Map.class);
assertEquals(1, headers.size());
HeaderEnricher.HeaderValueMessageProcessor headerValueMessageProcessor = headers.get("TEST_HEADER");
assertThat(headerValueMessageProcessor.getClass().getName(), Matchers.containsString("HeaderEnricher$MessageProcessingHeaderValueMessageProcessor"));
Object targetProcessor = TestUtils.getPropertyValue(headerValueMessageProcessor, "targetProcessor");
assertEquals(GroovyScriptExecutingMessageProcessor.class, targetProcessor.getClass());
inputB.send(new GenericMessage<String>("Hello"));
assertEquals("groovy", outputB.receive(1000).getHeaders().get("TEST_HEADER"));
}