Search in sources :

Example 11 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class FileOperateActionService method toFiles.

protected List toFiles(String path) throws IOException {
    List result = null;
    path = replaceProperty(path);
    File file = new File(path);
    if (file.exists()) {
        result = new ArrayList();
        result.add(file);
    } else {
        File parentFile = file;
        while ((parentFile = parentFile.getParentFile()) != null && !parentFile.exists()) ;
        if (parentFile == null) {
            parentFile = new File(".");
        } else {
            path = path.substring(parentFile.getPath().length() + 1);
        }
        try {
            RecurciveSearchFile rsf = new RecurciveSearchFile(parentFile);
            File[] files = rsf.listAllTreeFiles(path, RecurciveSearchFile.SEARCH_TYPE_ALL);
            if (files != null && files.length != 0) {
                result = new ArrayList();
                for (int i = 0; i < files.length; i++) {
                    result.add(files[i]);
                }
            }
        } catch (PatternSyntaxException e) {
        }
    }
    return result;
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 12 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class HttpTestStubService method startScenario.

public void startScenario(String userId, String scenarioGroupId, String scenarioId) throws Exception {
    synchronized (lock) {
        if (this.scenarioGroupId != null && this.scenarioId != null) {
            throw new Exception("Scenario started. scenarioGroupId=" + this.scenarioGroupId + ", scenarioId=" + this.scenarioId + ", userId=" + this.userId);
        }
        if (scenarioGroupId.equals(this.scenarioGroupId) && scenarioId.equals(this.scenarioId)) {
            return;
        }
        RecurciveSearchFile scenarioDir = new RecurciveSearchFile(new File(resourceDirectory, scenarioGroupId), scenarioId);
        if (!scenarioDir.deleteAllTree()) {
            throw new Exception("Resource directory can not delete. path=" + scenarioDir);
        }
        if (!scenarioDir.mkdirs()) {
            throw new Exception("Resource directory can not make. path=" + scenarioDir);
        }
        stubResourceManager.downloadScenarioResource(scenarioDir, scenarioGroupId, scenarioId, id);
        responseMap.clear();
        binaryMap.clear();
        evidenceMap.clear();
        File[] testcaseDirs = scenarioDir.listFiles();
        if (testcaseDirs == null || testcaseDirs.length == 0) {
            this.userId = userId;
            this.scenarioGroupId = scenarioGroupId;
            this.scenarioId = scenarioId;
            this.testcaseId = null;
            return;
        }
        for (int i = 0; i < testcaseDirs.length; i++) {
            if (!testcaseDirs[i].isDirectory()) {
                continue;
            }
            String testcaseId = testcaseDirs[i].getName();
            File[] files = testcaseDirs[i].listFiles();
            if (files == null) {
                continue;
            }
            sort(files);
            for (int j = 0; j < files.length; j++) {
                File file = files[j];
                if (file.isDirectory()) {
                    continue;
                }
                int extIndex = file.getName().lastIndexOf('.');
                String ext = null;
                if (extIndex != -1) {
                    ext = file.getName().substring(extIndex);
                }
                if (ext != null && binaryFileExtensionSet.contains(ext)) {
                    Map binMap = (Map) binaryMap.get(testcaseId);
                    if (binMap == null) {
                        binMap = new LinkedHashMap();
                        binaryMap.put(testcaseId, binMap);
                    }
                    binMap.put(file.getName(), file);
                } else {
                    Map map = (Map) responseMap.get(testcaseId);
                    if (map == null) {
                        map = new LinkedHashMap();
                        responseMap.put(testcaseId, map);
                    }
                    FileInputStream fis = new FileInputStream(file);
                    InputStreamReader isr = fileEncoding == null ? new InputStreamReader(fis) : new InputStreamReader(fis, fileEncoding);
                    RequestKey reqKey = new RequestKey();
                    try {
                        BufferedReader br = new BufferedReader(isr);
                        reqKey.urlPattern = br.readLine();
                        if (reqKey.urlPattern != null && reqKey.urlPattern.length() == 0) {
                            reqKey.urlPattern = null;
                        }
                        reqKey.bodyPattern = br.readLine();
                        if (reqKey.bodyPattern != null && reqKey.bodyPattern.length() == 0) {
                            reqKey.bodyPattern = null;
                        }
                    } finally {
                        fis.close();
                        isr.close();
                    }
                    if (reqKey.urlPattern == null) {
                        throw new Exception("URL not contains in Response file. path=" + file);
                    }
                    ResponseList list = (ResponseList) map.get(reqKey);
                    if (list == null) {
                        list = new ResponseList();
                        map.put(reqKey, list);
                    }
                    list.add(file);
                    list.sort();
                }
            }
        }
        this.userId = userId;
        this.scenarioGroupId = scenarioGroupId;
        this.scenarioId = scenarioId;
        this.testcaseId = null;
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) LinkedHashMap(java.util.LinkedHashMap) BufferedReader(java.io.BufferedReader) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 13 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class HttpTestStubService method cancelScenario.

public void cancelScenario() throws Exception {
    synchronized (lock) {
        if (scenarioGroupId == null && scenarioId == null) {
            return;
        }
        responseMap.clear();
        binaryMap.clear();
        evidenceMap.clear();
        responseCacheMap.clear();
        userId = null;
        RecurciveSearchFile scenarioDir = new RecurciveSearchFile(new File(resourceDirectory, scenarioGroupId), scenarioId);
        scenarioDir.deleteAllTree();
        this.scenarioGroupId = null;
        this.scenarioId = null;
        this.testcaseId = null;
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File)

Example 14 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class LocalTestResourceManagerService method downloadScenarioResource.

public void downloadScenarioResource(File dir, String scenarioGroupId, String scenarioId) throws Exception {
    RecurciveSearchFile testResourceFiles = new RecurciveSearchFile(testResourceDirectory, scenarioGroupId + "/" + scenarioId);
    testResourceFiles.copyAllTree(dir, new FileFilter());
    linkTemplate(dir, true);
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ExtentionFileFilter(jp.ossc.nimbus.io.ExtentionFileFilter)

Aggregations

RecurciveSearchFile (jp.ossc.nimbus.io.RecurciveSearchFile)14 File (java.io.File)11 IOException (java.io.IOException)6 ExtentionFileFilter (jp.ossc.nimbus.io.ExtentionFileFilter)4 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JarFile (java.util.jar.JarFile)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ServiceException (jp.ossc.nimbus.lang.ServiceException)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1