Open Kilda Java Documentation
BaseTest.java
Go to the documentation of this file.
1 package org.openkilda.test;
2 
3 import java.io.BufferedInputStream;
4 import java.io.BufferedReader;
5 import java.io.File;
6 import java.io.FileOutputStream;
7 import java.io.FileReader;
8 import java.io.IOException;
9 import java.net.MalformedURLException;
10 import java.net.URL;
11 import java.util.ArrayList;
12 import java.util.List;
13 
14 import org.apache.log4j.Logger;
15 import org.junit.Assert;
16 import org.junit.Test;
19 
25 public class BaseTest {
26 
27  private static final Logger LOGGER = Logger.getLogger(BaseTest.class);
28 
32  @Test
33  public void executeKildaFiles() {
34  LOGGER.info("Inside method executeKildaFiles");
35  File f = new File(IConstantsTest.FILE_PATH);
36  List<String> urlList = new ArrayList<String>();
37  String readLine = "";
38 
39  try (BufferedReader bufferedReader = new BufferedReader(new FileReader(f))) {
40  while ((readLine = bufferedReader.readLine()) != null) {
41  urlList.add(readLine);
42  }
43  } catch (Exception exception) {
44  LOGGER.error(
45  "exception occured Inside method executeKildaFiles: " + exception.getMessage());
46  }
47 
48  for (String url : urlList) {
49  try {
50  String[] inputValue = url.split("/");
51  String FileName = inputValue[inputValue.length - 1];
52 
53  if (url.contains(".css")) {
54  downloadFiles(url,
56  Assert.assertTrue(true);
57  }
58  if (url.contains(".js")) {
59  if (FileName.contains(IConstantsTest.JQUERY_FILE)) {
61  }
62  downloadFiles(url,
64  Assert.assertTrue(true);
65  }
66  if (url.contains("ttf") || url.contains("woff2") || url.contains("woff")) {
67  downloadFiles(url,
69  Assert.assertTrue(true);
70  }
71  if (url.contains("Roboto")) {
72  downloadFiles(url,
74  Assert.assertTrue(true);
75  }
76 
77  } catch (Exception exception) {
78  LOGGER.error("exception occured Inside method executeKildaFiles : "
79  + exception.getMessage());
80  Assert.assertTrue(false);
81  }
82  }
83  LOGGER.info("executeKildaFiles has been successfully executed");
84 
85  }
86 
93  private void downloadFiles(final String urlStr, final String file) {
94  if (file.contains(IConstantsTest.FONTS_PATH)) {
95  File directory = new File(IConstantsTest.CLASSPATH + IConstantsTest.FONTS_PATH);
96  if (!directory.exists()) {
97  directory.mkdir();
98  }
99  }
100  if (file.contains(IConstantsTest.JAVASCRIPT_PATH)) {
101  File directory = new File(IConstantsTest.CLASSPATH + IConstantsTest.JAVASCRIPT_PATH);
102  if (!directory.exists()) {
103  directory.mkdir();
104  }
105  }
106 
107  File fileObject = new File(file);
108  if (fileObject.exists()) {
109  return;
110  }
111 
112  LOGGER.info("Downloading file " + file);
113  URL url = null;
114  FileOutputStream fileOutputStream = null;
115  BufferedInputStream bufferedInputStream = null;
116 
117  try {
118  url = new URL(urlStr);
119  bufferedInputStream = new BufferedInputStream(url.openStream());
120  fileOutputStream = new FileOutputStream(file);
121  byte[] buffer = new byte[1024];
122  int count = 0;
123 
124  while ((count = bufferedInputStream.read(buffer, 0, 1024)) != -1) {
125  fileOutputStream.write(buffer, 0, count);
126  }
127 
128  } catch (MalformedURLException malformedURLException) {
129  LOGGER.error("exception occured during accessing file url" + urlStr + " : exception : "
130  + malformedURLException.getMessage());
131  } catch (IOException ioException) {
132  LOGGER.error("exception occured during downloading file " + file + " : exception : "
133  + ioException.getMessage());
134  } catch (Exception exception) {
135  LOGGER.error("exception occured during downloading file " + file + " : exception : "
136  + exception.getMessage());
137  } finally {
138  IoUtil.close(fileOutputStream);
139  IoUtil.close(bufferedInputStream);
140  }
141  }
142 }
int count
Definition: generator.py:19