KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > admin > ProjectFormControllerTest


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.admin;
21
22 import junit.framework.TestCase;
23 import org.openi.project.Project;
24 import org.openi.project.ProjectContext;
25 import org.openi.web.controller.BaseControllerTestCase;
26 import org.springframework.mock.web.*;
27 import org.springframework.web.servlet.ModelAndView;
28 import javax.servlet.http.HttpServletResponse JavaDoc;
29
30
31 /**
32  * @author Uddhab Pant <br>
33  * @version $Revision: 1.5 $ $Date: 2006/04/12 00:39:12 $ <br>
34  *
35  * Test case for project form controller.
36  *
37  *
38  */

39 public class ProjectFormControllerTest extends BaseControllerTestCase {
40     private ProjectFormController pc1;
41     private ProjectFormController pc2;
42     private MockHttpServletRequest request;
43     private HttpServletResponse JavaDoc response;
44     private ModelAndView mv;
45     private ProjectContext projectContext;
46
47     public void setUp() throws Exception JavaDoc {
48         logger.info("Setting up");
49
50         super.setUp();
51
52         pc1 = (ProjectFormController) appContext.getBean(
53                 "projectFormController");
54         pc2 = new ProjectFormController();
55
56         pc2.setApplicationContext(webAppContext);
57
58         request = newPost("/editproject.htm");
59
60         response = new MockHttpServletResponse();
61
62         projectContext = getTestProjectContext();
63
64         request.getSession().setAttribute("projectContext", projectContext);
65     }
66
67     /**
68      * Test form
69      * @throws Exception
70      */

71     public void testEdit() throws Exception JavaDoc {
72         assertFalse("Session form is not false", pc1.isSessionForm());
73         assertEquals("Command name is not equal", "project",
74             pc1.getCommandName());
75         assertEquals("Command class name is not equal",
76             "org.openi.project.Project", pc1.getCommandClass().getName());
77         assertEquals("Form view name is not equal", "editProjectForm",
78             pc1.getFormView());
79         assertEquals("Success view is not equal", "editProjectRedirect",
80             pc1.getSuccessView());
81     }
82
83     /**
84      * Test submit
85      */

86     public void testOnSubmit() throws Exception JavaDoc {
87         logger.info("Testing submit");
88
89         pc2.setSessionForm(pc1.isSessionForm());
90         pc2.setFormView(pc1.getFormView());
91         pc2.setSuccessView(pc1.getSuccessView());
92         pc2.setCommandClass(pc1.getCommandClass());
93         pc2.setCommandName(pc1.getCommandName());
94
95         request.addParameter("save", "save");
96         request.addParameter("projectName", "OpenI");
97         request.addParameter("cssName", "openidemo.css");
98         request.addParameter("logoUrl", "images/openi-logo.png");
99         request.addParameter("splashImageUrl", "images/openi-splash.png");
100         request.addParameter("splashPage", "");
101         request.addParameter("modules", "public/Samples");
102         request.addParameter("projectAdmins", "admin");
103         request.addParameter("projectUsers", "tomcat");
104         //request.addParameter("Category", "save private");
105
//request.addParameter("message", "save private");
106
mv = pc2.handleRequest(request, response);
107
108         Project project = (Project) mv.getModel().get(pc2.getCommandName());
109
110         // TODO : because of addition in project, ProjectTest is not updated,
111
// Need to update project test case along with this test case.
112
}
113
114     protected void tearDown() {
115         pc1 = null;
116         pc2 = null;
117     }
118 }
119
Popular Tags