2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.ccadaptor;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.assertFalse;
30 import static org.junit.Assert.fail;
31 import static org.mockito.BDDMockito.given;
32 import static org.mockito.Matchers.any;
33 import static org.mockito.Matchers.anyInt;
34 import static org.mockito.Matchers.anyString;
35 import static org.mockito.Matchers.eq;
36 import static org.mockito.Mockito.atLeastOnce;
37 import static org.mockito.Mockito.doThrow;
38 import static org.mockito.Mockito.inOrder;
39 import static org.mockito.Mockito.never;
40 import static org.mockito.Mockito.spy;
41 import static org.mockito.Mockito.times;
42 import static org.mockito.Mockito.verify;
43 import static org.mockito.Mockito.verifyNoMoreInteractions;
45 import com.jcraft.jsch.ChannelSftp;
46 import com.jcraft.jsch.ChannelShell;
47 import com.jcraft.jsch.ChannelSubsystem;
48 import com.jcraft.jsch.JSch;
49 import com.jcraft.jsch.JSchException;
50 import com.jcraft.jsch.Session;
51 import com.jcraft.jsch.SftpException;
52 import com.jcraft.jsch.UserInfo;
54 import java.io.FileNotFoundException;
55 import java.io.IOException;
56 import java.io.InputStream;
57 import java.io.OutputStream;
60 import org.apache.commons.lang.StringUtils;
61 import org.junit.Assert;
62 import org.junit.Before;
63 import org.junit.Ignore;
64 import org.junit.Test;
65 import org.junit.runner.RunWith;
66 import org.mockito.InOrder;
67 import org.mockito.Mock;
68 import org.mockito.runners.MockitoJUnitRunner;
69 import org.apache.commons.io.IOUtils;
71 @RunWith(MockitoJUnitRunner.class)
72 public class SshJcraftWrapperTest {
74 public void TestCheckIfReceivedStringMatchesDelimeter(){
75 SshJcraftWrapper wrapper = new SshJcraftWrapper();
77 boolean result = wrapper.checkIfReceivedStringMatchesDelimeter("#", "test#", "test#");
78 Assert.assertEquals(true, result);
82 public void testRemoveWhiteSpaceAndNewLineCharactersAroundString(){
83 SshJcraftWrapper wrapper = new SshJcraftWrapper();
84 String nameSpace = wrapper.removeWhiteSpaceAndNewLineCharactersAroundString("namespace ");
85 Assert.assertEquals("namespace", nameSpace);
89 public void testStripOffCmdFromRouterResponse(){
90 SshJcraftWrapper wrapper = new SshJcraftWrapper();
91 String result = wrapper.stripOffCmdFromRouterResponse("test\nsuccess");
92 Assert.assertEquals("success\n", result);
96 public void testGetLastFewLinesOfFile() throws FileNotFoundException, IOException{
97 SshJcraftWrapper wrapper = new SshJcraftWrapper();
98 URL path = SshJcraftWrapperTest.class.getResource("Test");
99 File file = new File(path.getFile());
100 String value = wrapper.getLastFewLinesOfFile(file,1);
101 Assert.assertEquals("\nTest data 3", value);
104 @Test(expected=Exception.class)
105 public void testSetRouterCommandType() throws IOException{
106 SshJcraftWrapper wrapper = new SshJcraftWrapper();
107 wrapper.setRouterCommandType("test");
108 wrapper.receiveUntil("test", 2, "test");
112 public void testValues() throws IOException{
113 SshJcraftWrapper wrapper = new SshJcraftWrapper();
114 wrapper.setEquipNameCode("testcode");
115 wrapper.setRouterCommandType("testcommand");
116 String equipName =wrapper.getEquipNameCode();
117 wrapper.getHostName();
118 wrapper.getPassWord();
119 wrapper.getRouterName();
120 wrapper.getUserName();
121 wrapper.getTheDate();
122 Assert.assertEquals("testcode", equipName);
125 @Test(expected=Exception.class)
126 public void testSetRouterCommandType2() throws IOException{
127 SshJcraftWrapper wrapper = new SshJcraftWrapper();
128 wrapper.appendToRouterFile("test", 2);
129 StringBuffer buffer = new StringBuffer();
130 buffer.append("test");
131 wrapper.appendToRouterFile("Test.txt", buffer);
132 wrapper.receiveUntilBufferFlush(3, 4, "test");
135 @Test(expected=Exception.class)
136 public void testSetRouterCommandType3() throws IOException{
137 SshJcraftWrapper wrapper = new SshJcraftWrapper();
138 wrapper.checkIfReceivedStringMatchesDelimeter(3, "test");