Test cases for Jsch client
[appc.git] / appc-adapters / appc-netconf-adapter / appc-netconf-adapter-bundle / src / test / java / org / onap / appc / adapter / netconf / internal / TestNetconfDataAccessServiceImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
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  *
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.adapter.netconf.internal;
23
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;
31
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;
40
41 public class TestNetconfDataAccessServiceImpl {
42     NetconfDataAccessServiceImpl netconfDataAccessService;
43     private String schema;
44     private DbLibService dbLibServiceMocked;
45
46     @Before
47     public void SetUp() {
48         schema = "test-netconf-adaptor";
49         dbLibServiceMocked = new DbLibService() {
50             @Override
51             public CachedRowSet getData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
52                 CachedRowSet cachedRowSetMocked = Mockito.mock(CachedRowSet.class);
53                 return cachedRowSetMocked;
54             }
55
56             @Override
57             public boolean writeData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
58                 return false;
59             }
60
61             @Override
62             public boolean isActive() {
63                 return false;
64             }
65
66             @Override
67             public Connection getConnection() throws SQLException {
68                 return null;
69             }
70
71             @Override
72             public Connection getConnection(String username, String password) throws SQLException {
73                 return null;
74             }
75
76             @Override
77             public <T> T unwrap(Class<T> iface) throws SQLException {
78                 return null;
79             }
80
81             @Override
82             public boolean isWrapperFor(Class<?> iface) throws SQLException {
83                 return false;
84             }
85
86             @Override
87             public PrintWriter getLogWriter() throws SQLException {
88                 return null;
89             }
90
91             @Override
92             public void setLogWriter(PrintWriter out) throws SQLException {
93
94             }
95
96             @Override
97             public int getLoginTimeout() throws SQLException {
98                 return 0;
99             }
100
101             @Override
102             public void setLoginTimeout(int seconds) throws SQLException {
103
104             }
105
106             @Override
107             public Logger getParentLogger() throws SQLFeatureNotSupportedException {
108                 return null;
109             }
110         };
111
112         netconfDataAccessService = new NetconfDataAccessServiceImpl();
113         netconfDataAccessService.setSchema(schema);
114         netconfDataAccessService.setDbLibService(dbLibServiceMocked);
115     }
116
117     @Test
118     public void testRetrieveConfigFileName() throws IOException {
119         String response = netconfDataAccessService.retrieveConfigFileName("test");
120
121         Assert.assertEquals("", response);
122     }
123
124     @Test
125     public void testRetrieveConnectionDetails() throws IOException {
126         ConnectionDetails netconfConnectionDetails = new ConnectionDetails();
127
128         boolean response = netconfDataAccessService.retrieveConnectionDetails("test", netconfConnectionDetails);
129
130         Assert.assertEquals(false, response);
131     }
132
133     @Test
134     public void testRetrieveNetconfConnectionDetails() throws IOException {
135         NetconfConnectionDetails netconfConnectionDetails = new NetconfConnectionDetails();
136
137         boolean response = netconfDataAccessService.retrieveNetconfConnectionDetails("test", netconfConnectionDetails);
138
139         Assert.assertEquals(true, response);
140     }
141
142     @Test
143     public void testLogDeviceInteraction() throws IOException {
144         NetconfConnectionDetails netconfConnectionDetails = new NetconfConnectionDetails();
145
146         boolean response = netconfDataAccessService.logDeviceInteraction("test", "",
147                                                                          "", "");
148
149         Assert.assertEquals(true, response);
150     }
151 }