1 package org.apache.fulcrum.yaafi.testcontainer; 2 40 import junit.framework.TestCase; 41 42 import org.apache.avalon.framework.component.Component; 43 import org.apache.avalon.framework.component.ComponentException; 44 45 54 public abstract class BaseUnitTest extends TestCase 55 { 56 57 public static String COMPONENT_APP_ROOT = Container.COMPONENT_APP_ROOT; 58 59 private Container container; 60 61 private String configurationFileName = "src/test/TestComponentConfig.xml"; 62 63 private String roleFileName = "src/test/TestRoleConfig.xml"; 64 65 private String parameterFileName = "src/test/TestParameters.properties"; 66 67 73 protected void setConfigurationFileName(String configurationFileName) 74 { 75 this.configurationFileName = configurationFileName; 76 } 77 78 84 protected void setRoleFileName(String roleFileName) 85 { 86 this.roleFileName = roleFileName; 87 } 88 89 95 protected void setParameterFileName(String parameterFileName) 96 { 97 this.parameterFileName = parameterFileName; 98 } 99 100 105 public BaseUnitTest(String testName) 106 { 107 super(testName); 108 } 109 110 113 protected void tearDown() throws Exception 114 { 115 if (container != null) 116 { 117 container.dispose(); 118 } 119 container = null; 120 } 121 126 protected String getConfigurationFileName() 127 { 128 return configurationFileName; 129 } 130 135 protected String getRoleFileName() 136 { 137 return roleFileName; 138 } 139 144 protected String getParameterFileName() 145 { 146 return parameterFileName; 147 } 148 154 protected Object lookup(String roleName) throws ComponentException 155 { 156 if (container == null) 157 { 158 container = new Container(); 159 container.startup(getConfigurationFileName(), getRoleFileName(), getParameterFileName()); 160 } 161 return container.lookup(roleName); 162 } 163 168 protected void release(Component component) 169 { 170 if (container != null) 171 { 172 container.release(component); 173 } 174 } 175 180 protected void release(Object component) 181 { 182 if (container != null) 183 { 184 container.release(component); 185 } 186 } 187 } 188 | Popular Tags |