📄 servicetestsetup.java
字号:
package net.java.workeffort.service;import java.util.List;import junit.extensions.TestSetup;import junit.framework.Test;import net.java.workeffort.data.DataFileUtil;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.context.ApplicationContext;import org.springframework.context.support.FileSystemXmlApplicationContext;/** * Setup for service tests. * <ul> * <li>Initializes the application context once per test suite using spring. * </li> * <li> * <li>Removes all data from the database tables </b> This means that if there * is any data you need for future use you have export it before you run the * tests.</li> * <li>Inserts data in the tables using the dataset files.</li> * </ul> * </p> * Note: The test data is not cleaned up once the tests complete. This allows * manual verification of the database state after a failed test. * @author Antony Joseph */public class ServiceTestSetup extends TestSetup { protected static final Log log = LogFactory.getLog(ServiceTestSetup.class); private static ApplicationContext context; private List dataFiles; private DataFileUtil dataFileUtil; /** * Test suite setup. * @param suite * @param files List of data files to be used for the test */ public ServiceTestSetup(Test suite, List files) { super(suite); this.dataFiles = files; // need these for sequence generation dataFiles.add(DataFileUtil.SEQUENCE); dataFileUtil = new DataFileUtil(); } protected void setUp() throws Exception { try { context = new FileSystemXmlApplicationContext(new String[] { "./src/web/WEB-INF/config/dataAccess-context.xml", "./src/web/WEB-INF/config/application-context.xml" }); } catch (Exception e) { e.printStackTrace(); log.error("Check path of the Spring config files.", e); throw e; } dataFileUtil.cleanAllDatabaseTables(context); dataFileUtil.loadDataFiles(dataFiles, context); } /** * @return context the applicaton context */ public static ApplicationContext getApplicationContext() { return context; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -