admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * To change this template, choose Tools | Templates |
| 3 | * and open the template in the editor. |
| 4 | */ |
| 5 | package tai_ofa; |
| 6 | |
| 7 | import java.io.BufferedReader; |
| 8 | import java.io.DataInputStream; |
| 9 | import java.io.FileInputStream; |
| 10 | import java.io.InputStreamReader; |
| 11 | import java.util.ArrayList; |
| 12 | import java.util.HashMap; |
| 13 | import java.util.Iterator; |
| 14 | import java.util.Locale; |
| 15 | import java.util.Map; |
| 16 | import java.util.Set; |
| 17 | import java.util.regex.Matcher; |
| 18 | import java.util.regex.Pattern; |
| 19 | |
| 20 | /** |
| 21 | * |
| 22 | * @author Raghav Kashyap (raghavkashyap@paxterrasolutions.com) |
| 23 | |
| 24 | * TestON is free software: you can redistribute it and/or modify |
| 25 | * it under the terms of the GNU General Public License as published by |
| 26 | * the Free Software Foundation, either version 2 of the License, or |
| 27 | * (at your option) any later version. |
| 28 | |
| 29 | * TestON is distributed in the hope that it will be useful, |
| 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 | * GNU General Public License for more details. |
| 33 | |
| 34 | * You should have received a copy of the GNU General Public License |
| 35 | * along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 36 | |
| 37 | */ |
| 38 | class OFAParamDeviceName { |
| 39 | |
| 40 | String paramFilePath; |
| 41 | ArrayList<String> paramDeviceName; |
| 42 | ArrayList<String> driverFunctionName; |
| 43 | ArrayList<String> paramDeviceType; |
| 44 | ArrayList<String> paramDeviceCoordinate; |
| 45 | ArrayList<String> paramDeviceHost; |
| 46 | ArrayList<String> paramDeviceUser; |
| 47 | ArrayList<String> paramDevicePassword; |
| 48 | ArrayList<String> paramDeviceTransport; |
| 49 | ArrayList<String> paramDevicePort; |
| 50 | ArrayList<String> paramDeviceBrowser; |
| 51 | ArrayList<String> paramDeviceUrl; |
| 52 | HashMap<String, String> deviceInfo = new HashMap(); |
| 53 | HashMap<String, String> urlInfo = new HashMap(); |
| 54 | HashMap<String, String> browserInfo = new HashMap(); |
| 55 | HashMap<String, String> coordinateInfo = new HashMap(); |
| 56 | HashMap<String, String> hostInfo = new HashMap(); |
| 57 | HashMap<String, String> userInfo = new HashMap(); |
| 58 | HashMap<String, String> passwordInfo = new HashMap(); |
| 59 | HashMap<String, String> portInfo = new HashMap(); |
| 60 | HashMap<String, String> transportInfo = new HashMap(); |
| 61 | String cliFunction; |
| 62 | HashMap deviceFunctionAndParameter = new HashMap(); |
| 63 | HashMap<String, String> functionWithParameter; |
| 64 | String functionName; |
| 65 | String functionParameter; |
| 66 | HashMap<String, String> webFunctionHashFirstParameter = new HashMap<String, String>(); |
| 67 | HashMap<String, String> webFunctionHashSecondParameter = new HashMap<String, String>(); |
| 68 | ArrayList<String> seleniumFunctionList = new ArrayList<String>(); |
| 69 | String bdrAction; |
| 70 | TAILocale label = new TAILocale(new Locale("en", "EN")); |
| 71 | String autoMateHarnessPath = label.OFAHarnessPath; |
| 72 | ArrayList<String> bdrFunctionName; |
| 73 | |
| 74 | public OFAParamDeviceName() { |
| 75 | } |
| 76 | |
| 77 | public OFAParamDeviceName(String filePath, String driverFilePath) { |
| 78 | paramDeviceName = new ArrayList<String>(); |
| 79 | paramDeviceType = new ArrayList<String>(); |
| 80 | paramDeviceCoordinate = new ArrayList<String>(); |
| 81 | paramDeviceHost = new ArrayList<String>(); |
| 82 | paramDeviceUser = new ArrayList<String>(); |
| 83 | paramDevicePassword = new ArrayList<String>(); |
| 84 | paramDeviceTransport = new ArrayList<String>(); |
| 85 | paramDevicePort = new ArrayList<String>(); |
| 86 | paramDeviceBrowser = new ArrayList<String>(); |
| 87 | paramDeviceUrl = new ArrayList<String>(); |
| 88 | this.paramFilePath = filePath; |
| 89 | } |
| 90 | |
| 91 | public void parseParamFile() { |
| 92 | try { |
| 93 | |
| 94 | FileInputStream fstream = new FileInputStream(paramFilePath); |
| 95 | ArrayList<String> paramFileName = new ArrayList<String>(); |
| 96 | ArrayList<String> nameBetweenTags = new ArrayList<String>(); |
| 97 | DataInputStream in = new DataInputStream(fstream); |
| 98 | BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
| 99 | String strLine; |
| 100 | while ((strLine = br.readLine()) != null) { |
| 101 | paramFileName.add(strLine); |
| 102 | |
| 103 | } |
| 104 | |
| 105 | for (int i = 0; i < paramFileName.size(); i++) { |
| 106 | String dName = ""; |
| 107 | String dType = ""; |
| 108 | String dCoordinate = ""; |
| 109 | String dHost = ""; |
| 110 | String dUser = ""; |
| 111 | String dPassword = ""; |
| 112 | String dTransport = ""; |
| 113 | String dPort = ""; |
| 114 | String dBrowser = ""; |
| 115 | String dUrl = ""; |
| 116 | Pattern devicePatternMatch = Pattern.compile("<COMPONENT>"); |
| 117 | Matcher deviceNameMatch = devicePatternMatch.matcher(paramFileName.get(i)); |
| 118 | if (deviceNameMatch.find()) { |
| 119 | int j = i + 1; |
| 120 | while (!paramFileName.get(j).equals("</COMPONENT>")) { |
| 121 | Pattern newTag = Pattern.compile("<(.+)(\\d+)>"); |
| 122 | Matcher tagMatch = newTag.matcher(paramFileName.get(j)); |
| 123 | if (tagMatch.find()) { |
| 124 | String temp = tagMatch.group(1); |
| 125 | Pattern slashCheck = Pattern.compile("^\\w+"); |
| 126 | Matcher slashMatch = slashCheck.matcher(temp); |
| 127 | if (slashMatch.find()) { |
| 128 | paramDeviceName.add(slashMatch.group() + tagMatch.group(2)); |
| 129 | dName = slashMatch.group() + tagMatch.group(2); |
| 130 | } |
| 131 | |
| 132 | } |
| 133 | |
| 134 | |
| 135 | Pattern deviceTypePattern = Pattern.compile("<type>\\s*(.+)\\s*</type>"); |
| 136 | Matcher deviceTypeMatch = deviceTypePattern.matcher(paramFileName.get(j)); |
| 137 | |
| 138 | while (deviceTypeMatch.find()) { |
| 139 | paramDeviceType.add(deviceTypeMatch.group(1)); |
| 140 | dType = deviceTypeMatch.group(1).toLowerCase(); |
| 141 | |
| 142 | } |
| 143 | Pattern deviceCoordinatePattern = Pattern.compile("<coordinate(x,y)>\\s*(.+)\\s*</coordinate(x,y)>"); |
| 144 | Matcher deviceCoordinateMatch = deviceCoordinatePattern.matcher(paramFileName.get(j)); |
| 145 | while (deviceCoordinateMatch.find()) { |
| 146 | paramDeviceCoordinate.add(deviceCoordinateMatch.group(1)); |
| 147 | dCoordinate = deviceCoordinateMatch.group(1); |
| 148 | |
| 149 | } |
| 150 | Pattern devicehostNamePattern = Pattern.compile("<host>\\s*(.+)\\s*</host>"); |
| 151 | Matcher deviceHostMatch = devicehostNamePattern.matcher(paramFileName.get(j)); |
| 152 | |
| 153 | while (deviceHostMatch.find()) { |
| 154 | paramDeviceHost.add(deviceHostMatch.group(1)); |
| 155 | dHost = deviceHostMatch.group(1); |
| 156 | } |
| 157 | Pattern deviceUserPattern = Pattern.compile("<user>\\s*(.+)\\s*</user>"); |
| 158 | Matcher deviceUserMatch = deviceUserPattern.matcher(paramFileName.get(j)); |
| 159 | while (deviceUserMatch.find()) { |
| 160 | paramDeviceUser.add(deviceUserMatch.group(1)); |
| 161 | dUser = deviceUserMatch.group(1); |
| 162 | } |
| 163 | |
| 164 | Pattern devicePasswordPattern = Pattern.compile("<password>\\s*(.+)\\s*</password>"); |
| 165 | Matcher devicePasswordMatch = devicePasswordPattern.matcher(paramFileName.get(j)); |
| 166 | while (devicePasswordMatch.find()) { |
| 167 | paramDevicePassword.add(devicePasswordMatch.group(1)); |
| 168 | dPassword = devicePasswordMatch.group(1); |
| 169 | } |
| 170 | |
| 171 | Pattern devicePortPattern = Pattern.compile("<test_target>\\s*(.+)\\s*</test_target>"); |
| 172 | Matcher devicePortMatch = devicePortPattern.matcher(paramFileName.get(j)); |
| 173 | while (devicePortMatch.find()) { |
| 174 | paramDevicePort.add(devicePortMatch.group(1)); |
| 175 | dPort = devicePortMatch.group(1); |
| 176 | } |
| 177 | |
| 178 | deviceInfo.put(dName, dType); |
| 179 | coordinateInfo.put(dName, dCoordinate); |
| 180 | hostInfo.put(dName, dHost); |
| 181 | userInfo.put(dName, dUser); |
| 182 | passwordInfo.put(dName, dPassword); |
| 183 | portInfo.put(dName, dPort); |
| 184 | j++; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | //Close the input stream |
| 189 | in.close(); |
| 190 | } catch (Exception e) {//Catch exception if any |
| 191 | System.err.println("Error: " + e.getMessage()); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | public void parseDevice(String devicePath) { |
| 196 | try { |
| 197 | FileInputStream fstream = new FileInputStream(devicePath); |
| 198 | DataInputStream in = new DataInputStream(fstream); |
| 199 | BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
| 200 | String strLine; |
| 201 | while ((strLine = br.readLine()) != null) { |
| 202 | Pattern cliFunctionPattern = Pattern.compile("sub\\s+(\\w+)"); |
| 203 | Matcher cliFunctionMatch = cliFunctionPattern.matcher(strLine); |
| 204 | Pattern cliFunctionArgumentPattern = Pattern.compile("utilities.parse_args\\(\\[\\s+qw\\((.*)\\)\\s*\\]\\,(.*)"); |
| 205 | Matcher argumentMatch = cliFunctionArgumentPattern.matcher(strLine); |
| 206 | while (cliFunctionMatch.find()) { |
| 207 | cliFunction = cliFunctionMatch.group(1); |
| 208 | Pattern rm = Pattern.compile("_(.*)"); |
| 209 | Matcher str2 = rm.matcher(cliFunction); |
| 210 | if (!str2.find()) { |
| 211 | } |
| 212 | } |
| 213 | while (argumentMatch.find()) { |
| 214 | deviceFunctionAndParameter.put(cliFunction, argumentMatch.group(1)); |
| 215 | } |
| 216 | } |
| 217 | } catch (Exception e) { |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | public void driverFunctionName(String driverPath) { |
| 222 | try { |
| 223 | functionWithParameter = new HashMap<String, String>(); |
| 224 | FileInputStream fstream = new FileInputStream(driverPath); |
| 225 | driverFunctionName = new ArrayList<String>(); |
| 226 | DataInputStream in = new DataInputStream(fstream); |
| 227 | BufferedReader br = new BufferedReader(new InputStreamReader(in)); |
| 228 | String strLine; |
| 229 | while ((strLine = br.readLine()) != null) { |
| 230 | Pattern functionParameterPattern = Pattern.compile("(.*)\\s*=\\s*utilities.parse_args\\(\\s*\\[\\s*(.*)\\s*\\]\\s*\\,(.*)"); |
| 231 | Matcher functionParaMeterMatch = functionParameterPattern.matcher(strLine); |
| 232 | Pattern pattern = Pattern.compile("^\\s*def\\s+(\\w+)"); |
| 233 | Matcher match = pattern.matcher(strLine); |
| 234 | while (match.find()) { |
| 235 | functionName = match.group(1); |
| 236 | Pattern cliFunctionWithOut_ = Pattern.compile("_(.*)"); |
| 237 | Matcher cliFunctionWithOut_Match = cliFunctionWithOut_.matcher(functionName); |
| 238 | if (!cliFunctionWithOut_Match.find()) { |
| 239 | driverFunctionName.add(match.group(1)); |
| 240 | } |
| 241 | |
| 242 | |
| 243 | } |
| 244 | while (functionParaMeterMatch.find()) { |
| 245 | functionParameter = functionParaMeterMatch.group(2); |
| 246 | functionWithParameter.put(functionName, functionParameter); |
| 247 | } |
| 248 | } |
| 249 | } catch (Exception e) { |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | public ArrayList<String> getParamDeviceName() { |
| 254 | return paramDeviceName; |
| 255 | } |
| 256 | |
| 257 | public ArrayList<String> getParamDeviceType() { |
| 258 | return paramDeviceType; |
| 259 | } |
| 260 | |
| 261 | public ArrayList<String> getDriverFunctionName() { |
| 262 | return driverFunctionName; |
| 263 | } |
| 264 | |
| 265 | public ArrayList<String> getCoordinateName() { |
| 266 | return paramDeviceCoordinate; |
| 267 | } |
| 268 | |
| 269 | public ArrayList<String> getBrowserName() { |
| 270 | return paramDeviceBrowser; |
| 271 | } |
| 272 | |
| 273 | public ArrayList<String> getHostName() { |
| 274 | return paramDeviceHost; |
| 275 | } |
| 276 | |
| 277 | public ArrayList<String> getUserName() { |
| 278 | return paramDeviceUser; |
| 279 | } |
| 280 | |
| 281 | public ArrayList<String> getPassword() { |
| 282 | return paramDevicePassword; |
| 283 | } |
| 284 | |
| 285 | public ArrayList<String> getTransport() { |
| 286 | return paramDeviceTransport; |
| 287 | } |
| 288 | |
| 289 | public ArrayList<String> getPort() { |
| 290 | return paramDevicePort; |
| 291 | } |
| 292 | |
| 293 | public ArrayList<String> getUrl() { |
| 294 | return paramDeviceUrl; |
| 295 | } |
| 296 | |
| 297 | public HashMap<String, String> getdeviceNameAndType() { |
| 298 | return deviceInfo; |
| 299 | } |
| 300 | |
| 301 | public HashMap<String, String> getdeviceNameAndBrowser() { |
| 302 | return browserInfo; |
| 303 | } |
| 304 | |
| 305 | public HashMap<String, String> getdeviceNameAndUrl() { |
| 306 | return urlInfo; |
| 307 | } |
| 308 | |
| 309 | public HashMap<String, String> getdeviceNameAndCoordinate() { |
| 310 | return coordinateInfo; |
| 311 | } |
| 312 | |
| 313 | public HashMap<String, String> getdeviceNameAndHost() { |
| 314 | return hostInfo; |
| 315 | } |
| 316 | |
| 317 | public HashMap<String, String> getdeviceNameAndUser() { |
| 318 | return userInfo; |
| 319 | } |
| 320 | |
| 321 | public HashMap<String, String> getdeviceNameAndPassword() { |
| 322 | return passwordInfo; |
| 323 | } |
| 324 | |
| 325 | public HashMap<String, String> getdeviceNameAndTransport() { |
| 326 | return transportInfo; |
| 327 | } |
| 328 | |
| 329 | public HashMap<String, String> getdeviceNameAndPort() { |
| 330 | return portInfo; |
| 331 | } |
| 332 | |
| 333 | public HashMap<String, String> getDeviceFunctionAndArgument() { |
| 334 | return deviceFunctionAndParameter; |
| 335 | } |
| 336 | } |