INT-1232: added ParameterMapper

This commit is contained in:
David Syer
2010-07-15 14:35:04 +00:00
parent 5db5f5fb7a
commit 8311a10975
12 changed files with 209 additions and 19 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.http.mapper;
package org.springframework.integration.http;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

View File

@@ -0,0 +1,50 @@
/*
* Copyright 2002-2008 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.http;
import static org.junit.Assert.assertEquals;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.springframework.integration.message.GenericMessage;
/**
* @author Dave Syer
* @since 2.0
*
*/
public class DefaultParameterMapperTests {
@Test
public void testFromMessage() throws Exception {
DefaultParameterMapper mapper = new DefaultParameterMapper();
Map<String, ?> params = mapper.fromMessage(new GenericMessage<Object>(Collections.singletonMap("foo", "bar")));
assertEquals(1, params.size());
assertEquals("bar", params.get("foo"));
}
@Test
public void testFromMessageWithExpressions() throws Exception {
DefaultParameterMapper mapper = new DefaultParameterMapper();
mapper.setDynamicParameterExpressions(Collections.singletonMap("foo", "payload"));
Map<String, ?> params = mapper.fromMessage(new GenericMessage<Object>("bar"));
assertEquals(1, params.size());
assertEquals("bar", params.get("foo"));
}
}

View File

@@ -16,6 +16,7 @@
<outbound-channel-adapter id="fullConfig"
url="http://localhost/test2"
parameter-mapper="testParameterMapper"
http-method="GET"
channel="requests"
charset="UTF-8"
@@ -28,6 +29,8 @@
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
<beans:bean id="testParameterMapper" class="org.springframework.integration.http.DefaultParameterMapper"/>
<util:list id="converterList">
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>

View File

@@ -34,6 +34,7 @@ import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.http.DefaultOutboundRequestMapper;
import org.springframework.integration.http.HttpRequestExecutingMessageHandler;
import org.springframework.integration.http.OutboundRequestMapper;
import org.springframework.integration.http.ParameterMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -53,6 +54,9 @@ public class HttpOutboundChannelAdapterParserTests {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private ParameterMapper parameterMapper;
@Test
public void minimalConfig() {
@@ -101,6 +105,7 @@ public class HttpOutboundChannelAdapterParserTests {
assertEquals(HttpMethod.GET, handlerAccessor.getPropertyValue("httpMethod"));
assertEquals("UTF-8", mapperAccessor.getPropertyValue("charset"));
assertEquals(false, mapperAccessor.getPropertyValue("extractPayload"));
assertEquals(parameterMapper, handlerAccessor.getPropertyValue("parameterMapper"));
}
}

View File

@@ -22,6 +22,7 @@
<outbound-gateway id="fullConfig"
url="http://localhost/test2"
parameter-mapper="testParameterMapper"
http-method="PUT"
request-channel="requests"
request-factory="testRequestFactory"
@@ -36,6 +37,8 @@
<beans:bean id="testRequestFactory" class="org.springframework.http.client.SimpleClientHttpRequestFactory"/>
<beans:bean id="testParameterMapper" class="org.springframework.integration.http.DefaultParameterMapper"/>
<util:list id="converterList">
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>
<beans:bean class="org.springframework.integration.http.config.StubHttpMessageConverter"/>

View File

@@ -36,6 +36,7 @@ import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.http.DefaultOutboundRequestMapper;
import org.springframework.integration.http.HttpRequestExecutingMessageHandler;
import org.springframework.integration.http.OutboundRequestMapper;
import org.springframework.integration.http.ParameterMapper;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -55,6 +56,8 @@ public class HttpOutboundGatewayParserTests {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private ParameterMapper parameterMapper;
@Test
public void minimalConfig() {
@@ -111,6 +114,7 @@ public class HttpOutboundGatewayParserTests {
Object sendTimeout = new DirectFieldAccessor(
handlerAccessor.getPropertyValue("channelTemplate")).getPropertyValue("sendTimeout");
assertEquals(new Long("1234"), sendTimeout);
assertEquals(parameterMapper, handlerAccessor.getPropertyValue("parameterMapper"));
}
}