View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: TestScopeServlet.java,v 1.5 2002/09/12 19:09:34 ludovicc Exp $ 37 */ 38 package test.controller.servlet; 39 40 41 import junit.framework.TestCase; 42 import org.scopemvc.controller.basic.ViewContext; 43 44 /*** 45 * <P> 46 * 47 * ***** Needs to test handlePopulateException and ServletException. ***** Needs 48 * to test redirect. </P> 49 * 50 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 51 * @created 05 September 2002 52 * @version $Revision: 1.5 $ $Date: 2002/09/12 19:09:34 $ 53 */ 54 public class TestScopeServlet extends TestCase { 55 56 /*** 57 * TODO: describe of the Field 58 */ 59 protected DummyServlet servlet; 60 61 62 /*** 63 * Constructor for the TestScopeServlet object 64 * 65 * @param inName Name of the test 66 */ 67 public TestScopeServlet(String inName) { 68 super(inName); 69 } 70 71 72 /*** 73 * The main program for the TestScopeServlet class 74 * 75 * @param args The command line arguments 76 */ 77 public static void main(String[] args) { 78 junit.swingui.TestRunner.run(TestScopeServlet.class); 79 } 80 81 82 /*** 83 * Default request should do startup of the AppController. 84 * 85 * @throws Exception Any abnormal exception 86 */ 87 public void testDefault() throws Exception { 88 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 89 }); 90 DummyHTTPResponse response = servlet.handlePost(request); 91 92 assertEquals("0", response.getContent()); 93 assertTrue(!AppController.doneTest1Control); 94 assertTrue(!AppController.doneTest1aControl); 95 assertTrue(!SubController.doneTest2Control); 96 } 97 98 99 /*** 100 * Route a Test1Control to viewid=1. 101 * 102 * @throws Exception Any abnormal exception 103 */ 104 public void testControlRouting1() throws Exception { 105 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 106 {"view", "1"}, 107 {"action", "Test1Control"}, 108 }); 109 DummyHTTPResponse response = servlet.handlePost(request); 110 111 assertEquals("TestModel", response.getContent()); 112 assertTrue(AppController.doneTest1Control); 113 assertTrue(!SubController.doneTest2Control); 114 } 115 116 117 /*** 118 * Route a Test1Control to viewid=1a. 119 * 120 * @throws Exception Any abnormal exception 121 */ 122 public void testControlRouting4() throws Exception { 123 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 124 {"view", "1a"}, 125 {"action", "Test1Control"}, 126 }); 127 DummyHTTPResponse response = servlet.handlePost(request); 128 129 assertEquals("TestModel", response.getContent()); 130 assertTrue(AppController.doneTest1Control); 131 assertTrue(!SubController.doneTest2Control); 132 } 133 134 135 /*** 136 * Route a Test1aControl to viewid=1 to set "1a" visible and then let 137 * ScopeServlet show the view because the Controller doesn't. 138 * 139 * @throws Exception Any abnormal exception 140 */ 141 public void testDefaultShowView() throws Exception { 142 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 143 {"view", "1"}, 144 {"action", "Test1aControl"}, 145 }); 146 DummyHTTPResponse response = servlet.handlePost(request); 147 148 // assertEquals("0", response.getContent()); 149 assertTrue(AppController.doneTest1aControl); 150 assertTrue(!AppController.doneTest1Control); 151 assertTrue(!SubController.doneTest2Control); 152 } 153 154 155 /*** 156 * Route a Test1Control to viewid=1 which is the default Page. 157 * 158 * @throws Exception Any abnormal exception 159 */ 160 public void testDefaultPage() throws Exception { 161 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 162 {"action", "Test1Control"}, 163 }); 164 DummyHTTPResponse response = servlet.handlePost(request); 165 166 assertEquals("TestModel", response.getContent()); 167 assertTrue(AppController.doneTest1Control); 168 assertTrue(!SubController.doneTest2Control); 169 } 170 171 172 /*** 173 * Route a Test1Control to viewid=NONSENSE should find app controller as 174 * first child of context. 175 * 176 * @throws Exception Any abnormal exception 177 */ 178 public void testDefaultPage2() throws Exception { 179 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 180 {"view", "NONSENSE"}, 181 {"action", "Test1Control"}, 182 }); 183 DummyHTTPResponse response = servlet.handlePost(request); 184 185 assertEquals("TestModel", response.getContent()); 186 assertTrue(AppController.doneTest1Control); 187 assertTrue(!SubController.doneTest2Control); 188 } 189 190 191 /*** 192 * Route a Test1Control to viewid=2 to see the chain of responsibility is 193 * OK. 194 * 195 * @throws Exception Any abnormal exception 196 */ 197 public void testControlRouting2() throws Exception { 198 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 199 {"view", "2"}, 200 {"action", "Test1Control"}, 201 }); 202 DummyHTTPResponse response = servlet.handlePost(request); 203 204 assertEquals("TestModel", response.getContent()); 205 assertTrue(AppController.doneTest1Control); 206 assertTrue(!SubController.doneTest2Control); 207 } 208 209 210 /*** 211 * Route a Test2Control to viewid=2. 212 * 213 * @throws Exception Any abnormal exception 214 */ 215 public void testControlRouting3() throws Exception { 216 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 217 {"view", "2"}, 218 {"action", "Test2Control"}, 219 }); 220 DummyHTTPResponse response = servlet.handlePost(request); 221 222 assertEquals("2TestModel2", response.getContent()); 223 assertTrue(!AppController.doneTest1Control); 224 assertTrue(SubController.doneTest2Control); 225 } 226 227 228 /*** 229 * Route a Test1Control to viewid=1 and try to populate the view's model. 230 * 231 * @throws Exception Any abnormal exception 232 */ 233 public void testPopulateModel1() throws Exception { 234 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 235 {"view", "1"}, 236 {"action", "Test1Control"}, 237 {".name", "NewName1"}, 238 }); 239 DummyHTTPResponse response = servlet.handlePost(request); 240 241 assertEquals("NewName1", response.getContent()); 242 } 243 244 245 /*** 246 * Route a Test1Control to viewid=1 and try to populate the view's model but 247 * omitting the viewid from the propertyid so should default to viewid=1 248 * 249 * @throws Exception Any abnormal exception 250 */ 251 public void testPopulateModel3() throws Exception { 252 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 253 {"view", "1"}, 254 {"action", "Test1Control"}, 255 {".name", "NewName2"}, 256 }); 257 DummyHTTPResponse response = servlet.handlePost(request); 258 259 assertEquals("NewName2", response.getContent()); 260 } 261 262 263 /*** 264 * Route a Test2Control to viewid=2 and try to populate the view's model. 265 * 266 * @throws Exception Any abnormal exception 267 */ 268 public void testPopulateModel2() throws Exception { 269 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 270 {"view", "2"}, 271 {"action", "Test2Control"}, 272 {".name", "NewName3"}, 273 }); 274 DummyHTTPResponse response = servlet.handlePost(request); 275 276 assertEquals("NewName3", response.getContent()); 277 } 278 279 280 /*** 281 * Route a Test2Control to viewid=2 and try to populate the view's model but 282 * omitting the viewid from the propertyid so should default to viewid=2 283 * 284 * @throws Exception Any abnormal exception 285 */ 286 public void testPopulateModel4() throws Exception { 287 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 288 {"view", "2"}, 289 {"action", "Test2Control"}, 290 {".name", "NewName4"}, 291 }); 292 DummyHTTPResponse response = servlet.handlePost(request); 293 294 assertEquals("NewName4", response.getContent()); 295 } 296 297 298 /*** 299 * Route a Test2Control to viewid=2 and try to populate the view's model but 300 * with a bad selectorid so get a validation error. 301 * 302 * @throws Exception Any abnormal exception 303 */ 304 public void testPopulateModel5() throws Exception { 305 DummyHTTPRequest request = new DummyHTTPRequest(new String[][]{ 306 {"view", "2"}, 307 {"action", "Test2Control"}, 308 {".x", "NewName5"}, 309 }); 310 DummyHTTPResponse response = servlet.handlePost(request); 311 312 assertTrue(response.getContent().indexOf("Error") > 0); 313 } 314 315 316 /*** 317 * The JUnit setup method 318 */ 319 protected void setUp() { 320 servlet = new DummyServlet(); 321 AppController.doneTest1Control = false; 322 AppController.doneTest1aControl = false; 323 SubController.doneTest2Control = false; 324 ViewContext.setGlobalContext(null); 325 ViewContext.clearThreadContext(); 326 } 327 }

This page was automatically generated by Maven