1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: TestSwingContext.java,v 1.3 2002/09/12 19:09:34 ludovicc Exp $
37 */
38 package test.controller.swing;
39
40 import java.awt.Cursor;
41
42 import junit.framework.*;
43 import org.scopemvc.controller.basic.*;
44 import org.scopemvc.controller.swing.*;
45 import org.scopemvc.core.*;
46 import org.scopemvc.util.ScopeConfig;
47 import org.scopemvc.view.swing.*;
48
49 /***
50 * @author <A HREF="mailto:ludovicc@users.sourceforge.net">Ludovic Claude</A>
51 * @created 05 September 2002
52 * @version $Revision: 1.3 $ $Date: 2002/09/12 19:09:34 $
53 */
54 public final class TestSwingContext extends TestCase {
55
56 private SwingContext context;
57
58 /***
59 * Constructor for the TestSwingContext object
60 *
61 * @param inName Name of the test
62 */
63 public TestSwingContext(String inName) {
64 super(inName);
65 }
66
67
68 /***
69 * A unit test for JUnit
70 *
71 * @throws Exception Any abnormal exception
72 */
73 public void testShowWindow() throws Exception {
74 SPanel window = new SPanel();
75 window.setTitle("Test Window");
76 window.setDisplayMode(SwingView.PRIMARY_WINDOW);
77 context.showView(window);
78 SuiteControllerSwing.waitForAWT();
79 assertTrue(!context.areAllViewsClosed());
80
81 context.hideAllViews();
82 SuiteControllerSwing.waitForAWT();
83 assertTrue(context.areAllViewsClosed());
84 }
85
86 /***
87 * A unit test for JUnit
88 *
89 * @throws Exception Any abnormal exception
90 */
91 public void testShowDialog() throws Exception {
92 // cannot test easily modal dialogs as they block the current thread of
93 // execution when calling show(), so we use modeless dialogs only
94 SPanel modelessDialog = new SPanel();
95 modelessDialog.setDisplayMode(SwingView.MODELESS_DIALOG);
96 modelessDialog.setTitle("Test Modeless Dialog");
97
98 context.showView(modelessDialog);
99 SuiteControllerSwing.waitForAWT();
100 assertTrue(!context.areAllViewsClosed());
101
102 context.hideAllViews();
103 SuiteControllerSwing.waitForAWT();
104 assertTrue(context.areAllViewsClosed());
105 }
106
107
108 /***
109 * A unit test for JUnit
110 *
111 * @throws Exception Any abnormal exception
112 */
113 public void testProgress() throws Exception {
114 long progressDelay = ScopeConfig.getInteger(SwingContext.PROGRESS_START_DELAY_PROPERTY).longValue();
115 SPanel window = new SPanel();
116 context.showView(window);
117 context.startProgress();
118 SuiteControllerSwing.waitForAWT();
119 Thread.sleep(progressDelay * 2);
120 // to pass the progress delay
121 assertTrue(!context.areAllViewsClosed());
122 assertEquals(window.getCursor().getType(), Cursor.WAIT_CURSOR);
123
124 Thread.sleep(1000);
125
126 context.stopProgress();
127 SuiteControllerSwing.waitForAWT();
128 assertEquals(window.getCursor().getType(), Cursor.DEFAULT_CURSOR);
129
130 Thread.sleep(1000);
131
132 context.hideAllViews();
133 SuiteControllerSwing.waitForAWT();
134 assertTrue(context.areAllViewsClosed());
135 }
136
137
138 /***
139 * A unit test for JUnit. <br>
140 * Ensures that Scope closes all its windows so the JVM can exit cleanly
141 *
142 * @throws Exception Any abnormal exception
143 * @todo Write this test
144 */
145 public void testComplexInitAndClose() throws Exception { }
146
147
148 /***
149 * The JUnit setup method
150 */
151 protected void setUp() {
152 context = new SwingContext();
153 ViewContext.setGlobalContext(context);
154 }
155
156 /***
157 * The teardown method for JUnit
158 */
159 protected void tearDown() {
160 ViewContext.setGlobalContext(null);
161 }
162
163 }
This page was automatically generated by Maven