1 63 64 package com.jcorporate.expresso.core.registry; 65 66 import com.jcorporate.expresso.core.security.SuperUser; 67 import com.jcorporate.expresso.core.security.User; 68 import com.jcorporate.expresso.services.test.TestSystemInitializer; 69 import junit.framework.TestCase; 70 71 75 public class TestMutableRequestRegistry extends TestCase { 76 private MutableRequestRegistry mutableRequestRegistry = null; 77 78 protected void setUp() throws Exception { 79 super.setUp(); 80 User admin = User.getUserFromId(User.getAdminId(TestSystemInitializer.getTestContext()), 81 TestSystemInitializer.getTestContext()); 82 83 84 mutableRequestRegistry = new MutableRequestRegistry(TestSystemInitializer 85 .getTestContext(), admin); 86 } 87 88 protected void tearDown() throws Exception { 89 mutableRequestRegistry.releaseSettings(); 90 mutableRequestRegistry = null; 91 super.tearDown(); 92 new MutableRequestRegistry(TestSystemInitializer 95 .getTestContext(), 96 SuperUser.SUPER_USER); 97 } 98 99 public void testReleaseSettings() { 100 mutableRequestRegistry.releaseSettings(); 101 assertEquals(null, RequestRegistry.getDataContext()); 102 assertEquals(null, RequestRegistry.getDataContext()); 103 } 104 105 public void testSetDataContext() { 106 assertEquals(TestSystemInitializer.getTestContext(), 107 RequestRegistry.getDataContext()); 108 109 mutableRequestRegistry.setDataContext("abcdefg"); 110 assertEquals("abcdefg", 111 RequestRegistry.getDataContext()); 112 } 113 114 public void testSetUser() throws Exception { 115 User u = new User(); 116 u.setDataContext(TestSystemInitializer.getTestContext()); 117 u.setLoginName(User.UNKNOWN_USER); 118 if (!u.find()) { 119 throw new IllegalStateException ("Couldn't find Unknown user"); 120 } 121 122 mutableRequestRegistry.setUser(u); 123 124 assertEquals(u.getLoginName(), 125 RequestRegistry.getUser().getLoginName()); 126 } 127 128 public void testMutableRequestRegistry() { 129 mutableRequestRegistry = new MutableRequestRegistry(); 130 assertEquals(null, RequestRegistry.getDataContext()); 131 assertEquals(null, RequestRegistry.getUser()); 132 } 133 134 public void testMutableRequestRegistry1() throws Exception { 135 User u = new User(); 136 u.setDataContext(TestSystemInitializer.getTestContext()); 137 u.setLoginName(User.UNKNOWN_USER); 138 if (!u.find()) { 139 throw new IllegalStateException ("Couldn't find Unknown user"); 140 } 141 String dataContext = "testing!Testing!"; 142 mutableRequestRegistry = new MutableRequestRegistry(dataContext, u); 143 assertEquals(dataContext, RequestRegistry.getDataContext()); 144 assertEquals(u.getLoginName(), RequestRegistry.getUser().getLoginName()); 145 } 146 147 public void testGetDataContext() { 148 assertEquals(TestSystemInitializer.getTestContext(), 149 RequestRegistry.getDataContext()); 150 } 151 152 public void testGetUser() throws Exception { 153 assertEquals(User.getAdminId(TestSystemInitializer.getTestContext()), 154 RequestRegistry.getUser().getUid()); 155 } 156 157 public void testSuperUser() throws Exception { 158 User u = new User(); 159 u.setDataContext(TestSystemInitializer.getTestContext()); 160 u.setLoginName(User.UNKNOWN_USER); 161 if (!u.find()) { 162 throw new IllegalStateException ("Couldn't find Unknown user"); 163 } 164 RequestRegistry.superUser(u); 165 assertEquals(User.UNKNOWN_USER, RequestRegistry.getUser().getLoginName()); 166 } 167 168 169 public void testRevertUser() throws Exception { 170 User u = new User(); 171 u.setDataContext(TestSystemInitializer.getTestContext()); 172 u.setLoginName(User.UNKNOWN_USER); 173 if (!u.find()) { 174 throw new IllegalStateException ("Couldn't find Unknown user"); 175 } 176 RequestRegistry.superUser(u); 177 User newUser = RequestRegistry.revertUser(); 178 assertEquals(newUser.getLoginName(), RequestRegistry.getUser().getLoginName()); 179 assertEquals(User.getAdminId(TestSystemInitializer.getTestContext()), 180 RequestRegistry.getUser().getUid()); 181 } 182 183 public void testRevertUserShouldThrowExceptionForUnmatchedPushPops() throws Exception { 184 try { 185 RequestRegistry.revertUser(); 186 fail("RequestRegistry.revertUser should have thrown " + 187 "ArrayIndexOutOfBoundsException"); 188 189 } catch (java.lang.ArrayIndexOutOfBoundsException ex) { 190 } 192 193 User u = new User(); 194 u.setDataContext(TestSystemInitializer.getTestContext()); 195 u.setLoginName(User.UNKNOWN_USER); 196 if (!u.find()) { 197 throw new IllegalStateException ("Couldn't find Unknown user"); 198 } 199 RequestRegistry.superUser(u); 200 User newUser = RequestRegistry.revertUser(); 201 202 try { 203 RequestRegistry.revertUser(); 204 fail("RequestRegistry.revertUser should have thrown " + 205 "ArrayIndexOutOfBoundsException"); 206 207 } catch (java.lang.ArrayIndexOutOfBoundsException ex) { 208 } 210 } 211 212 213 } 214 | Popular Tags |