1 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 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 appTitle; 47 private String appAdmins; 48 private String poweredLogo; 49 private String logonImage; 50 private String customerSupport; 51 private String copyRight; 52 private boolean basicAuth; 53 private String appAdminPermission; 54 private String projAdminPermission; 55 private String projUserPermission; 56 private String appConfigPath; 57 58 public void setUp() throws Exception { 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 } 83 84 87 public void testApplicationInstance() { 88 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 116 public void testAppConfigFile() { 117 logger.info("testing app config file: " + appConfigPath); 119 120 try { 122 app = (Application) this.storage.restoreBeanFromFile(appConfigPath, 123 Application.getInstance()); 124 } catch (IOException e) { 125 logger.error(e); 126 127 } 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 try { 152 this.storage.saveBeanToFile(appConfigPath, app); 153 } catch (IOException e) { 154 logger.error(e); 155 throw new RuntimeException (e); 156 } 157 } 158 159 private String genDirName() { 160 String dirName = this.getClass().getPackage().getName(); 161 dirName = Util.findTestDirectory(); 162 163 return dirName; 165 } 166 } 167 | Popular Tags |