01: /*
02: * $Id: WicketTestCase.java 460941 2006-06-06 18:24:23Z janne $ $Revision:
03: * 3927 $ $Date: 2006-06-06 20:24:23 +0200 (Tue, 06 Jun 2006) $
04: *
05: * ==================================================================== Licensed
06: * under the Apache License, Version 2.0 (the "License"); you may not use this
07: * file except in compliance with the License. You may obtain a copy of the
08: * License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15: * License for the specific language governing permissions and limitations under
16: * the License.
17: */
18: package wicket.examples;
19:
20: import junit.framework.TestCase;
21: import wicket.protocol.http.MockWebApplication;
22: import wicket.util.diff.DiffUtil;
23:
24: /**
25: * Base class for tests which require comparing wicket response with a file
26: */
27: public abstract class WicketTestCase extends TestCase {
28: /** */
29: public MockWebApplication application;
30:
31: /**
32: * Create the test.
33: *
34: * @param name
35: * The test name
36: */
37: public WicketTestCase(String name) {
38: super (name);
39: }
40:
41: protected void setUp() throws Exception {
42: application = new MockWebApplication(null);
43: }
44:
45: /**
46: * @param pageClass
47: * @param filename
48: * @throws Exception
49: */
50: protected void executeTest(final Class pageClass,
51: final String filename) throws Exception {
52: System.out.println("=== " + pageClass.getName() + " ===");
53:
54: application.setHomePage(pageClass);
55:
56: // Do the processing
57: application.setupRequestAndResponse();
58: application.processRequestCycle();
59:
60: assertEquals(pageClass, application.getLastRenderedPage()
61: .getClass());
62:
63: // Validate the document
64: String document = application.getServletResponse()
65: .getDocument();
66: assertTrue(DiffUtil.validatePage(document, this.getClass(),
67: filename));
68: }
69: }
|