|
1 | 1 | /* |
2 | | - * Copyright 2002-2017 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
80 | 80 | import org.springframework.integration.handler.MessageProcessor; |
81 | 81 | import org.springframework.integration.mqtt.core.ConsumerStopAction; |
82 | 82 | import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory; |
83 | | -import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory.Will; |
84 | 83 | import org.springframework.integration.mqtt.event.MqttConnectionFailedEvent; |
85 | 84 | import org.springframework.integration.mqtt.event.MqttIntegrationEvent; |
86 | 85 | import org.springframework.integration.mqtt.event.MqttSubscribedEvent; |
@@ -112,51 +111,23 @@ public class MqttAdapterTests { |
112 | 111 | this.alwaysComplete = (IMqttToken) pfb.getObject(); |
113 | 112 | } |
114 | 113 |
|
115 | | - @Test |
116 | | - public void testPahoConnectOptions() { |
117 | | - DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
118 | | - factory.setCleanSession(false); |
119 | | - factory.setConnectionTimeout(23); |
120 | | - factory.setKeepAliveInterval(45); |
121 | | - factory.setPassword("pass"); |
122 | | - SocketFactory socketFactory = mock(SocketFactory.class); |
123 | | - factory.setSocketFactory(socketFactory); |
124 | | - Properties props = new Properties(); |
125 | | - factory.setSslProperties(props); |
126 | | - factory.setUserName("user"); |
127 | | - Will will = new Will("foo", "bar".getBytes(), 2, true); |
128 | | - factory.setWill(will); |
129 | | - |
130 | | - MqttConnectOptions options = factory.getConnectionOptions(); |
131 | | - |
132 | | - assertEquals(23, options.getConnectionTimeout()); |
133 | | - assertEquals(45, options.getKeepAliveInterval()); |
134 | | - assertEquals("pass", new String(options.getPassword())); |
135 | | - assertSame(socketFactory, options.getSocketFactory()); |
136 | | - assertSame(props, options.getSSLProperties()); |
137 | | - assertEquals("user", options.getUserName()); |
138 | | - assertEquals("foo", options.getWillDestination()); |
139 | | - assertEquals("bar", new String(options.getWillMessage().getPayload())); |
140 | | - assertEquals(2, options.getWillMessage().getQos()); |
141 | | - |
142 | | - } |
143 | | - |
144 | 114 | @Test |
145 | 115 | public void testOutboundOptionsApplied() throws Exception { |
146 | 116 | DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
147 | | - factory.setCleanSession(false); |
148 | | - factory.setConnectionTimeout(23); |
149 | | - factory.setKeepAliveInterval(45); |
150 | | - factory.setPassword("pass"); |
| 117 | + MqttConnectOptions connectOptions = new MqttConnectOptions(); |
| 118 | + connectOptions.setCleanSession(false); |
| 119 | + connectOptions.setConnectionTimeout(23); |
| 120 | + connectOptions.setKeepAliveInterval(45); |
| 121 | + connectOptions.setPassword("pass".toCharArray()); |
151 | 122 | MemoryPersistence persistence = new MemoryPersistence(); |
152 | 123 | factory.setPersistence(persistence); |
153 | 124 | final SocketFactory socketFactory = mock(SocketFactory.class); |
154 | | - factory.setSocketFactory(socketFactory); |
| 125 | + connectOptions.setSocketFactory(socketFactory); |
155 | 126 | final Properties props = new Properties(); |
156 | | - factory.setSslProperties(props); |
157 | | - factory.setUserName("user"); |
158 | | - Will will = new Will("foo", "bar".getBytes(), 2, true); |
159 | | - factory.setWill(will); |
| 127 | + connectOptions.setSSLProperties(props); |
| 128 | + connectOptions.setUserName("user"); |
| 129 | + connectOptions.setWill("foo", "bar".getBytes(), 2, true); |
| 130 | + factory.setConnectionOptions(connectOptions); |
160 | 131 |
|
161 | 132 | factory = spy(factory); |
162 | 133 | final MqttAsyncClient client = mock(MqttAsyncClient.class); |
@@ -205,19 +176,20 @@ public void testOutboundOptionsApplied() throws Exception { |
205 | 176 | @Test |
206 | 177 | public void testInboundOptionsApplied() throws Exception { |
207 | 178 | DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
208 | | - factory.setCleanSession(false); |
209 | | - factory.setConnectionTimeout(23); |
210 | | - factory.setKeepAliveInterval(45); |
211 | | - factory.setPassword("pass"); |
| 179 | + MqttConnectOptions connectOptions = new MqttConnectOptions(); |
| 180 | + connectOptions.setCleanSession(false); |
| 181 | + connectOptions.setConnectionTimeout(23); |
| 182 | + connectOptions.setKeepAliveInterval(45); |
| 183 | + connectOptions.setPassword("pass".toCharArray()); |
212 | 184 | MemoryPersistence persistence = new MemoryPersistence(); |
213 | 185 | factory.setPersistence(persistence); |
214 | 186 | final SocketFactory socketFactory = mock(SocketFactory.class); |
215 | | - factory.setSocketFactory(socketFactory); |
| 187 | + connectOptions.setSocketFactory(socketFactory); |
216 | 188 | final Properties props = new Properties(); |
217 | | - factory.setSslProperties(props); |
218 | | - factory.setUserName("user"); |
219 | | - Will will = new Will("foo", "bar".getBytes(), 2, true); |
220 | | - factory.setWill(will); |
| 189 | + connectOptions.setSSLProperties(props); |
| 190 | + connectOptions.setUserName("user"); |
| 191 | + connectOptions.setWill("foo", "bar".getBytes(), 2, true); |
| 192 | + factory.setConnectionOptions(connectOptions); |
221 | 193 |
|
222 | 194 | factory = spy(factory); |
223 | 195 | final IMqttClient client = mock(IMqttClient.class); |
@@ -421,19 +393,19 @@ public void testReconnect() throws Exception { |
421 | 393 | @Test |
422 | 394 | public void testSubscribeFailure() throws Exception { |
423 | 395 | DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
424 | | - factory.setCleanSession(false); |
425 | | - factory.setConnectionTimeout(23); |
426 | | - factory.setKeepAliveInterval(45); |
427 | | - factory.setPassword("pass"); |
| 396 | + MqttConnectOptions connectOptions = new MqttConnectOptions(); |
| 397 | + connectOptions.setCleanSession(false); |
| 398 | + connectOptions.setConnectionTimeout(23); |
| 399 | + connectOptions.setKeepAliveInterval(45); |
| 400 | + connectOptions.setPassword("pass".toCharArray()); |
428 | 401 | MemoryPersistence persistence = new MemoryPersistence(); |
429 | 402 | factory.setPersistence(persistence); |
430 | 403 | final SocketFactory socketFactory = mock(SocketFactory.class); |
431 | | - factory.setSocketFactory(socketFactory); |
| 404 | + connectOptions.setSocketFactory(socketFactory); |
432 | 405 | final Properties props = new Properties(); |
433 | | - factory.setSslProperties(props); |
434 | | - factory.setUserName("user"); |
435 | | - Will will = new Will("foo", "bar".getBytes(), 2, true); |
436 | | - factory.setWill(will); |
| 406 | + connectOptions.setSSLProperties(props); |
| 407 | + connectOptions.setUserName("user"); |
| 408 | + connectOptions.setWill("foo", "bar".getBytes(), 2, true); |
437 | 409 |
|
438 | 410 | factory = spy(factory); |
439 | 411 | MqttAsyncClient aClient = mock(MqttAsyncClient.class); |
@@ -471,19 +443,19 @@ public void testSubscribeFailure() throws Exception { |
471 | 443 | @Test |
472 | 444 | public void testDifferentQos() throws Exception { |
473 | 445 | DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory(); |
474 | | - factory.setCleanSession(false); |
475 | | - factory.setConnectionTimeout(23); |
476 | | - factory.setKeepAliveInterval(45); |
477 | | - factory.setPassword("pass"); |
| 446 | + MqttConnectOptions connectOptions = new MqttConnectOptions(); |
| 447 | + connectOptions.setCleanSession(false); |
| 448 | + connectOptions.setConnectionTimeout(23); |
| 449 | + connectOptions.setKeepAliveInterval(45); |
| 450 | + connectOptions.setPassword("pass".toCharArray()); |
478 | 451 | MemoryPersistence persistence = new MemoryPersistence(); |
479 | 452 | factory.setPersistence(persistence); |
480 | 453 | final SocketFactory socketFactory = mock(SocketFactory.class); |
481 | | - factory.setSocketFactory(socketFactory); |
| 454 | + connectOptions.setSocketFactory(socketFactory); |
482 | 455 | final Properties props = new Properties(); |
483 | | - factory.setSslProperties(props); |
484 | | - factory.setUserName("user"); |
485 | | - Will will = new Will("foo", "bar".getBytes(), 2, true); |
486 | | - factory.setWill(will); |
| 456 | + connectOptions.setSSLProperties(props); |
| 457 | + connectOptions.setUserName("user"); |
| 458 | + connectOptions.setWill("foo", "bar".getBytes(), 2, true); |
487 | 459 |
|
488 | 460 | factory = spy(factory); |
489 | 461 | MqttAsyncClient aClient = mock(MqttAsyncClient.class); |
@@ -526,13 +498,15 @@ public IMqttClient getClientInstance(String uri, String clientId) throws MqttExc |
526 | 498 | } |
527 | 499 |
|
528 | 500 | }; |
529 | | - factory.setServerURIs("tcp://localhost:1883"); |
| 501 | + MqttConnectOptions connectOptions = new MqttConnectOptions(); |
| 502 | + connectOptions.setServerURIs(new String[] { "tcp://localhost:1883" }); |
530 | 503 | if (cleanSession != null) { |
531 | | - factory.setCleanSession(cleanSession); |
| 504 | + connectOptions.setCleanSession(cleanSession); |
532 | 505 | } |
533 | 506 | if (action != null) { |
534 | 507 | factory.setConsumerStopAction(action); |
535 | 508 | } |
| 509 | + factory.setConnectionOptions(connectOptions); |
536 | 510 | given(client.isConnected()).willReturn(true); |
537 | 511 | MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("client", factory, "foo"); |
538 | 512 | adapter.setApplicationEventPublisher(mock(ApplicationEventPublisher.class)); |
|
0 commit comments