2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Samsung
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.adapter.netconf.internal;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.Mockito;
28 import org.onap.appc.adapter.netconf.ConnectionDetails;
29 import org.onap.appc.adapter.netconf.NetconfConnectionDetails;
30 import org.onap.ccsdk.sli.core.dblib.DbLibService;
32 import javax.sql.rowset.CachedRowSet;
33 import java.io.IOException;
34 import java.io.PrintWriter;
35 import java.sql.Connection;
36 import java.sql.SQLException;
37 import java.sql.SQLFeatureNotSupportedException;
38 import java.util.ArrayList;
39 import java.util.logging.Logger;
41 public class TestNetconfDataAccessServiceImpl {
42 NetconfDataAccessServiceImpl netconfDataAccessService;
43 private String schema;
44 private DbLibService dbLibServiceMocked;
48 schema = "test-netconf-adaptor";
49 dbLibServiceMocked = new DbLibService() {
51 public CachedRowSet getData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
52 CachedRowSet cachedRowSetMocked = Mockito.mock(CachedRowSet.class);
53 return cachedRowSetMocked;
57 public boolean writeData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
62 public boolean isActive() {
67 public Connection getConnection() throws SQLException {
72 public Connection getConnection(String username, String password) throws SQLException {
77 public <T> T unwrap(Class<T> iface) throws SQLException {
82 public boolean isWrapperFor(Class<?> iface) throws SQLException {
87 public PrintWriter getLogWriter() throws SQLException {
92 public void setLogWriter(PrintWriter out) throws SQLException {
97 public int getLoginTimeout() throws SQLException {
102 public void setLoginTimeout(int seconds) throws SQLException {
107 public Logger getParentLogger() throws SQLFeatureNotSupportedException {
112 netconfDataAccessService = new NetconfDataAccessServiceImpl();
113 netconfDataAccessService.setSchema(schema);
114 netconfDataAccessService.setDbLibService(dbLibServiceMocked);
118 public void testRetrieveConfigFileName() throws IOException {
119 String response = netconfDataAccessService.retrieveConfigFileName("test");
121 Assert.assertEquals("", response);
125 public void testRetrieveConnectionDetails() throws IOException {
126 ConnectionDetails netconfConnectionDetails = new ConnectionDetails();
128 boolean response = netconfDataAccessService.retrieveConnectionDetails("test", netconfConnectionDetails);
130 Assert.assertEquals(false, response);
134 public void testRetrieveNetconfConnectionDetails() throws IOException {
135 NetconfConnectionDetails netconfConnectionDetails = new NetconfConnectionDetails();
137 boolean response = netconfDataAccessService.retrieveNetconfConnectionDetails("test", netconfConnectionDetails);
139 Assert.assertEquals(true, response);
143 public void testLogDeviceInteraction() throws IOException {
144 NetconfConnectionDetails netconfConnectionDetails = new NetconfConnectionDetails();
146 boolean response = netconfDataAccessService.logDeviceInteraction("test", "",
149 Assert.assertEquals(true, response);