001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.wicket;
018:
019: import junit.framework.TestCase;
020:
021: import org.apache.wicket.behavior.AbstractAjaxBehavior;
022: import org.apache.wicket.util.tester.WicketTester;
023:
024: /**
025: * Base class for tests which require comparing wicket response with a file.
026: * <p>
027: * To create/replace the expected result file with the new content, define the
028: * system property like -Dwicket.replace.expected.results=true
029: *
030: */
031: public abstract class WicketTestCase extends TestCase {
032: /** */
033: public WicketTester tester;
034:
035: /**
036: * Constructor
037: */
038: public WicketTestCase() {
039: }
040:
041: /**
042: * Create the test.
043: *
044: * @param name
045: * The test name
046: */
047: public WicketTestCase(String name) {
048: super (name);
049: }
050:
051: /**
052: * @see junit.framework.TestCase#setUp()
053: */
054: protected void setUp() throws Exception {
055: tester = new WicketTester();
056: }
057:
058: /**
059: * @see junit.framework.TestCase#tearDown()
060: */
061: protected void tearDown() throws Exception {
062: tester.destroy();
063: }
064:
065: /**
066: * Use <code>-Dwicket.replace.expected.results=true</code> to
067: * automatically replace the expected output file.
068: *
069: * @param pageClass
070: * @param filename
071: * @throws Exception
072: */
073: protected void executeTest(final Class pageClass,
074: final String filename) throws Exception {
075: System.out.println("=== " + pageClass.getName() + " ===");
076:
077: tester.startPage(pageClass);
078: tester.assertRenderedPage(pageClass);
079: tester.assertResultPage(this .getClass(), filename);
080: }
081:
082: /**
083: *
084: * @param clazz
085: * @param component
086: * @param filename
087: * @throws Exception
088: */
089: protected void executedListener(final Class clazz,
090: final Component component, final String filename)
091: throws Exception {
092: assertNotNull(component);
093:
094: System.out.println("=== " + clazz.getName() + " : "
095: + component.getPageRelativePath() + " ===");
096:
097: tester.executeListener(component);
098: tester.assertResultPage(clazz, filename);
099: }
100:
101: /**
102: *
103: * @param clazz
104: * @param behavior
105: * @param filename
106: * @throws Exception
107: */
108: protected void executedBehavior(final Class clazz,
109: final AbstractAjaxBehavior behavior, final String filename)
110: throws Exception {
111: assertNotNull(behavior);
112:
113: System.out.println("=== " + clazz.getName() + " : "
114: + behavior.toString() + " ===");
115:
116: tester.executeBehavior(behavior);
117: tester.assertResultPage(clazz, filename);
118: }
119: }
|