⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fsext.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
package com.ibm.staf.service.fsext;/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004, 2005                                  *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************//*****************************************************************************//*                                                                           *//* Author: Chris Alkov                                                       *//* Date: 12/2001                                                             *//* Revisions:                                                                *//*   01/31/2005 - Updated for STAF 3.0 marshalled results                    *//*****************************************************************************//*****************************************************************************//*                                                                           *//* Class: FSEXT                                                              *//* Description: This class provides the STAFService Interface and implements *//*              the majority of the service function                         *//*                                                                           *//*****************************************************************************/import com.ibm.staf.*;import com.ibm.staf.service.*;import com.ibm.staf.service.utility.ServiceUtilities;import java.io.File;import java.io.FileReader;import java.io.BufferedReader;import java.io.IOException;import java.io.FileWriter;import java.io.BufferedWriter;import java.io.FileNotFoundException;import java.util.Map;import java.util.HashMap;import java.util.List;import java.util.ArrayList;import java.util.Iterator;import java.util.Date;import java.util.Enumeration;import java.util.Vector;public class FSExt implements STAFServiceInterfaceLevel30{    private STAFHandle sHandle;    private String fServiceName;    private String fLocalMachineName = "";    /* STAF Parsers */    private STAFCommandParser procFileParser;    private STAFCommandParser compDirParser;    private STAFCommandParser fileContainsParser;    private STAFCommandParser lineContainsParser;    private STAFCommandParser waitForFileParser;    private STAFCommandParser substituteParser;    private STAFMapClassDefinition fFileContainsErrorMapClass;    private STAFMapClassDefinition fLineContainsMapClass;    /* String Constants */    private static final String FSEXTVERSION = "3.0.0";    private static final String PROCESSFILE = "PROCESSFILE";    private static final String MODE    = "MODE";    private static final String CAPTURE = "CAPTURE";    private static final String COMPARE = "COMPARE";    private static final String FILE1   = "FILE1";    private static final String FILE2   = "FILE2";    private static final String SORT    = "SORT";    private static final String COMPAREDIR = "COMPAREDIR";    private static final String DIR     = "DIR";    private static final String EXISTS  = "EXISTS";    private static final String ATTEMPTS = "ATTEMPTS";    private static final String POLL    = "INTERVAL";    private static final String FILECONTAINS = "FILECONTAINS";    private static final String LINECONTAINS = "LINECONTAINS";    private static final String FILE    = "FILE";    private static final String STRING = "STRING";    private static final String NOT     = "NOT";    private static final String IGNORECASE = "IGNORECASE";    private static final String SAVEONFAILURE = "SAVEONFAILURE";    private static final String LINENUMBER = "LINENUMBER";    private static final String WAITFORFILE = "WAITFORFILE";    private static final String TIMEOUT = "TIMEOUT";    private static final String HELP = "HELP";    private static final String VERSION = "VERSION";    private static final String SUBSTITUTE = "SUBSTITUTE";    private static final String TOFILE = "TOFILE";    private static final String TOMACHINE = "TOMACHINE";    private static final String FAILIFEXISTS = "FAILIFEXISTS";    private static final String FAILIFNEW = "FAILIFNEW";    /* Return Codes */    private static final int COMPAREFAIL = 4001;    private static final String COMPAREFAILInfo = "File Comparison Failed";    private static final String COMPAREFAILDesc =        "The file comparison failed.";    private static final int NOTDIRECTORY = 4002;    private static final String NOTDIRECTORYInfo = "Not A Directory";    private static final String NOTDIRECTORYDesc =        "The value specified for the DIR parameter is not a directory.";    private static final int FILENOTFOUND = 4003;    private static final String FILENOTFOUNDInfo = "File Not Found";    private static final String FILENOTFOUNDDesc =        "The specified file was not found on the file system.";    private static final int FILEEXISTS = 4004;    private static final String FILEEXISTSInfo = "File Exists";    private static final String FILEEXISTSDesc =        "The specified file exists. (The NOT parameter was specified.)";    private static final int EXTRAFILES = 4005;    private static final String EXTRAFILESInfo = "Extraneous Files Found";    private static final String EXTRAFILESDesc =        "Extraneous files were found in the specified directory.";    private static final int STRINGNOTFOUND = 4006;    private static final String STRINGNOTFOUNDInfo = "String(s) Not Found";    private static final String STRINGNOTFOUNDDesc =        "The specified String(s) were not found.";    private static final int STRINGFOUND = 4007;    private static final String STRINGFOUNDInfo = "String(s) Found";    private static final String STRINGFOUNDDesc =        "The specified String(s) were found. " +        "(The NOT parameter was specified.)";    private static final int LINEDOESNOTEXIST = 4008;    private static final String LINEDOESNOTEXISTInfo =        "Line Number Does Not Exist";    private static final String LINEDOESNOTEXISTDesc =        "The line number specified by the LINENUMBER parameter " +        "does not exist in the file.";    private static final int IOERROR = 4100;    private static final String IOERRORInfo = "Java IOError";    private static final String IOERRORDesc =        "A Java IOError occurred during command execution. Check the result " +        "buffer for more information.";/*****************************************************************************//*                                                                           *//* Method: Constructor                                                       *//* Description: Constructor method                                           *//*                                                                           *//*****************************************************************************/public FSExt(){    super();}/*****************************************************************************//*                                                                           *//* Method: acceptRequest                                                     *//* Description: required by interface STAFServiceInterfaceLevel30             *//*              performs first parse of request                              *//*                                                                           *//*****************************************************************************/public STAFResult acceptRequest(STAFServiceInterfaceLevel30.RequestInfo info){    String request = info.request.toUpperCase();    STAFResult result = null;    try    {        if (request.startsWith(PROCESSFILE))            result = processFile(info);        else if (request.startsWith(COMPAREDIR))            result = compareDir(info);        else if (request.startsWith(FILECONTAINS))            result = fileContains(info);        else if (request.startsWith(LINECONTAINS))            result = lineContains(info);        else if (request.startsWith(WAITFORFILE))            result = waitForFile(info);        else if(request.startsWith(SUBSTITUTE))            result = substitute(info);        else if (request.startsWith(HELP))            result = handleHelp(info);        else if (request.startsWith(VERSION))            result = handleVersion(info);        else            result = new STAFResult(STAFResult.InvalidRequestString, request);    }    catch(Throwable t)    {        result = new STAFResult(STAFResult.JavaError, t.toString());    }    return result;}/*****************************************************************************//*                                                                           *//* Method: compareDir                                                        *//* Description: performs compareDir service function                         *//* Parameters: info - RequestInfo passed to acceptRequest                    *//* Returns: STAFResult                                                       *//*                                                                           *//*****************************************************************************/private STAFResult compareDir(STAFServiceInterfaceLevel30.RequestInfo info){    // Verify the requester has at least trust level 3    STAFResult trustResult = STAFUtil.validateTrust(        3, fServiceName, "COMPAREDIR", fLocalMachineName, info);    if (trustResult.rc != STAFResult.Ok) return trustResult;    // Parse request string    STAFCommandParseResult pResult = compDirParser.parse(info.request);    if (pResult.rc != 0)    {        return new STAFResult(STAFResult.InvalidRequestString,                              pResult.errorBuffer);    }    // Determine which options which specified in the request    File dir;    String[] expectedFiles;    // Parse DIR & FILES options    STAFResult res = STAFUtil.resolveRequestVar(        pResult.optionValue(DIR), sHandle, info.requestNumber);    if (res.rc != 0) return res;    String dirName = res.result;    dir = new File(dirName);    if (!dir.isDirectory())    {        // Value for DIR option specified is not a directory        return new STAFResult(NOTDIRECTORY, dirName);    }    // Create a String array of fully qualified filenames from list of    // relative filenames passed in via the FILE parm.    int numFiles = pResult.optionTimes(FILE);    expectedFiles = new String[numFiles];    for (int i = 0; i < numFiles; i++)    {        res = STAFUtil.resolveRequestVar(            pResult.optionValue(FILE, i+1), sHandle, info.requestNumber);        if (res.rc != 0) return res;        String shortName = res.result;        File file = new File(dir, shortName);        expectedFiles[i] = file.getPath();    }    // Parse EXISTS parm    boolean exact = true;    if (pResult.optionTimes(EXISTS) == 1)    {        exact = false;    }    // Parse RETRY parm    int attempts = 1;    int poll = 15000;    if (pResult.optionTimes(ATTEMPTS) == 1)    {        res = STAFUtil.resolveRequestVarAndCheckInt(            ATTEMPTS, pResult.optionValue(ATTEMPTS),            sHandle, info.requestNumber);        if (res.rc != 0) return res;        attempts = Integer.parseInt(res.result);    }    if (pResult.optionTimes(POLL) == 1)    {        res = STAFUtil.resolveRequestVarAndCheckInt(            POLL, pResult.optionValue(POLL), sHandle, info.requestNumber);        if (res.rc != 0) return res;        poll = Integer.parseInt(res.result);    }    // Start a large "for" loop to handle retries    for (int loop = 1; loop <= attempts; loop++)    {        boolean success = true;        // Create a HashMap of all files in the specified directory.  The        // filenames shall be the keys for the Map and the values will all        // initially be set to false.  As a filename in the FILES list is        // matched with a file in the file system, the value will be set to        // true.        HashMap files = ServiceUtilities.createMapOfFiles(dir);        // Loop through the list of expected files and verify that all of them        // exist in the specified directory.        for (int i = 0; i < expectedFiles.length; i++)        {            if (files.containsKey(expectedFiles[i]))            {                // File exists - set value to true                files.put(expectedFiles[i], new Boolean(true));            }            else if (loop == attempts)            {                // File does not exist - Last retry so return failure                return new STAFResult(FILENOTFOUND, expectedFiles[i]);            }            else            {                // File does not exist - Set success to false for this attempt                success = false;            }        }        // If all the expected files were found and EXISTS was not specified,        // check that no extraneous files exist.        if (exact && success)        {            if (files.containsValue(new Boolean(false)))            {                // At least one extra file found                if (loop == attempts)                {                    // Last retry so return failure and list of extra files                    List fileList = new ArrayList();                    Iterator keys = files.keySet().iterator();                    while(keys.hasNext())                    {                        // Loop thru map and return all files with false value                        String key = (String)keys.next();                        boolean failed = !((Boolean)files.get(key)).                            booleanValue();                        if (failed) fileList.add(key);                    }                    // Create a marshalled list of the exta files                    STAFMarshallingContext mc = new STAFMarshallingContext();                    mc.setRootObject(fileList);                    return new STAFResult(EXTRAFILES, mc.marshall());                }                else                {                    // Extra files found. Set success to false for this attempt                    success = false;                }            } // end if file.containsValue        } // end if (exact && success)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -