2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
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.encryptiontool.wrapper;
24 import java.io.IOException;
25 import java.sql.SQLException;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.Mockito;
29 import org.onap.ccsdk.sli.core.dblib.DbLibService;
30 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
31 import org.powermock.api.mockito.PowerMockito;
32 import org.powermock.core.classloader.annotations.PrepareForTest;
33 import org.powermock.modules.junit4.PowerMockRunner;
34 import com.sun.rowset.CachedRowSetImpl;
36 @RunWith(PowerMockRunner.class)
37 @PrepareForTest(DbServiceUtil.class)
38 public class WrapperEncryptionToolTest {
40 private DbLibService dbLibService;
41 private DBResourceManager dbResourceManager;
45 public void testAnsible() throws SQLException, IOException {
46 PowerMockito.mockStatic(DbServiceUtil.class);
47 dbLibService = Mockito.mock(DbLibService.class);
48 dbResourceManager = Mockito.mock(DBResourceManager.class);
49 CachedRowSetImpl rowset = Mockito.mock(CachedRowSetImpl.class);
50 Mockito.when(rowset.first()).thenReturn(true);
51 Mockito.when(rowset.getString(Mockito.anyString()))
53 PowerMockito.when(DbServiceUtil.getData(Mockito.anyString(), Mockito.anyList(), Mockito.anyString(),
54 Mockito.anyString(), Mockito.anyString())).thenReturn(rowset);
55 PowerMockito.when(DbServiceUtil.initDbLibService()).thenReturn(dbResourceManager);
56 WrapperEncryptionTool.main(new String[] {"VNF-TYPE", "ANSIBLE", "USER", "PASS", "ACTION", "PORT", "URL"});
57 Mockito.verify(dbResourceManager).cleanUp();
61 public void testNonAnsible() throws SQLException, IOException {
62 PowerMockito.mockStatic(DbServiceUtil.class);
63 dbLibService = Mockito.mock(DbLibService.class);
64 dbResourceManager = Mockito.mock(DBResourceManager.class);
65 CachedRowSetImpl rowset = Mockito.mock(CachedRowSetImpl.class);
66 Mockito.when(rowset.first()).thenReturn(true);
67 Mockito.when(rowset.getString(Mockito.anyString()))
69 PowerMockito.when(DbServiceUtil.getData(Mockito.anyString(), Mockito.anyList(), Mockito.anyString(),
70 Mockito.anyString(), Mockito.anyString())).thenReturn(rowset);
71 PowerMockito.when(DbServiceUtil.initDbLibService()).thenReturn(dbResourceManager);
72 WrapperEncryptionTool.main(new String[] {"VNF-TYPE", "TEST", "USER", "PASS", "ACTION", "PORT", "URL"});
73 Mockito.verify(dbResourceManager).cleanUp();