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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.pnfsimulator.netconfmonitor;
23 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.Mockito.never;
25 import static org.mockito.Mockito.verify;
26 import static org.mockito.Mockito.when;
28 import com.tailf.jnc.JNCException;
29 import java.io.IOException;
30 import org.junit.jupiter.api.BeforeEach;
31 import org.junit.jupiter.api.Test;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationCache;
35 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationReader;
36 import org.onap.pnfsimulator.netconfmonitor.netconf.NetconfConfigurationWriter;
38 class NetconfConfigurationCheckingTaskTest {
40 private NetconfConfigurationCheckingTask checkingTask;
43 private NetconfConfigurationReader reader;
45 private NetconfConfigurationWriter writer;
47 private NetconfConfigurationCache cache;
51 MockitoAnnotations.initMocks(this);
52 checkingTask = new NetconfConfigurationCheckingTask(reader, writer, cache);
56 void run_should_update_configuration_when_changed() throws IOException, JNCException {
57 String configuration = "newConfiguration";
58 when(reader.read()).thenReturn(configuration);
59 when(cache.getConfiguration()).thenReturn("oldConfiguration");
63 verify(reader).read();
64 verify(cache).getConfiguration();
65 verify(writer).writeToFile(configuration);
66 verify(cache).update(configuration);
70 void run_should_not_update_configuration_when_same() throws IOException, JNCException {
71 String configuration = "configuration";
72 when(reader.read()).thenReturn(configuration);
73 when(cache.getConfiguration()).thenReturn("configuration");
77 verify(reader).read();
78 verify(cache).getConfiguration();
79 verify(writer, never()).writeToFile(configuration);
80 verify(cache, never()).update(configuration);
84 void run_should_not_take_any_action_when_failed_to_read_configuration() throws IOException, JNCException {
85 when(reader.read()).thenThrow(new IOException());
89 verify(reader).read();
90 verify(cache, never()).getConfiguration();
91 verify(writer, never()).writeToFile(any());
92 verify(cache, never()).update(any());