1 15 package org.apache.tapestry.html; 16 17 import org.apache.hivemind.test.HiveMindTestCase; 18 import org.apache.tapestry.IPage; 19 import org.apache.tapestry.IRequestCycle; 20 import org.apache.tapestry.test.Creator; 21 import org.easymock.MockControl; 22 23 27 public class TestPageEvents extends HiveMindTestCase 28 { 29 private IPage newPage() 30 { 31 Creator creator = new Creator(); 32 33 return (IPage) creator.newInstance(BasePage.class); 34 } 35 36 public void testPageDetached() 37 { 38 IPage page = newPage(); 39 ListenerFixture l = new ListenerFixture(); 40 41 43 page.detach(); 44 45 page.addPageDetachListener(l); 46 47 page.detach(); 48 49 assertEquals("pageDetached", l.getMethod()); 50 51 l.reset(); 52 53 page.removePageDetachListener(l); 54 55 page.detach(); 56 57 assertNull(l.getMethod()); 58 } 59 60 62 public void testPageAttached() 63 { 64 IPage page = newPage(); 65 ListenerFixture l = new ListenerFixture(); 66 67 69 page.attach(null, null); 70 71 page.addPageAttachListener(l); 72 73 page.attach(null, null); 74 75 assertEquals("pageAttached", l.getMethod()); 76 77 l.reset(); 78 79 page.removePageAttachListener(l); 80 81 page.attach(null, null); 82 83 assertNull(l.getMethod()); 84 } 85 86 public void testPageBeginRender() 87 { 88 IPage page = newPage(); 89 ListenerFixture l = new ListenerFixture(); 90 91 MockControl control = newControl(IRequestCycle.class); 92 IRequestCycle cycle = (IRequestCycle) control.getMock(); 93 94 cycle.isRewinding(); 95 control.setReturnValue(true); 96 97 replayControls(); 98 99 101 page.renderPage(null, cycle); 102 103 verifyControls(); 104 105 cycle.isRewinding(); 106 control.setReturnValue(true); 107 108 replayControls(); 109 110 page.addPageBeginRenderListener(l); 111 112 page.renderPage(null, cycle); 113 114 assertEquals("pageBeginRender", l.getMethod()); 115 116 l.reset(); 117 118 page.removePageBeginRenderListener(l); 119 120 verifyControls(); 121 122 cycle.isRewinding(); 123 control.setReturnValue(true); 124 125 replayControls(); 126 127 page.renderPage(null, cycle); 128 129 assertNull(l.getMethod()); 130 131 verifyControls(); 132 } 133 134 public void testPageEndRender() 135 { 136 IPage page = newPage(); 137 ListenerFixture l = new ListenerFixture(); 138 139 MockControl control = newControl(IRequestCycle.class); 140 IRequestCycle cycle = (IRequestCycle) control.getMock(); 141 142 cycle.isRewinding(); 143 control.setReturnValue(true); 144 145 replayControls(); 146 147 149 page.renderPage(null, cycle); 150 151 verifyControls(); 152 153 cycle.isRewinding(); 154 control.setReturnValue(true); 155 156 replayControls(); 157 158 page.addPageEndRenderListener(l); 159 160 page.renderPage(null, cycle); 161 162 assertEquals("pageEndRender", l.getMethod()); 163 164 l.reset(); 165 166 page.removePageEndRenderListener(l); 167 168 verifyControls(); 169 170 cycle.isRewinding(); 171 control.setReturnValue(true); 172 173 replayControls(); 174 175 page.renderPage(null, cycle); 176 177 assertNull(l.getMethod()); 178 179 verifyControls(); 180 } 181 182 public void testPageValidate() 183 { 184 IPage page = newPage(); 185 ListenerFixture l = new ListenerFixture(); 186 187 189 page.validate(null); 190 191 page.addPageValidateListener(l); 192 193 page.validate(null); 194 195 assertEquals("pageValidate", l.getMethod()); 196 197 l.reset(); 198 199 page.removePageValidateListener(l); 200 201 page.validate(null); 202 203 assertNull(l.getMethod()); 204 } 205 206 } | Popular Tags |