KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > BaseControllerTestCase


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

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 JavaDoc;
36
37
38 /**
39  * @author Uddhab Pant <br>
40  * @version $Revision: 1.5 $ $Date: 2006/04/12 00:39:12 $ <br>
41  *
42  * Base class for controller test cases.
43  * This class initializes and defines common objects
44  * required by controllers.
45  *
46  *
47  */

48 public abstract class BaseControllerTestCase extends TestCase {
49     // Required to test form controller in web application context.
50
protected static StaticWebApplicationContext webAppContext;
51
52     // Required to test form controller in application context
53
protected static ApplicationContext appContext;
54     protected static final String JavaDoc TEST_PROJECT_NAME = "project.xml";
55     protected static final Application app = null;
56
57     static {
58         String JavaDoc dirName = Util.findTestDirectory() + "/openi";
59         // load app context from spring servlet file.
60
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 JavaDoc {
77     }
78
79     /**
80      * Convenience methods to make tests simpler
81      */

82     public MockHttpServletRequest newPost(String JavaDoc url) {
83         return new MockHttpServletRequest("POST", url);
84     }
85
86     public MockHttpServletRequest newGet(String JavaDoc url) {
87         return new MockHttpServletRequest("GET", url);
88     }
89
90     public Project getTestProject() throws IOException JavaDoc {
91         return org.openi.project.ProjectFactory.getProject(getTestProjectsDir(),
92             "standard");
93     }
94
95     public ProjectContext getTestProjectContext() throws Exception JavaDoc {
96         Project project = getTestProject();
97         String JavaDoc username = getTestUser();
98         String JavaDoc baseDirectory = getTestProjectsDir();
99
100         return new ProjectContext(project, baseDirectory, username);
101     }
102
103     protected static String JavaDoc getTestProjectsDir() {
104         return Util.findTestDirectory() + "/projects";
105     }
106
107     protected static String JavaDoc getTestDirectory() {
108         return Util.findTestDirectory();
109     }
110
111     protected static String JavaDoc 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 JavaDoc getTestUser() {
121         return "mouser";
122     }
123
124     protected void tearDown() {
125     }
126 }
127
Popular Tags