49132f1ef43fc9cfc9f06f7d6881abb6345b853b
[dcaegen2/collectors/ves.git] / src / test / java / org / onap / dcae / ApplicationConfigurationListenerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VES Collector
4  * ================================================================================
5  * Copyright (C) 2020 Nokia. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.dcae;
21
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.Mockito;
27 import org.mockito.Spy;
28 import org.mockito.junit.MockitoJUnitRunner;
29 import org.onap.dcae.configuration.ConfigurationHandler;
30
31 import java.time.Duration;
32
33 import static org.mockito.ArgumentMatchers.any;
34
35 @RunWith(MockitoJUnitRunner.class)
36 public class ApplicationConfigurationListenerTest {
37
38     @Mock
39     private ConfigurationHandler configurationHandler;
40
41     @InjectMocks
42     @Spy
43     private ApplicationConfigurationListener applicationConfigurationListener;
44
45     @Test
46     public void shouldStopJobAndCloseConnectionWhenErrorOccurredDuringListenAtConsulChange() {
47
48        // given
49        Mockito.doThrow(new RuntimeException("Simulate exception")).when(configurationHandler).startListen(any());
50
51        // when
52        applicationConfigurationListener.run();
53
54        // then
55         Mockito.verify(applicationConfigurationListener).stopListeningForConfigurationUpdates(any());
56     }
57
58     @Test
59     public void shouldSendReloadAction() {
60
61         // when
62         applicationConfigurationListener.reload(Duration.ofMillis(1));
63
64         // then
65         Mockito.verify(applicationConfigurationListener).sendReloadAction();
66     }
67 }