Skip to content

Commit 86634d2

Browse files
committed
1 parent 7d16ab5 commit 86634d2

File tree

3 files changed

+139
-130
lines changed

3 files changed

+139
-130
lines changed

spring-integration-http/src/test/java/org/springframework/integration/http/config/HttpOutboundGatewayWithMethodExpression.java

Lines changed: 0 additions & 130 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<beans xmlns="http://www.springframework.org/schema/beans"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:int="http://www.springframework.org/schema/integration"
6+
xmlns:int-http="http://www.springframework.org/schema/integration/http"
7+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
8+
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
9+
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd">
10+
11+
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate"/>
12+
13+
<int-http:outbound-gateway url="/testApps/httpMethod"
14+
request-channel="requestChannel"
15+
reply-channel="replyChannel"
16+
rest-template="restTemplate"
17+
expected-response-type="java.lang.String"
18+
http-method-expression="payload"/>
19+
20+
<int-http:outbound-gateway url="/testApps/httpMethod"
21+
request-channel="defaultChannel"
22+
reply-channel="replyChannel"
23+
rest-template="restTemplate"
24+
expected-response-type="java.lang.String"/>
25+
26+
<int:channel id="replyChannel">
27+
<int:queue/>
28+
</int:channel>
29+
30+
</beans>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2002-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.http.config;
18+
19+
import static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertNotNull;
21+
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
22+
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
23+
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
24+
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
29+
import org.springframework.beans.factory.annotation.Autowired;
30+
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
31+
import org.springframework.context.support.ClassPathXmlApplicationContext;
32+
import org.springframework.http.HttpMethod;
33+
import org.springframework.http.MediaType;
34+
import org.springframework.messaging.Message;
35+
import org.springframework.messaging.MessageChannel;
36+
import org.springframework.messaging.PollableChannel;
37+
import org.springframework.messaging.support.GenericMessage;
38+
import org.springframework.test.annotation.DirtiesContext;
39+
import org.springframework.test.context.ContextConfiguration;
40+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41+
import org.springframework.test.web.client.MockRestServiceServer;
42+
import org.springframework.web.client.RestTemplate;
43+
44+
/**
45+
* @author Oleg Zhurakousky
46+
* @author Artem Bilan
47+
*
48+
* see https://jira.springsource.org/browse/INT-2397
49+
*/
50+
@RunWith(SpringJUnit4ClassRunner.class)
51+
@ContextConfiguration
52+
@DirtiesContext
53+
public class HttpOutboundGatewayWithMethodExpressionTests {
54+
55+
@Autowired
56+
private MessageChannel defaultChannel;
57+
58+
@Autowired
59+
private MessageChannel requestChannel;
60+
61+
@Autowired
62+
private PollableChannel replyChannel;
63+
64+
@Autowired
65+
private RestTemplate restTemplate;
66+
67+
private MockRestServiceServer mockServer;
68+
69+
@Before
70+
public void setup() {
71+
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
72+
}
73+
74+
@Test
75+
public void testDefaultMethod() throws Exception {
76+
this.mockServer.expect(requestTo("/testApps/httpMethod"))
77+
.andExpect(method(HttpMethod.POST))
78+
.andRespond(withSuccess(HttpMethod.POST.name(), MediaType.TEXT_PLAIN));
79+
80+
this.defaultChannel.send(new GenericMessage<String>("Hello"));
81+
Message<?> message = this.replyChannel.receive(5000);
82+
assertNotNull(message);
83+
assertEquals("POST", message.getPayload());
84+
85+
this.mockServer.verify();
86+
}
87+
88+
@Test
89+
public void testExplicitlySetMethod() throws Exception {
90+
this.mockServer.expect(requestTo("/testApps/httpMethod"))
91+
.andExpect(method(HttpMethod.GET))
92+
.andRespond(withSuccess(HttpMethod.GET.name(), MediaType.TEXT_PLAIN));
93+
94+
this.requestChannel.send(new GenericMessage<String>("GET"));
95+
Message<?> message = replyChannel.receive(5000);
96+
assertNotNull(message);
97+
assertEquals("GET", message.getPayload());
98+
99+
this.mockServer.verify();
100+
}
101+
102+
@Test(expected = BeanDefinitionParsingException.class)
103+
public void testMutuallyExclusivityInMethodAndMethodExpression() throws Exception {
104+
new ClassPathXmlApplicationContext(
105+
"http-outbound-gateway-with-httpmethod-expression-fail.xml", getClass())
106+
.close();
107+
}
108+
109+
}

0 commit comments

Comments
 (0)