17
17
import static org .junit .Assert .assertFalse ;
18
18
import static org .junit .Assert .assertTrue ;
19
19
import static org .junit .Assert .fail ;
20
+ import static org .mockito .ArgumentMatchers .any ;
20
21
import static org .mockito .ArgumentMatchers .anyLong ;
22
+ import static org .mockito .ArgumentMatchers .eq ;
21
23
import static org .mockito .Mockito .doAnswer ;
22
24
import static org .mockito .Mockito .doThrow ;
23
25
import static org .mockito .Mockito .mock ;
24
26
import static org .mockito .Mockito .spy ;
27
+ import static org .mockito .Mockito .timeout ;
25
28
import static org .mockito .Mockito .times ;
26
29
import static org .mockito .Mockito .verify ;
27
30
import static org .mockito .Mockito .when ;
45
48
import org .eclipse .kura .message .store .StoredMessage ;
46
49
import org .eclipse .kura .message .store .provider .MessageStore ;
47
50
import org .eclipse .kura .message .store .provider .MessageStoreProvider ;
51
+ import org .eclipse .kura .status .CloudConnectionStatusComponent ;
48
52
import org .eclipse .kura .status .CloudConnectionStatusEnum ;
49
53
import org .eclipse .kura .status .CloudConnectionStatusService ;
50
54
import org .eclipse .kura .watchdog .WatchdogService ;
53
57
import org .junit .Test ;
54
58
import org .mockito .ArgumentMatchers ;
55
59
import org .mockito .Mockito ;
60
+ import org .mockito .verification .VerificationMode ;
56
61
import org .osgi .framework .BundleContext ;
57
62
import org .osgi .service .component .ComponentContext ;
58
63
59
64
public class DataServiceImplTest {
60
65
61
66
private DataServiceImpl dataServiceImpl ;
62
67
private DataTransportService dataTransportServiceMock ;
68
+ private CloudConnectionStatusService ccssMock ;
63
69
private Map <String , Object > properties ;
64
70
private Optional <Exception > exception = Optional .empty ();
65
71
private final MessageStoreProvider messageStoreProvider = Mockito .mock (MessageStoreProvider .class );
@@ -151,6 +157,21 @@ public void shouldStoreMessagesWithPayloadSizeEqualThanConfiguredThreshold() thr
151
157
thenNoExceptionIsTrown ();
152
158
thenMessageIsStored (0 , "foo" , new byte [4 ], 0 , false , 9 );
153
159
}
160
+
161
+ @ Test
162
+ public void shouldNotDisconnectOnConfigChange () throws KuraStoreException {
163
+ givenDataService ();
164
+ givenMessageStoreProvider ();
165
+ givenDataTrasportServiceDisconnected ();
166
+ givenConfigurationProperty ("connect.auto-on-startup" , true );
167
+ givenIsActive ();
168
+ givenDataTrasportServiceConnected ();
169
+
170
+ whenConfigurationIsChanged ("enable.recovery.on.connection.failure" , true );
171
+
172
+ thenDataTrasportStaysConnected ();
173
+ thenCloudConnectionStatusServiceIsNotChanged ();
174
+ }
154
175
155
176
@ Test
156
177
public void shouldNotStoreMessagesWithPayloadSizeGreaterThanConfiguredThreshold () throws KuraStoreException {
@@ -225,7 +246,7 @@ private void givenDataService() {
225
246
DataServiceOptions dataServiceOptions = new DataServiceOptions (Collections .emptyMap ());
226
247
MessageStoreProvider messageStoreProviderMock = mock (MessageStoreProvider .class );
227
248
MessageStore messageStoreMock = mock (MessageStore .class );
228
- CloudConnectionStatusService ccssMock = mock (CloudConnectionStatusService .class );
249
+ this . ccssMock = mock (CloudConnectionStatusService .class );
229
250
WatchdogService watchdogServiceMock = mock (WatchdogService .class );
230
251
initMockMessageStore (messageStoreProviderMock , messageStoreMock );
231
252
TestUtil .setFieldValue (this .dataServiceImpl , "dataServiceOptions" , dataServiceOptions );
@@ -237,6 +258,11 @@ private void givenDataService() {
237
258
}
238
259
239
260
}
261
+
262
+ private void whenConfigurationIsChanged (final String key , final Object value ) {
263
+ this .properties .put (key , value );
264
+ this .dataServiceImpl .updated (properties );
265
+ }
240
266
241
267
private void whenMessageIsPublished (final String topic , final byte [] payload , final int qos , final boolean retain ,
242
268
final int priority ) {
@@ -266,7 +292,19 @@ private void thenDataTrasportIsConnected() {
266
292
fail ();
267
293
}
268
294
}
295
+
296
+ private void thenDataTrasportStaysConnected () {
297
+ try {
298
+ verify (this .dataTransportServiceMock , times (0 )).connect ();
299
+ } catch (KuraConnectException e ) {
300
+ fail ();
301
+ }
302
+ }
269
303
304
+ private void thenCloudConnectionStatusServiceIsNotChanged () {
305
+ verify (this .ccssMock , times (1 )).updateStatus (any (CloudConnectionStatusComponent .class ), eq (CloudConnectionStatusEnum .SLOW_BLINKING ));
306
+ }
307
+
270
308
private void thenStartConnectionTaskIsInvoked () {
271
309
verify (this .dataServiceImpl , times (2 )).startConnectionTask ();
272
310
}
0 commit comments