KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > application > ApplicationTest


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.application;
21
22 import junit.framework.Assert;
23 import junit.framework.TestCase;
24 import org.apache.log4j.Logger;
25 import org.openi.application.Application;
26 import org.openi.test.Util;
27 import org.openi.xml.BeanStorage;
28 import java.io.*;
29 import java.util.*;
30
31
32 /**
33  * @author Uddhab Pant <br>
34  * @version $Revision: 1.6 $ $Date: 2006/04/12 00:39:12 $ <br>
35  *
36  * Test case for application configuration.
37  *
38  *
39  */

40 public class ApplicationTest extends TestCase {
41     private static Logger logger = Logger.getLogger(ApplicationTest.class);
42     private Application appOne = null;
43     private Application appTwo = null;
44     private Application app;
45     private BeanStorage storage;
46     private String JavaDoc appTitle;
47     private String JavaDoc appAdmins;
48     private String JavaDoc poweredLogo;
49     private String JavaDoc logonImage;
50     private String JavaDoc customerSupport;
51     private String JavaDoc copyRight;
52     private boolean basicAuth;
53     private String JavaDoc appAdminPermission;
54     private String JavaDoc projAdminPermission;
55     private String JavaDoc projUserPermission;
56     private String JavaDoc appConfigPath;
57
58     public void setUp() throws Exception JavaDoc {
59         super.setUp();
60         this.storage = new BeanStorage();
61         appTitle = "OpenI";
62         appAdmins = "admin1,admin2";
63         poweredLogo = "images/mo-log.jpg";
64         logonImage = "images/logon.jpg";
65         customerSupport = "http://sourceforge.net/forum/?group_id=142873";
66         copyRight = "copyright (c) 2005, Loyalty Matrix, Inc.";
67         basicAuth = true;
68         appAdminPermission = "app administration,project administration";
69         projAdminPermission = "project administration,save public,save private";
70         projUserPermission = "save private";
71
72         logger.info("getting first instance...");
73
74         appOne = Application.getInstance();
75
76         logger.info("getting second...");
77         appTwo = Application.getInstance();
78
79         appConfigPath = genDirName() + "-projects/WEB-INF/application.xml";
80
81         //System.out.println(appConfigPath);
82
}
83
84     /**
85      * Verify single copy of application configuration.
86      */

87     public void testApplicationInstance() {
88         //System.out.println("testing application instance");
89
logger.info("testing application instance...");
90         appOne.setApplicationTitle(appTitle);
91         appOne.setApplicationAdmins(appAdmins);
92         appOne.setPoweredByLogoName(poweredLogo);
93         appOne.setLogonImageName(logonImage);
94         appOne.setCustomerSupport(customerSupport);
95         appOne.setCopyrightMessage(copyRight);
96         appOne.setBasicAuthentication(basicAuth);
97         appOne.setApplicationAdminPermissions(appAdminPermission);
98         appOne.setProjectAdminPermissions(projAdminPermission);
99         appOne.setProjectUserPermissions(projUserPermission);
100
101         assertEquals(appTwo.getApplicationTitle(), appTitle);
102         assertEquals(appTwo.getApplicationAdmins(), appAdmins);
103         assertEquals(appTwo.getPoweredByLogoName(), poweredLogo);
104         assertEquals(appTwo.getLogonImageName(), logonImage);
105         assertEquals(appTwo.getCustomerSupport(), customerSupport);
106         assertEquals(appTwo.getCopyrightMessage(), copyRight);
107         assertEquals(appTwo.isBasicAuthentication(), basicAuth);
108         assertEquals(appTwo.getApplicationAdminPermissions(), appAdminPermission);
109         assertEquals(appTwo.getProjectAdminPermissions(), projAdminPermission);
110         assertEquals(appTwo.getProjectUserPermissions(), projUserPermission);
111     }
112
113     /**
114      * restore and save test of application.xml
115      */

116     public void testAppConfigFile() {
117         //System.out.println("testing app config file"+ appConfigPath);
118
logger.info("testing app config file: " + appConfigPath);
119
120         //test restore
121
try {
122             app = (Application) this.storage.restoreBeanFromFile(appConfigPath,
123                     Application.getInstance());
124         } catch (IOException e) {
125             logger.error(e);
126
127             //System.err.println("Error:"+e);
128
}
129
130         assertNotNull(app);
131         assertEquals("OpenIŽ Open Intelligence Portal",
132             app.getApplicationTitle());
133         assertEquals("upant", app.getApplicationAdmins());
134         assertEquals("../openi-projects/openi/images/openi-footer.png",
135             app.getPoweredByLogoName());
136         assertEquals("../openi-projects/openi/images/openi-logo.png",
137             app.getLogonImageName());
138         assertEquals("http://sourceforge.net/forum/?group_id=142873",
139             app.getCustomerSupport());
140         assertEquals("copyright (c) 2005, Loyalty Matrix, Inc.",
141             app.getCopyrightMessage());
142         assertEquals(true, app.isBasicAuthentication());
143         assertEquals("Application_Administration,Project_Administration,Save_Public,Save_Private,Delete_Public,Delete_Private,Create_New,Upload_File,Diagnostics,Configure_Datasource,Manage_Files",
144             app.getApplicationAdminPermissions());
145         assertEquals("Project_Administration,Save_Public,Save_Private,Delete_Public,Delete_Private,Create_New,Upload_File,Configure_Datasource,Manage_Files",
146             app.getProjectAdminPermissions());
147         assertEquals("Save_Private,Delete_Private,Create_New,Configure_Datasource",
148             app.getProjectUserPermissions());
149
150         //test save
151
try {
152             this.storage.saveBeanToFile(appConfigPath, app);
153         } catch (IOException e) {
154             logger.error(e);
155             throw new RuntimeException JavaDoc(e);
156         }
157     }
158
159     private String JavaDoc genDirName() {
160         String JavaDoc dirName = this.getClass().getPackage().getName();
161         dirName = Util.findTestDirectory();
162
163         // System.out.println(dirName);
164
return dirName;
165     }
166 }
167
Popular Tags