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;
}
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;
}
}
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;
}
}
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);
}
Aggregations