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 com.tailf.jnc.Element;
24 import com.tailf.jnc.JNCException;
25 import com.tailf.jnc.NetconfSession;
26 import com.tailf.jnc.XMLParser;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.mockito.Mock;
30 import org.mockito.Mockito;
31 import org.onap.netconfsimulator.netconfcore.configuration.NetconfConfigurationEditor;
32 import org.springframework.util.ResourceUtils;
33 import org.xml.sax.InputSource;
35 import java.io.ByteArrayInputStream;
36 import java.io.IOException;
37 import java.nio.file.Files;
39 import static org.mockito.Mockito.verify;
40 import static org.mockito.MockitoAnnotations.initMocks;
42 class NetconfConfigurationEditorTest {
45 private NetconfSession session;
47 private NetconfSessionHelper netconfSessionHelper;
49 private NetconfConfigurationEditor editor;
52 void setUp() throws IOException, JNCException {
54 NetconfConnectionParams params = null;
55 Mockito.when(netconfSessionHelper.createNetconfSession(params)).thenReturn(session);
56 editor = new NetconfConfigurationEditor(params, netconfSessionHelper);
60 void testShouldEditConfigSuccessfully() throws IOException, JNCException {
62 Files.readAllBytes(ResourceUtils.getFile("classpath:updatedConfig.xml").toPath());
63 Element editConfigXml = new XMLParser().parse(new InputSource(new ByteArrayInputStream(bytes)));
65 editor.editConfig(editConfigXml);
67 verify(session).editConfig(editConfigXml);