001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.testapp.interactive.testscreen;
031:
032: import nextapp.echo2.app.Button;
033: import nextapp.echo2.app.Column;
034: import nextapp.echo2.app.Extent;
035: import nextapp.echo2.app.Insets;
036: import nextapp.echo2.app.Label;
037: import nextapp.echo2.app.event.ActionEvent;
038: import nextapp.echo2.app.event.ActionListener;
039: import nextapp.echo2.app.layout.SplitPaneLayoutData;
040: import nextapp.echo2.testapp.interactive.GhostTask;
041: import nextapp.echo2.testapp.interactive.InteractiveApp;
042:
043: /**
044: * Test to initiate a client-server push "loop" that autonomously clicks random
045: * on-screen buttons.
046: */
047: public class PushGhostTest extends Column {
048:
049: /**
050: * Default constructor.
051: */
052: public PushGhostTest() {
053: super ();
054: SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
055: splitPaneLayoutData.setInsets(new Insets(10));
056: setLayoutData(splitPaneLayoutData);
057:
058: setCellSpacing(new Extent(3));
059:
060: Label label;
061: label = new Label(
062: "This test will cause the application to continuously push asynchronous updates "
063: + "to the client by clicking buttons randomly on the screen. Once started, the test cannot be "
064: + "stopped until your application session is destroyed, i.e., by exiting your browser or "
065: + "manually clearing the session cookie.");
066: add(label);
067:
068: if (InteractiveApp.LIVE_DEMO_SERVER) {
069: label = new Label(
070: "Because you are visiting this application on the nextapp.com server, we have disabled "
071: + "the options to run this test indefinitely and/or with a 0ms callback interval. If you install this "
072: + "application on your own server, you will be given the option of running the more extreme version "
073: + "of this test. A binary Web Archive (WAR file) version of this application is provided by the "
074: + "standard Echo2 download.");
075: add(label);
076: }
077:
078: addTestButton(500, 20, 1);
079:
080: if (!InteractiveApp.LIVE_DEMO_SERVER) {
081: addTestButton(0, 10, 1);
082: addTestButton(0, 20, 1);
083: addTestButton(0, 60, 1);
084: addTestButton(0, 300, 1);
085: addTestButton(0, 600, 1);
086: addTestButton(0, 3600, 1);
087: addTestButton(0, 0, 1);
088:
089: addTestButton(0, 10, 10);
090: addTestButton(0, 20, 10);
091: addTestButton(0, 60, 10);
092: addTestButton(0, 300, 10);
093: addTestButton(0, 600, 10);
094: addTestButton(0, 3600, 10);
095: addTestButton(0, 0, 10);
096:
097: addTestButton(0, 10, 100);
098: addTestButton(0, 20, 100);
099: addTestButton(0, 60, 100);
100: addTestButton(0, 300, 100);
101: addTestButton(0, 600, 100);
102: addTestButton(0, 3600, 100);
103: addTestButton(0, 0, 100);
104: }
105: }
106:
107: private void addTestButton(final int callbackInterval,
108: final int runTimeInSeconds, final int clicksPerIteration) {
109: StringBuffer text = new StringBuffer("START (Runtime: ");
110: text.append(runTimeInSeconds == 0 ? "Indefinite"
111: : (runTimeInSeconds + "s"));
112: text.append(", Callback interval: ");
113: text.append(callbackInterval);
114: text.append("ms, Clicks Per Iteration: ");
115: text.append(clicksPerIteration);
116: Button startButton = new Button(text.toString());
117: startButton.setStyleName("Default");
118: startButton.addActionListener(new ActionListener() {
119: public void actionPerformed(ActionEvent e) {
120: InteractiveApp app = (InteractiveApp) getApplicationInstance();
121: GhostTask ghostTask = new GhostTask();
122: ghostTask.setClicksPerIteration(clicksPerIteration);
123: if (runTimeInSeconds > 0) {
124: ghostTask.setRunTime(runTimeInSeconds * 1000);
125: }
126: app.startGhostTask(ghostTask, callbackInterval);
127: }
128: });
129: add(startButton);
130: }
131: }
|