Second part of onap rename
[appc.git] / appc-config / appc-config-adaptor / provider / src / test / java / org / onap / appc / ccadaptor / SshJcraftWrapperTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.ccadaptor;
26
27
28 import java.io.File;
29 import java.io.FileNotFoundException;
30 import java.io.IOException;
31 import java.net.URL;
32
33 import org.junit.Assert;
34 import org.junit.Test;
35
36 public class SshJcraftWrapperTest {
37     
38     @Test
39     public void TestCheckIfReceivedStringMatchesDelimeter(){
40         SshJcraftWrapper wrapper = new SshJcraftWrapper();
41         wrapper.getTheDate();
42         boolean result = wrapper.checkIfReceivedStringMatchesDelimeter("#", "test#", "test#");
43         Assert.assertEquals(true, result);
44     }
45     
46     @Test
47     public void testRemoveWhiteSpaceAndNewLineCharactersAroundString(){
48         SshJcraftWrapper wrapper = new SshJcraftWrapper();
49         String nameSpace = wrapper.removeWhiteSpaceAndNewLineCharactersAroundString("namespace ");
50         Assert.assertEquals("namespace", nameSpace);
51     }
52     
53     @Test
54     public void testStripOffCmdFromRouterResponse(){
55         SshJcraftWrapper wrapper = new SshJcraftWrapper();
56         String result = wrapper.stripOffCmdFromRouterResponse("test\nsuccess");
57         Assert.assertEquals("success\n", result);            
58     }
59     
60     //@Test
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);
67     }
68     
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");
74     }
75     
76     @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();
86         wrapper.getTheDate();
87         Assert.assertEquals("testcode", equipName);
88     }
89     
90     @Test(expected=Exception.class)
91     public void testSetRouterCommandType2() throws IOException{
92         SshJcraftWrapper wrapper = new SshJcraftWrapper();
93         wrapper.appendToRouterFile("test", 2);
94         StringBuffer buffer = new StringBuffer();
95         buffer.append("test");
96         wrapper.appendToRouterFile("Test.txt", buffer);
97         wrapper.receiveUntilBufferFlush(3, 4, "test");        
98     }
99     
100     @Test(expected=Exception.class)
101     public void testSetRouterCommandType3() throws IOException{
102         SshJcraftWrapper wrapper = new SshJcraftWrapper();
103         wrapper.checkIfReceivedStringMatchesDelimeter(3, "test");
104     }
105 }