2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.ccadaptor;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
33 import org.junit.Assert;
34 import org.junit.Test;
36 public class SshJcraftWrapperTest {
39 public void TestCheckIfReceivedStringMatchesDelimeter(){
40 SshJcraftWrapper wrapper = new SshJcraftWrapper();
42 boolean result = wrapper.checkIfReceivedStringMatchesDelimeter("#", "test#", "test#");
43 Assert.assertEquals(true, result);
47 public void testRemoveWhiteSpaceAndNewLineCharactersAroundString(){
48 SshJcraftWrapper wrapper = new SshJcraftWrapper();
49 String nameSpace = wrapper.removeWhiteSpaceAndNewLineCharactersAroundString("namespace ");
50 Assert.assertEquals("namespace", nameSpace);
54 public void testStripOffCmdFromRouterResponse(){
55 SshJcraftWrapper wrapper = new SshJcraftWrapper();
56 String result = wrapper.stripOffCmdFromRouterResponse("test\nsuccess");
57 Assert.assertEquals("success\n", result);
61 public void testGetLastFewLinesOfFile() throws FileNotFoundException, IOException{
62 SshJcraftWrapper wrapper = new SshJcraftWrapper();
63 URL path = SshJcraftWrapperTest.class.getResource("Test");
64 File file = new File(path.getFile());
65 String value = wrapper.getLastFewLinesOfFile(file,1);
66 Assert.assertEquals("\nTest data 3", value);
69 @Test(expected=Exception.class)
70 public void testSetRouterCommandType() throws IOException{
71 SshJcraftWrapper wrapper = new SshJcraftWrapper();
72 wrapper.setRouterCommandType("test");
73 wrapper.receiveUntil("test", 2, "test");
77 public void testValues() throws IOException{
78 SshJcraftWrapper wrapper = new SshJcraftWrapper();
79 wrapper.setEquipNameCode("testcode");
80 wrapper.setRouterCommandType("testcommand");
81 String equipName =wrapper.getEquipNameCode();
82 wrapper.getHostName();
83 wrapper.getPassWord();
84 wrapper.getRouterName();
85 wrapper.getUserName();
87 Assert.assertEquals("testcode", equipName);
90 @Test(expected=Exception.class)
91 public void testSetRouterCommandType2() throws IOException{
92 SshJcraftWrapper wrapper = new SshJcraftWrapper();
93 wrapper.appendToRouterFile("test", 2);
94 StringBuilder sb = new StringBuilder();
96 wrapper.appendToRouterFile("Test.txt", sb);
97 wrapper.receiveUntilBufferFlush(3, 4, "test");
100 @Test(expected=Exception.class)
101 public void testSetRouterCommandType3() throws IOException{
102 SshJcraftWrapper wrapper = new SshJcraftWrapper();
103 wrapper.checkIfReceivedStringMatchesDelimeter(3, "test");