001: package com.tctest.wicket;
002:
003: import java.io.Serializable;
004:
005: import org.apache.wicket.Page;
006: import org.apache.wicket.markup.html.WebPage;
007: import org.apache.wicket.markup.html.basic.Label;
008: import org.apache.wicket.markup.html.link.Link;
009: import org.apache.wicket.util.tester.ITestPageSource;
010: import org.apache.wicket.util.tester.WicketTester;
011:
012: import com.tc.object.config.ConfigVisitor;
013: import com.tc.object.config.DSOClientConfigHelper;
014: import com.tc.simulator.app.ApplicationConfig;
015: import com.tc.simulator.listener.ListenerProvider;
016: import com.tctest.TransparentTestBase;
017: import com.tctest.runner.AbstractTransparentApp;
018:
019: /**
020: * This is mainly a stub test just to see how WicketTester fits with DSO functional testing fraework
021: */
022: public class DistributedWicketTest extends TransparentTestBase {
023:
024: private static final int NODE_COUNT = 2;
025:
026: protected void setUp() throws Exception {
027: super .setUp();
028: getTransparentAppConfig().setClientCount(NODE_COUNT)
029: .setIntensity(1);
030: setTimeoutThreshold(600000L);
031: initializeTestRunner();
032: }
033:
034: protected Class getApplicationClass() {
035: return DistributedWicketTestApp.class;
036: }
037:
038: public static class DistributedWicketTestApp extends
039: AbstractTransparentApp {
040:
041: public DistributedWicketTestApp(String appId,
042: ApplicationConfig cfg, ListenerProvider listenerProvider) {
043: super (appId, cfg, listenerProvider);
044: }
045:
046: public static void visitL1DSOConfig(ConfigVisitor visitor,
047: DSOClientConfigHelper config) {
048: //
049: }
050:
051: public void run() {
052: WicketTester tester = new WicketTester();
053:
054: tester.startPage(Page1.class);
055: tester.assertRenderedPage(Page1.class);
056: tester.assertLabel("message1", "Hello!");
057:
058: // click test
059: tester.startPage(Page1.class);
060: tester.clickLink("toPage2");
061: tester.assertRenderedPage(Page2.class);
062: tester.assertLabel("message2", "Hi!");
063:
064: tester.startPage(new Page2Source());
065: tester.assertRenderedPage(Page2.class);
066: tester.assertLabel("message2", "mock message");
067: tester.assertInfoMessages(new String[] { "Hi again!" });
068: }
069:
070: private static final class Page2Source implements
071: ITestPageSource, Serializable {
072: private static final long serialVersionUID = 1L;
073:
074: public Page getTestPage() {
075: return new Page2("mock message");
076: }
077: }
078: }
079:
080: public static class Page1 extends WebPage {
081: private static final long serialVersionUID = 1L;
082:
083: public Page1() {
084: add(new Label("message1", "Hello!"));
085: add(new Link("toPage2") {
086: private static final long serialVersionUID = 1L;
087:
088: public void onClick() {
089: setResponsePage(new Page2("Hi!"));
090: }
091: });
092: }
093:
094: }
095:
096: public static class Page2 extends WebPage {
097: private static final long serialVersionUID = 1L;
098:
099: public Page2(String message) {
100: add(new Label("message2", message));
101: info("Hi again!");
102: }
103: }
104:
105: }
|