1 15 package org.apache.tapestry.engine.state; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.easymock.MockControl; 19 20 26 public class TestApplicationStateManager extends HiveMindTestCase 27 { 28 private StateObjectManagerRegistry newRegistry(String name, 29 StateObjectManager manager) 30 { 31 MockControl c = newControl(StateObjectManagerRegistry.class); 32 StateObjectManagerRegistry result = (StateObjectManagerRegistry) c 33 .getMock(); 34 35 result.get(name); 36 c.setReturnValue(manager); 37 38 return result; 39 } 40 41 public void testExistsInCache() 42 { 43 Object stateObject = new Object (); 44 45 MockControl c = newControl(StateObjectManager.class); 46 StateObjectManager m = (StateObjectManager) c.getMock(); 47 48 m.get(); 49 c.setReturnValue(stateObject); 50 51 StateObjectManagerRegistry r = newRegistry("fred", m); 52 53 replayControls(); 54 55 ApplicationStateManagerImpl asm = new ApplicationStateManagerImpl(); 56 asm.setRegistry(r); 57 58 assertSame(stateObject, asm.get("fred")); 59 60 assertEquals(true, asm.exists("fred")); 61 62 verifyControls(); 63 } 64 65 public void testNotExist() 66 { 67 68 MockControl c = newControl(StateObjectManager.class); 69 StateObjectManager m = (StateObjectManager) c.getMock(); 70 71 m.exists(); 72 c.setReturnValue(false); 73 74 StateObjectManagerRegistry r = newRegistry("barney", m); 75 76 replayControls(); 77 78 ApplicationStateManagerImpl asm = new ApplicationStateManagerImpl(); 79 asm.setRegistry(r); 80 81 assertEquals(false, asm.exists("barney")); 82 83 verifyControls(); 84 } 85 86 public void testGet() 87 { 88 Object stateObject = new Object (); 89 90 MockControl c = newControl(StateObjectManager.class); 91 StateObjectManager m = (StateObjectManager) c.getMock(); 92 93 m.get(); 94 c.setReturnValue(stateObject); 95 96 MockControl rc = newControl(StateObjectManagerRegistry.class); 97 StateObjectManagerRegistry r = (StateObjectManagerRegistry) rc 98 .getMock(); 99 100 r.get("barney"); 101 rc.setReturnValue(m); 102 103 replayControls(); 104 105 ApplicationStateManagerImpl asm = new ApplicationStateManagerImpl(); 106 asm.setRegistry(r); 107 108 assertSame(stateObject, asm.get("barney")); 109 110 verifyControls(); 111 112 replayControls(); 113 114 116 assertSame(stateObject, asm.get("barney")); 117 118 verifyControls(); 119 120 r.get("barney"); 121 rc.setReturnValue(m); 122 123 m.get(); 124 c.setReturnValue(stateObject); 125 126 replayControls(); 127 128 asm.passivateService(); 130 131 assertSame(stateObject, asm.get("barney")); 133 134 verifyControls(); 135 } 136 137 public void testFlush() 138 { 139 Object stateObject = new Object (); 140 141 MockControl c = newControl(StateObjectManager.class); 142 StateObjectManager m = (StateObjectManager) c.getMock(); 143 144 m.get(); 145 c.setReturnValue(stateObject); 146 147 MockControl rc = newControl(StateObjectManagerRegistry.class); 148 StateObjectManagerRegistry r = (StateObjectManagerRegistry) rc 149 .getMock(); 150 151 r.get("barney"); 152 rc.setReturnValue(m); 153 154 replayControls(); 155 156 ApplicationStateManagerImpl asm = new ApplicationStateManagerImpl(); 157 asm.setRegistry(r); 158 159 assertSame(stateObject, asm.get("barney")); 160 161 verifyControls(); 162 163 r.get("barney"); 164 rc.setReturnValue(m); 165 166 m.store(stateObject); 167 168 replayControls(); 169 170 asm.flush(); 171 172 verifyControls(); 173 } 174 } | Popular Tags |