001: package abbot.editor.recorder;
002:
003: import java.awt.*;
004:
005: import javax.swing.*;
006:
007: import junit.extensions.abbot.RepeatHelper;
008: import abbot.Platform;
009: import abbot.script.Resolver;
010: import abbot.tester.JInternalFrameTester;
011:
012: /**
013: * Unit test to verify proper capture of user semantic events on a Window.
014: */
015: public class JInternalFrameRecorderTest extends
016: AbstractSemanticRecorderFixture {
017:
018: private JInternalFrame frame;
019: private JInternalFrameTester tester;
020:
021: /** Special adapter to catch events on JInternalFrame instances. */
022: private class InternalFrameWatcher extends
023: AbstractInternalFrameWatcher {
024: public InternalFrameWatcher(JInternalFrame frame) {
025: super (frame);
026: }
027:
028: protected void dispatch(AWTEvent e) {
029: insertEvent(e);
030: }
031: }
032:
033: public void testCaptureShowHide() throws Throwable {
034: startRecording();
035: showInternalFrame();
036: assertStep("Wait for ComponentShowing");
037:
038: frame.setVisible(false);
039: assertStep("Wait for !ComponentShowing");
040: }
041:
042: /*
043: public void testCaptureMaximizeNormalize() throws Throwable {
044: showInternalFrame();
045: startRecording();
046: tester.actionMaximize(frame);
047: assertStep("Maximize\\(.*\\)");
048: tester.actionNormalize(frame);
049: assertStep("Normalize\\(.*\\)");
050: }
051: */
052:
053: public void testCaptureIconifyDeiconify() throws Throwable {
054: showInternalFrame();
055: startRecording();
056: tester.actionIconify(frame);
057: assertStep("Iconify\\(.*\\)");
058: tester.actionDeiconify(frame);
059: assertStep("Deiconify\\(.*\\)");
060: }
061:
062: public void testCaptureMove() throws Throwable {
063: showInternalFrame();
064: startRecording();
065: Point p = frame.getLocation();
066: tester.actionMove(frame, p.x + 10, p.y + 10);
067: assertStep("Move\\(.*\\)");
068: }
069:
070: public void testCaptureResize() throws Throwable {
071: showInternalFrame();
072: startRecording();
073: Dimension size = frame.getSize();
074: tester.actionResize(frame, size.width + 10, size.height + 10);
075: assertStep("Resize\\(.*\\)");
076: }
077:
078: public void testCaptureClose() throws Throwable {
079: showInternalFrame();
080: startRecording();
081: tester.actionClose(frame);
082: assertStep("Close\\(.*\\)");
083: }
084:
085: private void showInternalFrame() throws Throwable {
086: EventQueue.invokeAndWait(new Runnable() {
087: public void run() {
088: frame.show();
089: }
090: });
091: }
092:
093: protected void setUp() {
094: if (Platform.JAVA_VERSION < Platform.JAVA_1_4) {
095: fail("Internal frame tracking not supported prior to 1.4");
096: }
097:
098: JDesktopPane dtpane = new JDesktopPane();
099: frame = new JInternalFrame(getName(), true, true, true, true);
100: frame.getContentPane().add(new JLabel(getName()));
101:
102: dtpane.add(frame);
103: showFrame(dtpane, new Dimension(400, 400));
104: frame.setLocation(10, 10);
105: frame.setSize(300, 300);
106:
107: new InternalFrameWatcher(frame);
108: tester = new JInternalFrameTester();
109: }
110:
111: public JInternalFrameRecorderTest(String name) {
112: super (name);
113: }
114:
115: protected SemanticRecorder createSemanticRecorder(Resolver r) {
116: return new JInternalFrameRecorder(r);
117: }
118:
119: public static void main(String[] args) {
120: RepeatHelper.runTests(args, JInternalFrameRecorderTest.class);
121: }
122: }
|