2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================
5 * Copyright (C) 2018 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
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.netconfsimulator.netconfcore.configuration;
23 import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25 import static org.mockito.ArgumentMatchers.anyString;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
30 import com.tailf.jnc.Element;
31 import com.tailf.jnc.JNCException;
32 import com.tailf.jnc.NetconfSession;
33 import com.tailf.jnc.NodeSet;
34 import java.io.IOException;
35 import org.junit.jupiter.api.BeforeEach;
36 import org.junit.jupiter.api.Test;
37 import org.mockito.Mock;
38 import org.mockito.Mockito;
39 import org.mockito.MockitoAnnotations;
41 class NetconfConfigurationReaderTest {
43 private static final String NETCONF_MODEL_PATH = "";
44 private static final String EXPECTED_STRING_XML = "<?xml version=\"1.0\"?>";
45 private NetconfConfigurationReader reader;
48 private NetconfSession netconfSession;
51 private NetconfSessionHelper netconfSessionHelper;
54 private NodeSet nodeSet;
57 private Element element;
60 void setUp() throws IOException, JNCException {
61 MockitoAnnotations.initMocks(this);
62 NetconfConnectionParams params = null;
63 Mockito.when(netconfSessionHelper.createNetconfSession(params)).thenReturn(netconfSession);
64 reader = new NetconfConfigurationReader(params, netconfSessionHelper);
68 void properlyReadXML() throws IOException, JNCException {
69 when(netconfSession.getConfig()).thenReturn(nodeSet);
70 when(nodeSet.toXMLString()).thenReturn(EXPECTED_STRING_XML);
72 String result = reader.getRunningConfig();
74 verify(netconfSession).getConfig();
75 verify(nodeSet).toXMLString();
76 assertThat(result).isEqualTo(EXPECTED_STRING_XML);
80 void shouldProperlyReadXmlByName() throws IOException, JNCException {
81 when(netconfSession.getConfig("/sample:test")).thenReturn(nodeSet);
82 when(nodeSet.first()).thenReturn(element);
83 when(element.toXMLString()).thenReturn(EXPECTED_STRING_XML);
85 String result = reader.getRunningConfig("/sample:test");
87 verify(netconfSession).getConfig("/sample:test");
88 verify(nodeSet, times(2)).first();
89 verify(element).toXMLString();
91 assertThat(result).isEqualTo(EXPECTED_STRING_XML);