[SDC-29] rebase continue work to align source
[sdc.git] / ui-ci / src / main / java / org / openecomp / sdc / ci / tests / execute / setup / TestFtp.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.execute.setup;
22
23 import java.io.BufferedReader;
24 import java.io.File;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30
31 import org.openqa.selenium.remote.internal.ApacheHttpClient;
32
33 public class TestFtp {
34
35         public static void main(String[] args) throws IOException {
36                 // TODO Auto-generated method stub
37                 AttFtpClient instance = AttFtpClient.getInstance();
38                 
39                  String server = "135.177.130.113";
40               int port = 2121;
41               String user = "admin";
42               String pass = "admin";
43               AttFtpClient.getInstance().init(server, port, user, pass);
44               
45               try {
46                   AttFtpClient.getInstance().retrieveListOfFile();
47                   
48                   File retrieveLastModifiedFileFromFTP = instance.retrieveLastModifiedFileFromFTP();
49                   String content = new String(Files.readAllBytes(Paths.get(retrieveLastModifiedFileFromFTP.getPath())), StandardCharsets.UTF_8);
50 //                instance.deleteFilesFromFTPserver();
51                   System.out.println(content);
52                   readFile(retrieveLastModifiedFileFromFTP);
53                         
54                 } finally {
55                         instance.terminateClient();
56                 }
57               
58              
59
60               
61               
62               
63                 
64         }
65          public static void readFile(File retrieveLastModifiedFileFromFTP) {
66
67                 StringBuilder sb = new StringBuilder();
68                 BufferedReader br = null;
69                 try {
70                     br = new BufferedReader(new FileReader(retrieveLastModifiedFileFromFTP.getPath()));
71                     String line;
72                     while ((line = br.readLine()) != null) {
73                         if (sb.length() > 0) {
74                             sb.append("\n");
75                         }
76                         sb.append(line);
77                     }
78                 } catch (IOException e) {
79                     e.printStackTrace();
80                 } finally {
81                     try {
82                         if (br != null) {
83                             br.close();
84                         }
85                     } catch (IOException ex) {
86                         ex.printStackTrace();
87                     }
88                 }
89                 String contents = sb.toString();
90                 System.out.println(contents);           
91                  
92          }
93
94 }