| 
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.  | 
 | 
69 | 69 | import org.springframework.integration.channel.QueueChannel;  | 
70 | 70 | import org.springframework.integration.mqtt.core.ConsumerStopAction;  | 
71 | 71 | import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;  | 
72 |  | -import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory.Will;  | 
73 | 72 | import org.springframework.integration.mqtt.event.MqttConnectionFailedEvent;  | 
74 | 73 | import org.springframework.integration.mqtt.event.MqttIntegrationEvent;  | 
75 | 74 | import org.springframework.integration.mqtt.event.MqttSubscribedEvent;  | 
@@ -99,51 +98,23 @@ public class MqttAdapterTests {  | 
99 | 98 | 		this.alwaysComplete = (IMqttToken) pfb.getObject();  | 
100 | 99 | 	}  | 
101 | 100 | 
 
  | 
102 |  | -	@Test  | 
103 |  | -	public void testPahoConnectOptions() {  | 
104 |  | -		DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();  | 
105 |  | -		factory.setCleanSession(false);  | 
106 |  | -		factory.setConnectionTimeout(23);  | 
107 |  | -		factory.setKeepAliveInterval(45);  | 
108 |  | -		factory.setPassword("pass");  | 
109 |  | -		SocketFactory socketFactory = mock(SocketFactory.class);  | 
110 |  | -		factory.setSocketFactory(socketFactory);  | 
111 |  | -		Properties props = new Properties();  | 
112 |  | -		factory.setSslProperties(props);  | 
113 |  | -		factory.setUserName("user");  | 
114 |  | -		Will will = new Will("foo", "bar".getBytes(), 2, true);  | 
115 |  | -		factory.setWill(will);  | 
116 |  | - | 
117 |  | -		MqttConnectOptions options = factory.getConnectionOptions();  | 
118 |  | - | 
119 |  | -		assertEquals(23, options.getConnectionTimeout());  | 
120 |  | -		assertEquals(45, options.getKeepAliveInterval());  | 
121 |  | -		assertEquals("pass", new String(options.getPassword()));  | 
122 |  | -		assertSame(socketFactory, options.getSocketFactory());  | 
123 |  | -		assertSame(props, options.getSSLProperties());  | 
124 |  | -		assertEquals("user", options.getUserName());  | 
125 |  | -		assertEquals("foo", options.getWillDestination());  | 
126 |  | -		assertEquals("bar", new String(options.getWillMessage().getPayload()));  | 
127 |  | -		assertEquals(2, options.getWillMessage().getQos());  | 
128 |  | - | 
129 |  | -	}  | 
130 |  | - | 
131 | 101 | 	@Test  | 
132 | 102 | 	public void testOutboundOptionsApplied() throws Exception {  | 
133 | 103 | 		DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();  | 
134 |  | -		factory.setCleanSession(false);  | 
135 |  | -		factory.setConnectionTimeout(23);  | 
136 |  | -		factory.setKeepAliveInterval(45);  | 
137 |  | -		factory.setPassword("pass");  | 
 | 104 | +		MqttConnectOptions connectOptions = new MqttConnectOptions();  | 
 | 105 | +		connectOptions.setCleanSession(false);  | 
 | 106 | +		connectOptions.setConnectionTimeout(23);  | 
 | 107 | +		connectOptions.setKeepAliveInterval(45);  | 
 | 108 | +		connectOptions.setPassword("pass".toCharArray());  | 
138 | 109 | 		MemoryPersistence persistence = new MemoryPersistence();  | 
139 | 110 | 		factory.setPersistence(persistence);  | 
140 | 111 | 		final SocketFactory socketFactory = mock(SocketFactory.class);  | 
141 |  | -		factory.setSocketFactory(socketFactory);  | 
 | 112 | +		connectOptions.setSocketFactory(socketFactory);  | 
142 | 113 | 		final Properties props = new Properties();  | 
143 |  | -		factory.setSslProperties(props);  | 
144 |  | -		factory.setUserName("user");  | 
145 |  | -		Will will = new Will("foo", "bar".getBytes(), 2, true);  | 
146 |  | -		factory.setWill(will);  | 
 | 114 | +		connectOptions.setSSLProperties(props);  | 
 | 115 | +		connectOptions.setUserName("user");  | 
 | 116 | +		connectOptions.setWill("foo", "bar".getBytes(), 2, true);  | 
 | 117 | +		factory.setConnectionOptions(connectOptions);  | 
147 | 118 | 
 
  | 
148 | 119 | 		factory = spy(factory);  | 
149 | 120 | 		final MqttAsyncClient client = mock(MqttAsyncClient.class);  | 
@@ -192,19 +163,20 @@ public void testOutboundOptionsApplied() throws Exception {  | 
192 | 163 | 	@Test  | 
193 | 164 | 	public void testInboundOptionsApplied() throws Exception {  | 
194 | 165 | 		DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();  | 
195 |  | -		factory.setCleanSession(false);  | 
196 |  | -		factory.setConnectionTimeout(23);  | 
197 |  | -		factory.setKeepAliveInterval(45);  | 
198 |  | -		factory.setPassword("pass");  | 
 | 166 | +		MqttConnectOptions connectOptions = new MqttConnectOptions();  | 
 | 167 | +		connectOptions.setCleanSession(false);  | 
 | 168 | +		connectOptions.setConnectionTimeout(23);  | 
 | 169 | +		connectOptions.setKeepAliveInterval(45);  | 
 | 170 | +		connectOptions.setPassword("pass".toCharArray());  | 
199 | 171 | 		MemoryPersistence persistence = new MemoryPersistence();  | 
200 | 172 | 		factory.setPersistence(persistence);  | 
201 | 173 | 		final SocketFactory socketFactory = mock(SocketFactory.class);  | 
202 |  | -		factory.setSocketFactory(socketFactory);  | 
 | 174 | +		connectOptions.setSocketFactory(socketFactory);  | 
203 | 175 | 		final Properties props = new Properties();  | 
204 |  | -		factory.setSslProperties(props);  | 
205 |  | -		factory.setUserName("user");  | 
206 |  | -		Will will = new Will("foo", "bar".getBytes(), 2, true);  | 
207 |  | -		factory.setWill(will);  | 
 | 176 | +		connectOptions.setSSLProperties(props);  | 
 | 177 | +		connectOptions.setUserName("user");  | 
 | 178 | +		connectOptions.setWill("foo", "bar".getBytes(), 2, true);  | 
 | 179 | +		factory.setConnectionOptions(connectOptions);  | 
208 | 180 | 
 
  | 
209 | 181 | 		factory = spy(factory);  | 
210 | 182 | 		final IMqttClient client = mock(IMqttClient.class);  | 
@@ -390,13 +362,15 @@ public IMqttClient getClientInstance(String uri, String clientId) throws MqttExc  | 
390 | 362 | 			}  | 
391 | 363 | 
 
  | 
392 | 364 | 		};  | 
393 |  | -		factory.setServerURIs("tcp://localhost:1883");  | 
 | 365 | +		MqttConnectOptions connectOptions = new MqttConnectOptions();  | 
 | 366 | +		connectOptions.setServerURIs(new String[] { "tcp://localhost:1883" });  | 
394 | 367 | 		if (cleanSession != null) {  | 
395 |  | -			factory.setCleanSession(cleanSession);  | 
 | 368 | +			connectOptions.setCleanSession(cleanSession);  | 
396 | 369 | 		}  | 
397 | 370 | 		if (action != null) {  | 
398 | 371 | 			factory.setConsumerStopAction(action);  | 
399 | 372 | 		}  | 
 | 373 | +		factory.setConnectionOptions(connectOptions);  | 
400 | 374 | 		given(client.isConnected()).willReturn(true);  | 
401 | 375 | 		MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("client", factory, "foo");  | 
402 | 376 | 		adapter.setApplicationEventPublisher(mock(ApplicationEventPublisher.class));  | 
 | 
0 commit comments