@@ -113,36 +113,7 @@ public void testSingleTopic() {
113113 MqttPahoMessageDrivenChannelAdapter inbound =
114114 new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (), "si-test-in" , "mqtt-foo" );
115115 QueueChannel outputChannel = new QueueChannel ();
116- inbound .setOutputChannel (outputChannel );
117- inbound .setTaskScheduler (taskScheduler );
118- inbound .setBeanFactory (mock (BeanFactory .class ));
119- inbound .afterPropertiesSet ();
120- inbound .start ();
121- adapter .handleMessage (new GenericMessage <>("foo" ));
122- Message <?> out = outputChannel .receive (20000 );
123- assertThat (out ).isNotNull ();
124- adapter .stop ();
125- inbound .stop ();
126- assertThat (out .getPayload ()).isEqualTo ("foo" );
127- assertThat (out .getHeaders ().get (MqttHeaders .RECEIVED_TOPIC )).isEqualTo ("mqtt-foo" );
128- assertThat (adapter .getConnectionInfo ().getServerURIs ()[0 ]).isEqualTo (MosquittoContainerTest .mqttUrl ());
129- }
130-
131- @ Test
132- void testSingleTopicWithQuiescentSet () {
133- MqttPahoMessageHandler adapter = new MqttPahoMessageHandler (MosquittoContainerTest .mqttUrl (), "si-test-out" );
134- adapter .setDefaultTopic ("mqtt-foo" );
135- adapter .setBeanFactory (mock (BeanFactory .class ));
136- adapter .afterPropertiesSet ();
137- adapter .start ();
138- MqttPahoMessageDrivenChannelAdapter inbound =
139- new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (), "si-test-in" , "mqtt-foo" );
140- QueueChannel outputChannel = new QueueChannel ();
141- inbound .setOutputChannel (outputChannel );
142- inbound .setTaskScheduler (taskScheduler );
143- inbound .setQuiescentTimeout (QUIESCENT_TIMEOUT );
144- inbound .setDisconnectCompletionTimeout (DISCONNECT_COMPLETION_TIMEOUT );
145- inbound .setBeanFactory (mock (BeanFactory .class ));
116+ initializeInboundAdapter (inbound , outputChannel );
146117 inbound .afterPropertiesSet ();
147118 inbound .start ();
148119 adapter .handleMessage (new GenericMessage <>("foo" ));
@@ -179,9 +150,7 @@ private void testJsonCommon(String... trusted) {
179150 MqttPahoMessageDrivenChannelAdapter inbound =
180151 new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (), "si-test-in" , "mqtt-foo" );
181152 QueueChannel outputChannel = new QueueChannel ();
182- inbound .setOutputChannel (outputChannel );
183- inbound .setTaskScheduler (taskScheduler );
184- inbound .setBeanFactory (mock (BeanFactory .class ));
153+ initializeInboundAdapter (inbound , outputChannel );
185154 inbound .setConverter (converter );
186155 inbound .afterPropertiesSet ();
187156 inbound .start ();
@@ -210,9 +179,7 @@ public void testAddRemoveTopic() {
210179 MqttPahoMessageDrivenChannelAdapter inbound =
211180 new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (), "si-test-in" );
212181 QueueChannel outputChannel = new QueueChannel ();
213- inbound .setOutputChannel (outputChannel );
214- inbound .setTaskScheduler (taskScheduler );
215- inbound .setBeanFactory (mock (BeanFactory .class ));
182+ initializeInboundAdapter (inbound , outputChannel );
216183 inbound .afterPropertiesSet ();
217184 inbound .start ();
218185 inbound .addTopic ("mqtt-foo" );
@@ -258,9 +225,7 @@ public void testTwoTopics() {
258225 new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (),
259226 "si-test-in" , "mqtt-foo" , "mqtt-bar" );
260227 QueueChannel outputChannel = new QueueChannel ();
261- inbound .setOutputChannel (outputChannel );
262- inbound .setTaskScheduler (taskScheduler );
263- inbound .setBeanFactory (mock (BeanFactory .class ));
228+ initializeInboundAdapter (inbound , outputChannel );
264229 inbound .afterPropertiesSet ();
265230 inbound .start ();
266231 adapter .handleMessage (new GenericMessage <>("foo" ));
@@ -293,9 +258,7 @@ public void testAsync() throws Exception {
293258 MqttPahoMessageDrivenChannelAdapter inbound =
294259 new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (), "si-test-in" , "mqtt-foo" );
295260 QueueChannel outputChannel = new QueueChannel ();
296- inbound .setOutputChannel (outputChannel );
297- inbound .setTaskScheduler (taskScheduler );
298- inbound .setBeanFactory (mock (BeanFactory .class ));
261+ initializeInboundAdapter (inbound , outputChannel );
299262 inbound .afterPropertiesSet ();
300263 inbound .start ();
301264 GenericMessage <String > message = new GenericMessage <>("foo" );
@@ -331,9 +294,7 @@ public void testAsyncPersisted() throws Exception {
331294 new MqttPahoMessageDrivenChannelAdapter (MosquittoContainerTest .mqttUrl (),
332295 "si-test-in" , "mqtt-foo" , "mqtt-bar" );
333296 QueueChannel outputChannel = new QueueChannel ();
334- inbound .setOutputChannel (outputChannel );
335- inbound .setTaskScheduler (taskScheduler );
336- inbound .setBeanFactory (mock (BeanFactory .class ));
297+ initializeInboundAdapter (inbound , outputChannel );
337298 inbound .afterPropertiesSet ();
338299 inbound .start ();
339300 Message <String > message1 = new GenericMessage <>("foo" );
@@ -428,6 +389,14 @@ public void onApplicationEvent(MqttSubscribedEvent event) {
428389
429390 }
430391
392+ private void initializeInboundAdapter (MqttPahoMessageDrivenChannelAdapter inbound , QueueChannel outputChannel ) {
393+ inbound .setOutputChannel (outputChannel );
394+ inbound .setTaskScheduler (taskScheduler );
395+ inbound .setQuiescentTimeout (QUIESCENT_TIMEOUT );
396+ inbound .setDisconnectCompletionTimeout (DISCONNECT_COMPLETION_TIMEOUT );
397+ inbound .setBeanFactory (mock (BeanFactory .class ));
398+ }
399+
431400 private class EventPublisher implements ApplicationEventPublisher {
432401
433402 private volatile MqttMessageDeliveredEvent delivered ;
0 commit comments