1 64 65 package com.jcorporate.expresso.services.dbobj.tests; 66 67 import com.jcorporate.expresso.core.cache.CacheManager; 68 import com.jcorporate.expresso.core.db.DBException; 69 import com.jcorporate.expresso.core.dbobj.SecuredDBObject; 70 import com.jcorporate.expresso.core.dbobj.ValidValue; 71 import com.jcorporate.expresso.services.dbobj.Setup; 72 import com.jcorporate.expresso.services.test.ExpressoTestCase; 73 import com.jcorporate.expresso.services.test.TestSystemInitializer; 74 import junit.framework.TestSuite; 75 76 import java.util.Enumeration ; 77 import java.util.StringTokenizer ; 78 79 80 88 public class SetupTests 89 extends ExpressoTestCase { 90 public SetupTests(String name) 91 throws Exception { 92 super(name); 93 } 94 95 public static void main(String [] args) 96 throws java.lang.Exception { 97 98 junit.textui.TestRunner.run(suite()); 100 } 101 102 108 public static junit.framework.Test suite() 109 throws Exception { 110 return new TestSuite(SetupTests.class); 111 } 112 113 116 public void testSetupCacheCreation() { 117 try { 118 Setup s = new Setup(SecuredDBObject.SYSTEM_ACCOUNT); 119 s.setDataContext(TestSystemInitializer.getTestContext()); 120 Setup.readSetups(); 121 122 if (!CacheManager.existsCache(TestSystemInitializer.getTestContext(), Setup.CACHE_NAME)) { 123 fail("Setup cache was not created correctly."); 124 } 125 126 assertTrue("Setup Cache must have at least 10 values in it.", 127 CacheManager.getItemCount(TestSystemInitializer.getTestContext(), Setup.CACHE_NAME) > 10); 128 } catch (DBException ex) { 129 ex.printStackTrace(); 130 fail(ex.getMessage()); 131 } 132 } 133 134 138 public void testSetupCacheValues() { 139 try { 140 Setup s = new Setup(SecuredDBObject.SYSTEM_ACCOUNT); 141 s.setDataContext(TestSystemInitializer.getTestContext()); 142 143 String oneValue = null; 144 String oneSchema = null; 145 String oneCode = null; 146 ValidValue oneItem = null; 147 148 for (Enumeration e = CacheManager.getItems(TestSystemInitializer.getTestContext(), Setup.CACHE_NAME).elements(); 149 e.hasMoreElements();) { 150 oneItem = (ValidValue) e.nextElement(); 151 152 StringTokenizer stk = new StringTokenizer (oneItem.getKey(), "|"); 155 oneSchema = stk.nextToken(); 156 oneCode = stk.nextToken(); 157 oneValue = Setup.getValue(TestSystemInitializer.getTestContext(), oneSchema, oneCode); 158 159 if (!(oneItem.getDescription().indexOf("%context%") != -1 || 164 oneItem.getDescription().indexOf("%web-app%") != -1)) { 165 if (!oneValue.equals(oneItem.getDescription())) { 166 fail("Setup value for default db, schema '" + oneSchema + 167 "', code '" + oneCode + "'" + " should have been " + 168 oneItem.getDescription() + ", but was " + oneValue); 169 } 170 } 171 } 172 } catch (Exception ex) { 173 ex.printStackTrace(); 174 fail(ex.getMessage()); 175 } 176 } 177 } | Popular Tags |