KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.openi.application.Application;
23 import org.openi.web.controller.BaseControllerTestCase;
24 import org.springframework.mock.web.*;
25 import org.springframework.web.servlet.ModelAndView;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27
28
29 /**
30  * @author Uddhab Pant <br>
31  * @version $Revision: 1.7 $ $Date: 2006/04/12 00:39:12 $ <br>
32  *
33  * Test case for application form controller.
34  *
35  *
36  */

37 public class ApplicationFormControllerTest extends BaseControllerTestCase {
38     private ApplicationFormController ac1;
39     private ApplicationFormController ac2;
40     private MockHttpServletRequest request;
41     private HttpServletResponse JavaDoc response;
42     private ModelAndView mv;
43
44     /**
45      * Initialize test objects
46      *
47      * @throws IOException
48      */

49     public void setUp() throws Exception JavaDoc {
50         logger.info("Setting up");
51
52         super.setUp();
53
54         ac1 = (ApplicationFormController) appContext.getBean(
55                 "applicationFormController");
56         ac2 = new ApplicationFormController();
57
58         ac2.setApplicationContext(webAppContext);
59
60         request = newPost("/editapplication.htm");
61
62         response = new MockHttpServletResponse();
63     }
64
65     /**
66      * Test form
67      *
68      * @throws Exception
69      */

70     public void testEdit() throws Exception JavaDoc {
71         logger.info("Testing form");
72
73         assertFalse("Session form is not false", ac1.isSessionForm());
74         assertEquals("Command name is not equal", "application",
75             ac1.getCommandName());
76         assertEquals("Command class name is not equal",
77             "org.openi.application.Application", ac1.getCommandClass().getName());
78         assertEquals("Form view name is not equal", "editApplicationForm",
79             ac1.getFormView());
80         assertEquals("Success view is not equal", "editApplicationRedirect",
81             ac1.getSuccessView());
82     }
83
84     /**
85      * Test submit
86      */

87     public void testOnSubmit() throws Exception JavaDoc {
88         logger.info("Testing submit");
89
90         ac2.setSessionForm(ac1.isSessionForm());
91         ac2.setFormView(ac1.getFormView());
92         ac2.setSuccessView(ac1.getSuccessView());
93         ac2.setCommandClass(ac1.getCommandClass());
94         ac2.setCommandName(ac1.getCommandName());
95
96         request.addParameter("save", "save");
97         request.addParameter("applicationTitle",
98             "OpenIŽ Open Intelligence Portal");
99         request.addParameter("applicationAdmins", "upant");
100         request.addParameter("poweredByLogoName",
101             "../openi-projects/openi/images/openi-footer.png");
102         request.addParameter("logonImageName",
103             "../openi-projects/openi/images/openi-logo.png");
104         request.addParameter("customerSupport",
105             "http://sourceforge.net/forum/?group_id=142873");
106         request.addParameter("copyrightMessage",
107             "copyright (c) 2005, Loyalty Matrix, Inc.");
108         request.addParameter("basicAuthentication", "true");
109         request.addParameter("applicationAdminPermissions",
110             "Application_Administration,Project_Administration,Save_Public,Save_Private,Delete_Public,Delete_Private,Create_New,Upload_File,Diagnostics,Configure_Datasource,Manage_Files");
111         request.addParameter("projectAdminPermissions",
112             "Project_Administration,Save_Public,Save_Private,Delete_Public,Delete_Private,Create_New,Upload_File,Configure_Datasource,Manage_Files");
113         request.addParameter("projectUserPermissions",
114             "Save_Private,Delete_Private,Create_New,Configure_Datasource");
115
116         mv = ac2.handleRequest(request, response);
117
118         Application app = (Application) mv.getModel().get(ac2.getCommandName());
119         assertNotNull("application is null", app);
120         assertEquals("title is not equal", "OpenIŽ Open Intelligence Portal",
121             app.getApplicationTitle());
122         assertEquals("app admins is not equal", "upant",
123             app.getApplicationAdmins());
124         assertEquals("powered by logo in not equal",
125             "../openi-projects/openi/images/openi-footer.png",
126             app.getPoweredByLogoName());
127         assertEquals("logon image is not equal",
128             "../openi-projects/openi/images/openi-logo.png",
129             app.getLogonImageName());
130         assertEquals("contact support is not equal",
131             "http://sourceforge.net/forum/?group_id=142873",
132             app.getCustomerSupport());
133         assertEquals("copy right is not equal",
134             "copyright (c) 2005, Loyalty Matrix, Inc.",
135             app.getCopyrightMessage());
136         assertEquals("basic auth is not equal", "true",
137             String.valueOf(app.isBasicAuthentication()));
138         assertEquals("app admin permissions is not equal",
139             "Application_Administration,Project_Administration,Save_Public,Save_Private,Delete_Public,Delete_Private,Create_New,Upload_File,Diagnostics,Configure_Datasource,Manage_Files",
140             app.getApplicationAdminPermissions());
141         assertEquals("project admin permissions is not equal",
142             "Project_Administration,Save_Public,Save_Private,Delete_Public,Delete_Private,Create_New,Upload_File,Configure_Datasource,Manage_Files",
143             app.getProjectAdminPermissions());
144         assertEquals("project user permission is not equal",
145             "Save_Private,Delete_Private,Create_New,Configure_Datasource",
146             app.getProjectUserPermissions());
147     }
148
149     protected void tearDown() {
150         ac1 = null;
151         ac2 = null;
152     }
153 }
154
Popular Tags