4f5da33093a35eb7465f4177c915bef991cfb627
[integration.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. 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
21 package org.onap.pnfsimulator.netconfmonitor;
22
23 import static org.mockito.ArgumentMatchers.anyString;
24 import static org.mockito.Mockito.any;
25 import static org.mockito.Mockito.anyLong;
26 import static org.mockito.Mockito.doNothing;
27 import static org.mockito.Mockito.times;
28 import static org.mockito.Mockito.verify;
29 import static org.mockito.Mockito.when;
30
31 import com.tailf.jnc.JNCException;
32 import java.io.IOException;
33 import java.util.Timer;
34 import org.junit.jupiter.api.BeforeEach;
35 import org.junit.jupiter.api.Test;
36 import org.mockito.Mock;
37 import org.mockito.MockitoAnnotations;
38 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
39 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
40 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
41
42 class NetconfMonitorServiceTest {
43
44     private NetconfMonitorService service;
45
46     @Mock
47     private Timer timer;
48     @Mock
49     private NetconfConfigurationReader reader;
50     @Mock
51     private NetconfConfigurationWriter writer;
52     @Mock
53     private NetconfConfigurationCache cache;
54
55     @BeforeEach
56     void setup() {
57         MockitoAnnotations.initMocks(this);
58         service = new NetconfMonitorService(timer, reader, writer, cache);
59     }
60
61     @Test
62     void startNetconfService() throws IOException, JNCException {
63         when(reader.read()).thenReturn("message");
64         doNothing().when(writer).writeToFile(anyString());
65         doNothing().when(cache).update(anyString());
66
67         service.start();
68
69         verify(cache, times(1)).update(anyString());
70         verify(writer, times(1)).writeToFile(anyString());
71         verify(timer, times(1)).scheduleAtFixedRate(any(), anyLong(), anyLong());
72     }
73 }