371bdd84bdd4e633a93683f660c20c3fc794879b
[integration.git] /
1 /*
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
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.netconfsimulator.netconfcore.configuration;
22
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;
34
35 import java.io.ByteArrayInputStream;
36 import java.io.IOException;
37 import java.nio.file.Files;
38
39 import static org.mockito.Mockito.verify;
40 import static org.mockito.MockitoAnnotations.initMocks;
41
42 class NetconfConfigurationEditorTest {
43
44     @Mock
45     private NetconfSession session;
46     @Mock
47     private NetconfSessionHelper netconfSessionHelper;
48
49     private NetconfConfigurationEditor editor;
50
51     @BeforeEach
52     void setUp() throws IOException, JNCException {
53         initMocks(this);
54         NetconfConnectionParams params = null;
55         Mockito.when(netconfSessionHelper.createNetconfSession(params)).thenReturn(session);
56         editor = new NetconfConfigurationEditor(params, netconfSessionHelper);
57     }
58
59     @Test
60     void testShouldEditConfigSuccessfully() throws IOException, JNCException {
61         byte[] bytes =
62                 Files.readAllBytes(ResourceUtils.getFile("classpath:updatedConfig.xml").toPath());
63         Element editConfigXml = new XMLParser().parse(new InputSource(new ByteArrayInputStream(bytes)));
64
65         editor.editConfig(editConfigXml);
66
67         verify(session).editConfig(editConfigXml);
68     }
69 }