1 package org.tigris.scarab.test; 2 3 48 import java.io.File ; 49 import java.util.HashMap ; 50 import java.util.Map ; 51 52 import junit.framework.TestCase; 53 54 import org.apache.fulcrum.TurbineServices; 55 import org.apache.turbine.Turbine; 56 import org.apache.turbine.TurbineConfig; 57 import org.apache.turbine.TurbineConstants; 58 import org.apache.turbine.TurbineXmlConfig; 59 65 public class BaseTurbineTestCase extends TestCase { 66 private static TurbineConfig tc = null; 67 68 private static boolean initialized = false; 69 70 public BaseTurbineTestCase() { 71 System.setProperty("applicationRoot", "./target/test-classes"); 72 } 73 74 public BaseTurbineTestCase(String name) throws Exception { 75 super(name); 76 } 77 80 protected void setUp() throws Exception { 81 82 if (!initialized) { 83 createLog4jDirectory(); 84 initTurbine(); 85 initialized=true; 86 } 87 } 88 91 protected void tearDown() throws Exception { 92 super.tearDown(); 93 if (Turbine.getConfiguration() != null) { 94 boolean stop = Turbine.getConfiguration().getBoolean("unittest.teardown.shutdownServices", true); 98 99 if (stop) { 100 TurbineServices.getInstance().shutdownServices(); 101 initialized=false; 102 } 103 } 104 } 105 106 private void createLog4jDirectory(){ 107 File log4jDir = new File ("." 108 + File.separator + "target" 109 + File.separator + "scarab" 110 + File.separator + "logs" + File.separator); 111 if(!log4jDir.exists()){ 112 log4jDir.mkdirs(); 113 } 114 } 115 private void initTurbine() throws Exception { 116 File directoryFile = new File ("src/test"); 117 String directory = directoryFile.getAbsolutePath(); 118 119 Map params = new HashMap (); 120 params.put(TurbineXmlConfig.CONFIGURATION_PATH_KEY,"../../src/test/TestTurbineConfiguration.xml"); 121 params.put(TurbineConstants.APPLICATION_ROOT,"target/scarab"); 122 124 tc = new TurbineXmlConfig(directory,params); 125 tc.init(); 126 127 } 128 129 130 } 131 | Popular Tags |