11/*
2- * Copyright 2002-2024 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
3131import org .springframework .expression .spel .standard .SpelExpression ;
3232import org .springframework .http .HttpMethod ;
3333import org .springframework .http .client .ClientHttpRequestFactory ;
34- import org .springframework .http .client .ClientHttpResponse ;
3534import org .springframework .http .client .SimpleClientHttpRequestFactory ;
3635import org .springframework .integration .endpoint .AbstractEndpoint ;
36+ import org .springframework .integration .endpoint .EventDrivenConsumer ;
3737import org .springframework .integration .endpoint .PollingConsumer ;
3838import org .springframework .integration .handler .advice .AbstractRequestHandlerAdvice ;
3939import org .springframework .integration .http .outbound .HttpRequestExecutingMessageHandler ;
4040import org .springframework .integration .test .util .TestUtils ;
4141import org .springframework .messaging .Message ;
4242import org .springframework .messaging .MessageChannel ;
43+ import org .springframework .messaging .MessageHandler ;
4344import org .springframework .messaging .support .GenericMessage ;
4445import org .springframework .test .annotation .DirtiesContext ;
4546import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
4849
4950import static org .assertj .core .api .Assertions .assertThat ;
5051import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
52+ import static org .mockito .Mockito .mock ;
5153
5254/**
5355 * @author Mark Fisher
5961@ DirtiesContext
6062public class HttpOutboundGatewayParserTests {
6163
64+ public static final ResponseErrorHandler mockResponseErrorHandler = mock ();
65+
6266 @ Autowired
6367 @ Qualifier ("minimalConfig" )
64- private AbstractEndpoint minimalConfigEndpoint ;
68+ private EventDrivenConsumer minimalConfigEndpoint ;
6569
6670 @ Autowired
6771 @ Qualifier ("fullConfig" )
68- private AbstractEndpoint fullConfigEndpoint ;
72+ private EventDrivenConsumer fullConfigEndpoint ;
6973
7074 @ Autowired
7175 @ Qualifier ("withUrlExpression" )
72- private AbstractEndpoint withUrlExpressionEndpoint ;
76+ private EventDrivenConsumer withUrlExpressionEndpoint ;
7377
7478 @ Autowired
7579 @ Qualifier ("withAdvice" )
76- private AbstractEndpoint withAdvice ;
80+ private EventDrivenConsumer withAdvice ;
7781
7882 @ Autowired
7983 @ Qualifier ("withPoller1" )
@@ -86,48 +90,41 @@ public class HttpOutboundGatewayParserTests {
8690
8791 @ Test
8892 public void minimalConfig () {
89- HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler ) new DirectFieldAccessor (
90- this .minimalConfigEndpoint ).getPropertyValue ("handler" );
91- MessageChannel requestChannel = (MessageChannel ) new DirectFieldAccessor (
92- this .minimalConfigEndpoint ).getPropertyValue ("inputChannel" );
93+ HttpRequestExecutingMessageHandler handler =
94+ (HttpRequestExecutingMessageHandler ) this .minimalConfigEndpoint .getHandler ();
95+ MessageChannel requestChannel = this .minimalConfigEndpoint .getInputChannel ();
9396 assertThat (requestChannel ).isEqualTo (this .applicationContext .getBean ("requests" ));
94- DirectFieldAccessor handlerAccessor = new DirectFieldAccessor (handler );
95- Object replyChannel = handlerAccessor .getPropertyValue ("outputChannel" );
97+ Object replyChannel = handler .getOutputChannel ();
9698 assertThat (replyChannel ).isNull ();
97- DirectFieldAccessor templateAccessor = new DirectFieldAccessor (handlerAccessor .getPropertyValue ("restTemplate" ));
98- ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory )
99- templateAccessor .getPropertyValue ("requestFactory" );
100- assertThat (requestFactory instanceof SimpleClientHttpRequestFactory ).isTrue ();
101- Expression uriExpression = (Expression ) handlerAccessor .getPropertyValue ("uriExpression" );
99+ Object requestFactory = TestUtils .getPropertyValue (handler , "restTemplate.requestFactory" );
100+ assertThat (requestFactory ).isInstanceOf (SimpleClientHttpRequestFactory .class );
101+ Expression uriExpression = TestUtils .getPropertyValue (handler , "uriExpression" , Expression .class );
102102 assertThat (uriExpression .getValue ()).isEqualTo ("http://localhost/test1" );
103103 assertThat (TestUtils .getPropertyValue (handler , "httpMethodExpression" , Expression .class ).getExpressionString ())
104104 .isEqualTo (HttpMethod .POST .name ());
105- assertThat (handlerAccessor .getPropertyValue ("charset" )).isEqualTo (StandardCharsets .UTF_8 );
106- assertThat (handlerAccessor .getPropertyValue ("extractPayload" )).isEqualTo (true );
107- assertThat (handlerAccessor .getPropertyValue ("transferCookies" )).isEqualTo (false );
105+ assertThat (TestUtils .getPropertyValue (handler , "charset" )).isEqualTo (StandardCharsets .UTF_8 );
106+ assertThat (TestUtils .getPropertyValue (handler , "extractPayload" )).isEqualTo (true );
107+ assertThat (TestUtils .getPropertyValue (handler , "transferCookies" )).isEqualTo (false );
108108 }
109109
110110 @ Test
111111 @ SuppressWarnings ("unchecked" )
112112 public void fullConfig () {
113113 DirectFieldAccessor endpointAccessor = new DirectFieldAccessor (this .fullConfigEndpoint );
114114 HttpRequestExecutingMessageHandler handler =
115- (HttpRequestExecutingMessageHandler ) endpointAccessor .getPropertyValue ("handler" );
116- MessageChannel requestChannel = (MessageChannel ) new DirectFieldAccessor (
117- this .fullConfigEndpoint ).getPropertyValue ("inputChannel" );
115+ (HttpRequestExecutingMessageHandler ) this .fullConfigEndpoint .getHandler ();
116+ MessageChannel requestChannel = this .fullConfigEndpoint .getInputChannel ();
118117 assertThat (requestChannel ).isEqualTo (this .applicationContext .getBean ("requests" ));
119118 DirectFieldAccessor handlerAccessor = new DirectFieldAccessor (handler );
120119 assertThat (handlerAccessor .getPropertyValue ("order" )).isEqualTo (77 );
121120 assertThat (endpointAccessor .getPropertyValue ("autoStartup" )).isEqualTo (Boolean .FALSE );
122121 Object replyChannel = handlerAccessor .getPropertyValue ("outputChannel" );
123122 assertThat (replyChannel ).isNotNull ();
124123 assertThat (replyChannel ).isEqualTo (this .applicationContext .getBean ("replies" ));
125- DirectFieldAccessor templateAccessor = new DirectFieldAccessor (handlerAccessor .getPropertyValue ("restTemplate" ));
126- ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory )
127- templateAccessor .getPropertyValue ("requestFactory" );
128- assertThat (requestFactory instanceof SimpleClientHttpRequestFactory ).isTrue ();
124+ Object requestFactory = TestUtils .getPropertyValue (handler , "restTemplate.requestFactory" );
125+ assertThat (requestFactory ).isInstanceOf (SimpleClientHttpRequestFactory .class );
129126 Object converterListBean = this .applicationContext .getBean ("converterList" );
130- assertThat (templateAccessor .getPropertyValue (" messageConverters" )).isEqualTo (converterListBean );
127+ assertThat (TestUtils .getPropertyValue (handler , "restTemplate. messageConverters" )).isEqualTo (converterListBean );
131128
132129 assertThat (TestUtils .getPropertyValue (handler , "expectedResponseTypeExpression" , Expression .class ).getValue ())
133130 .isEqualTo (String .class .getName ());
@@ -140,7 +137,7 @@ public void fullConfig() {
140137 Object requestFactoryBean = this .applicationContext .getBean ("testRequestFactory" );
141138 assertThat (requestFactory ).isEqualTo (requestFactoryBean );
142139 Object errorHandlerBean = this .applicationContext .getBean ("testErrorHandler" );
143- assertThat (templateAccessor .getPropertyValue (" errorHandler" )).isEqualTo (errorHandlerBean );
140+ assertThat (TestUtils .getPropertyValue (handler , "restTemplate. errorHandler" )).isEqualTo (errorHandlerBean );
144141 Object sendTimeout = new DirectFieldAccessor (
145142 handlerAccessor .getPropertyValue ("messagingTemplate" )).getPropertyValue ("sendTimeout" );
146143 assertThat (sendTimeout ).isEqualTo (1234L );
@@ -162,10 +159,9 @@ public void fullConfig() {
162159
163160 @ Test
164161 public void withUrlExpression () {
165- HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler ) new DirectFieldAccessor (
166- this .withUrlExpressionEndpoint ).getPropertyValue ("handler" );
167- MessageChannel requestChannel = (MessageChannel ) new DirectFieldAccessor (
168- this .withUrlExpressionEndpoint ).getPropertyValue ("inputChannel" );
162+ HttpRequestExecutingMessageHandler handler =
163+ (HttpRequestExecutingMessageHandler ) this .withUrlExpressionEndpoint .getHandler ();
164+ MessageChannel requestChannel = this .withUrlExpressionEndpoint .getInputChannel ();
169165 assertThat (requestChannel ).isEqualTo (this .applicationContext .getBean ("requests" ));
170166 DirectFieldAccessor handlerAccessor = new DirectFieldAccessor (handler );
171167 Object replyChannel = handlerAccessor .getPropertyValue ("outputChannel" );
@@ -194,8 +190,7 @@ public void withUrlExpression() {
194190
195191 @ Test
196192 public void withAdvice () {
197- HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler ) new DirectFieldAccessor (
198- this .withAdvice ).getPropertyValue ("handler" );
193+ MessageHandler handler = this .withAdvice .getHandler ();
199194 handler .handleMessage (new GenericMessage <>("foo" ));
200195 assertThat (adviceCalled ).isEqualTo (1 );
201196 }
@@ -214,19 +209,6 @@ public void withPoller() {
214209 assertThat (this .withPoller1 ).isInstanceOf (PollingConsumer .class );
215210 }
216211
217- public static class StubErrorHandler implements ResponseErrorHandler {
218-
219- @ Override
220- public boolean hasError (ClientHttpResponse response ) {
221- return false ;
222- }
223-
224- @ Override
225- public void handleError (ClientHttpResponse response ) {
226- }
227-
228- }
229-
230212 public static class FooAdvice extends AbstractRequestHandlerAdvice {
231213
232214 @ Override
0 commit comments