1 20 package org.openi.web.controller; 21 22 import junit.framework.TestCase; 23 import org.apache.log4j.Logger; 24 import org.openi.application.*; 25 import org.openi.project.Project; 26 import org.openi.project.ProjectContext; 27 import org.openi.security.Permission; 28 import org.openi.test.Util; 29 import org.openi.xml.BeanStorage; 30 import org.springframework.context.ApplicationContext; 31 import org.springframework.context.support.FileSystemXmlApplicationContext; 32 import org.springframework.core.io.*; 33 import org.springframework.mock.web.*; 34 import org.springframework.web.context.support.StaticWebApplicationContext; 35 import java.io.IOException ; 36 37 38 48 public abstract class BaseControllerTestCase extends TestCase { 49 protected static StaticWebApplicationContext webAppContext; 51 52 protected static ApplicationContext appContext; 54 protected static final String TEST_PROJECT_NAME = "project.xml"; 55 protected static final Application app = null; 56 57 static { 58 String dirName = Util.findTestDirectory() + "/openi"; 59 appContext = new FileSystemXmlApplicationContext(dirName 61 + "/WEB-INF/springapp-servlet.xml"); 62 63 webAppContext = new StaticWebApplicationContext(); 64 65 MockServletContext servletcontext = new MockServletContext(); 66 67 webAppContext.setServletContext(servletcontext); 68 69 Application app = Application.getInstance(); 70 app.setApplicationAdmins(getTestUser()); 71 app.setApplicationAdminPermissions(getAllPermission()); 72 } 73 74 protected transient final Logger logger = Logger.getLogger(getClass()); 75 76 protected void setUp() throws Exception { 77 } 78 79 82 public MockHttpServletRequest newPost(String url) { 83 return new MockHttpServletRequest("POST", url); 84 } 85 86 public MockHttpServletRequest newGet(String url) { 87 return new MockHttpServletRequest("GET", url); 88 } 89 90 public Project getTestProject() throws IOException { 91 return org.openi.project.ProjectFactory.getProject(getTestProjectsDir(), 92 "standard"); 93 } 94 95 public ProjectContext getTestProjectContext() throws Exception { 96 Project project = getTestProject(); 97 String username = getTestUser(); 98 String baseDirectory = getTestProjectsDir(); 99 100 return new ProjectContext(project, baseDirectory, username); 101 } 102 103 protected static String getTestProjectsDir() { 104 return Util.findTestDirectory() + "/projects"; 105 } 106 107 protected static String getTestDirectory() { 108 return Util.findTestDirectory(); 109 } 110 111 protected static String getAllPermission() { 112 return Permission.APP_ADMINISTRATION + "," 113 + Permission.CONFIGURE_DATASOURCE + "," + Permission.CREATE_NEW + "," 114 + Permission.DELETE_PRIVATE + "," + Permission.DELETE_PUBLIC + "," 115 + Permission.DIAGNOSTICS + "," + Permission.MANAGE_FILES + "," 116 + Permission.PROJ_ADMINISTRATION + "," + Permission.SAVE_PRIVATE + "," 117 + Permission.SAVE_PUBLIC + "," + Permission.UPLOAD_FILE; 118 } 119 120 protected static String getTestUser() { 121 return "mouser"; 122 } 123 124 protected void tearDown() { 125 } 126 } 127 | Popular Tags |