1 20 package org.openi.test; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 25 import org.apache.log4j.*; 26 import org.openi.analysis.Analysis; 27 import org.openi.application.Application; 28 import org.openi.project.Project; 29 import org.openi.project.ProjectContext; 30 import org.openi.xml.BeanStorage; 31 32 33 36 public class Util { 37 private static Logger logger = Logger.getLogger(Util.class); 38 44 public static String findTestDirectory() { 45 return System.getProperty("TESTDIR", "./test"); 46 } 47 48 public static void setupLog4j() { 49 PropertyConfigurator.configure(Util.findTestDirectory() 50 + "/log4jtest.properties"); 51 } 52 53 56 public static void initApplicationConfig() { 57 String appConfigPath = Util.findTestDirectory() + 58 "/../conf/application.xml"; 59 try { 60 65 new BeanStorage().restoreBeanFromFile(appConfigPath, Application.getInstance()); 66 67 } catch (IOException e) { 69 logger.error(e); 71 } 72 73 } 74 75 80 public static ProjectContext createTestProjectContext(String username) { 81 String baseDir = Util.findTestDirectory() + "/projects/"; 82 return createTestProjectContext(username, "standard"); 83 } 84 85 public static ProjectContext createTestProjectContext(String username, String projectId) { 86 String baseDir = Util.findTestDirectory() + "/projects/"; 87 String projectFile = baseDir + "/" + projectId + "/project.xml"; 88 ProjectContext context = null; 89 try { 90 Project project = (Project) new BeanStorage().restoreBeanFromFile(projectFile); 91 context= new ProjectContext(project, baseDir, username); 92 } catch (IOException e) { 93 logger.error(e); 95 } 96 return context; 97 } 98 99 public static Analysis restoreAnalysis(String analysisName) 100 throws IOException { 101 return (Analysis) new BeanStorage().restoreBeanFromFile(Util.findTestDirectory() + 102 "/projects/standard/public/" + analysisName); 103 104 } 105 } 106 | Popular Tags |