/** * <b>Purpose:</b> Verify of existance of the provided path non-exactly <br> * Verify whether the status of the menuitem matches the provided status (optional parameter) * * @throws SAFSException */ protected void verifyMenuItemContains() throws SAFSException { // we always need the path parameter, so need to check if (params.size() < 1) { this.issueParameterCountFailure( FAILStrings.convert( FAILStrings.BAD_PARAM, "Invalid parameter value for MenuItemText", "MenuItemText")); return; } verifyMenuBar(obj1, getPath(), getStatus(), true); }
/** * <b>Purpose:</b> Select the path provided without the verification of existance of this path * * @throws SAFSException */ protected void selectUnverifiedPopupMenuItem() throws SAFSException { // we always need the path parameter, so need to check if (params.size() < 1) { this.issueParameterCountFailure( FAILStrings.convert( FAILStrings.BAD_PARAM, "Invalid parameter value for MenuItemText", "MenuItemText")); return; } selectMenuBar(obj1, getPath(), false, false); }
/** * <b>Purpose:</b> Verify the complete status of the current popup menu with a benchmark file. * * @throws SAFSException */ protected void verifyPopupMenu() throws SAFSException { String debugmsg = getClass().getName() + ".verifyPopupMenu() "; String benchFileName = null, headerString = null, testFileName = null, diffFileName = null; // Analyse the four parameters, three of them are optional // benchFileName (required),headerString (optional),testFileName (optional),diffFileName // (optional) if (params.size() < 1) { this.issueParameterCountFailure( FAILStrings.convert( FAILStrings.BAD_PARAM, "Invalid parameter value for BenchmarkFile", "BenchmarkFile")); Log.debug(debugmsg + " Missing parameter of 'benchFileName'!!!"); return; } Iterator iter = params.iterator(); String defaultFileName = iter.next().toString(); Log.info(debugmsg + " default file name (for bench,test,diff): " + defaultFileName); benchFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_BENCHDIRECTORY); if (iter.hasNext()) headerString = iter.next().toString(); if (iter.hasNext()) { testFileName = iter.next().toString(); if (testFileName != null && !testFileName.trim().equals("")) { testFileName = getAbsoluteFileName(testFileName, STAFHelper.SAFS_VAR_TESTDIRECTORY); } else { testFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_TESTDIRECTORY); } } else { testFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_TESTDIRECTORY); } if (iter.hasNext()) { diffFileName = iter.next().toString(); if (diffFileName != null && !diffFileName.trim().equals("")) { diffFileName = getAbsoluteFileName(diffFileName, STAFHelper.SAFS_VAR_DIFDIRECTORY); } else { diffFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_DIFDIRECTORY); } } else { diffFileName = getAbsoluteFileName(defaultFileName, STAFHelper.SAFS_VAR_DIFDIRECTORY); } // 1.Get the whole sub-tree of the JMenu provided (the third parameter) GuiSubitemTestObject guiObj = new GuiSubitemTestObject(obj1.getObjectReference()); MenuTree tree = (MenuTree) extractMenuItems(guiObj, 0); // Get a list which contains all nodes' "path=status" List treePathAndStatus = tree.getTreePaths("", true); // 2.Stroe the header-file into the test-file // Store the each node's path and it's status of the sub-tree into the "test-file" if (headerString != null && !headerString.trim().equals("")) { Log.debug(debugmsg + testFileName + " will contains headerString: " + headerString); treePathAndStatus.add(0, headerString); } if (testFileName != null && !testFileName.trim().equals("")) { Log.debug(debugmsg + "Menu status will be saved to " + testFileName); try { StringUtils.writefile(testFileName, treePathAndStatus); } catch (IOException e) { String detail = failedText.convert( FAILStrings.FILE_ERROR, "Can not write to " + testFileName, testFileName); Log.debug(debugmsg + detail); throw new SAFSException(detail); } } // 3.Compare with the bench-file; // If mached, set the testRecord's status to OK. // Otherwise, set the testRecord's status to FAILURE and store the difference to diff-file. List benchContents = new ArrayList(); try { benchContents.addAll(StringUtils.readfile(benchFileName)); } catch (IOException e) { String detail = failedText.convert( FAILStrings.FILE_ERROR, "Can not read " + benchFileName, benchFileName); Log.debug(debugmsg + detail); throw new SAFSException(detail); } Log.debug(debugmsg + "BenchFile Menu's status:" + benchContents); Log.debug(debugmsg + "Current Menu's status:" + treePathAndStatus); // The list differences will contains the difference between current status and bench status List differences = new ArrayList(); if (headerString != null && !headerString.trim().equals("")) { Log.debug(debugmsg + "Compare the header line."); String benchHeader = benchContents.isEmpty() ? "" : benchContents.remove(0).toString(); String currentHeader = treePathAndStatus.remove(0).toString(); Log.debug("benchHeader: " + benchHeader); Log.debug("currentHeader: " + currentHeader); if (!currentHeader.equalsIgnoreCase(benchHeader)) { differences.add( "Header different: \n" + "benchHeader: " + benchHeader + "\n" + "currentHeader: " + currentHeader + "\n\n"); } } // Convert List to Map which contains path as key and status as value Map benchStatusMap = convertToMap(benchContents); Map currentStatusMap = convertToMap(treePathAndStatus); // I. If the two maps have the same path and the same status // II. Else If the two maps have the same path but status are different, then write this // difference to the list differences. // Finally remove the path from both maps Object[] currentPathArray = currentStatusMap.keySet().toArray(); for (int i = 0; i < currentPathArray.length; i++) { String key = currentPathArray[i].toString(); String benchStatus = null; if (benchStatusMap.containsKey(key)) { benchStatus = benchStatusMap.get(key).toString(); } else { continue; } String currentStatus = currentStatusMap.get(key).toString(); Log.debug("menu path: " + key); Log.debug("benchStatusValue: " + benchStatus); Log.debug("currentStatusValue: " + currentStatus); if (!benchStatus.equalsIgnoreCase(currentStatus)) { differences.add( "Menu path: " + key + " has difference: \n" + "benchStatus: " + benchStatus + "\n" + "currentStatus: " + currentStatus + "\n"); } // Finally remove this path from both benchStatusMap and currentStatusMap benchStatusMap.remove(key); currentStatusMap.remove(key); } // III. Else if MenuItem exist only in bench file, write this difference to list differences. if (benchStatusMap.size() != 0) { differences.add("MenuItem exist only in " + benchFileName); Object[] keys = benchStatusMap.keySet().toArray(); for (int i = 0; i < keys.length; i++) { String key = keys[i].toString(); differences.add("Menu path: " + key + " ## Status: " + benchStatusMap.get(key)); } } // IV. Else if MenuItem exist only in current menu, write this difference to list differences. if (currentStatusMap.size() != 0) { differences.add("MenuItem exist only in current menu"); Object[] keys = currentStatusMap.keySet().toArray(); for (int i = 0; i < keys.length; i++) { String key = keys[i].toString(); differences.add("Menu path: " + key + " ## Status: " + currentStatusMap.get(key)); } } // If the size of differences is bigger than 0, there are some differences between current // status and bench status if (differences.size() > 0) { testRecordData.setStatusCode(StatusCodes.GENERAL_SCRIPT_FAILURE); String detail = failedText.convert( GENStrings.CONTENT_NOT_MATCHES_KEY, "the content of 'Current menu status' does not match the content of '" + benchFileName + "'", "Current menu's status", benchFileName); if (diffFileName != null && !diffFileName.trim().equals("")) { try { StringUtils.writefile(diffFileName, differences); detail += " " + genericText.convert( GENStrings.SEE_DIFFERENCE_FILE, "\n\tPlease see difference in file '" + diffFileName + "'.", diffFileName); } catch (IOException e1) { String message = failedText.convert( FAILStrings.FILE_ERROR, "Can not write to " + diffFileName, diffFileName); Log.debug(debugmsg + message); } } componentExecutedFailureMessage(detail); return; } Log.debug(debugmsg + "All status of menu match that of benchfile."); String detail = genericText.convert( GENStrings.CONTENT_MATCHES_KEY, "the content of 'Current menu status' matches the content of '" + benchFileName + "'", "Current menu's status", benchFileName); componentSuccessMessage(detail); testRecordData.setStatusCode(StatusCodes.OK); }