1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, Steve Meyfroidt
4 * All rights reserved.
5 * Email: smeyfroi@users.sourceforge.net
6 *
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * Neither the name "Scope" nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 *
37 * $Id: TestPage.java,v 1.3 2002/08/05 13:17:17 ludovicc Exp $
38 */
39
40
41 package test.view.servlet;
42
43 import org.scopemvc.controller.basic.ViewContext;
44 import org.scopemvc.controller.servlet.ServletContext;
45 import org.scopemvc.view.servlet.Page;
46 import org.scopemvc.view.servlet.ServletView;
47 import junit.framework.TestCase;
48 import org.scopemvc.model.basic.BasicModel;
49 import org.scopemvc.core.Selector;
50 import org.scopemvc.core.Controller;
51 import org.scopemvc.controller.basic.BasicController;
52 import org.scopemvc.core.Control;
53 import org.scopemvc.core.View;
54 import java.io.OutputStream;
55 import org.scopemvc.core.ControlException;
56
57
58 /***
59 * <P>
60 * </P>
61 *
62 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A>
63 * @version $Revision: 1.3 $ $Date: 2002/08/05 13:17:17 $
64 */
65 public final class TestPage extends TestCase {
66
67
68 public TestPage(String inName) {
69 super(inName);
70 }
71
72
73 private Page page1;
74 private Page page2;
75 private ServletView servletView;
76 private Object model;
77 private ServletTestController controller;
78
79
80 protected void setUp() {
81 page1 = new ServletTestPage("1");
82 page2 = new ServletTestPage("2");
83 servletView = new ServletView();
84 model = new Object();
85 controller = new ServletTestController();
86 }
87
88
89 public void testID() {
90 assertEquals("1", page1.getID());
91 assertEquals("2", page2.getID());
92 }
93
94
95 public void testEqualsID() {
96 assertTrue(page1.equalsID("1"));
97 assertTrue(! page1.equalsID("rubbish"));
98 assertTrue(page2.equalsID("2"));
99 assertTrue(! page2.equalsID("rubbish"));
100 }
101
102
103 public void testParent() {
104 assertNull(page1.getParent());
105 page1.setParent(servletView);
106 assertSame(servletView, page1.getParent());
107 }
108
109
110 public void testBoundModel() {
111 assertNull(page1.getBoundModel());
112 assertNull(page2.getBoundModel());
113
114 servletView.addPage(page1);
115 servletView.addPage(page2);
116 servletView.setBoundModel(model);
117
118 assertSame(model, page1.getBoundModel());
119 assertSame(model, page2.getBoundModel());
120
121 try {
122 page1.setBoundModel(new Object());
123 fail("setBoundModel on an unparented Page");
124 } catch (UnsupportedOperationException e) {
125 // expected
126 }
127 }
128
129
130 public void testController() {
131 assertNull(page1.getController());
132 assertNull(page2.getController());
133
134 servletView.addPage(page1);
135 servletView.addPage(page2);
136 servletView.setController(controller);
137
138 assertSame(controller, page1.getController());
139 assertSame(controller, page2.getController());
140
141 try {
142 page1.setController(new ServletTestController());
143 fail("setController on an unparented Page");
144 } catch (UnsupportedOperationException e) {
145 // expected
146 }
147 }
148
149
150 public void testIssueControl() throws Exception {
151 ViewContext.setThreadContext(new TestServletContext());
152 Control control = new Control("TestControl");
153
154 try {
155 page1.issueControl(control);
156 fail("issueControl on an unparented Page");
157 } catch (UnsupportedOperationException e) {
158 // expected
159 }
160
161 servletView.addPage(page1);
162 servletView.setController(controller);
163 page1.issueControl(control);
164 assertTrue("Control not issued through parent view", controller.handledControl);
165 }
166
167 static class TestServletContext extends ServletContext {
168 public TestServletContext() {
169 super(null, null, null, null);
170 }
171 public void showView(View inView) {}
172 }
173 }
This page was automatically generated by Maven