1   /*
2    * Scope: a generic MVC framework.
3    * Copyright (c) 2000-2002, Steve Meyfroidt
4    * All rights reserved.
5    * Email: smeyfroi@users.sourceforge.net
6    *
7    *
8    * Redistribution and use in source and binary forms, with or without
9    * modification, are permitted provided that the following conditions
10   * are met:
11   *
12   * Redistributions of source code must retain the above copyright
13   * notice, this list of conditions and the following disclaimer.
14   *
15   * Redistributions in binary form must reproduce the above copyright
16   * notice, this list of conditions and the following disclaimer in the
17   * documentation and/or other materials provided with the distribution.
18   *
19   * Neither the name "Scope" nor the names of its contributors
20   * may be used to endorse or promote products derived from this software
21   * without specific prior written permission.
22   *
23   *
24   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27   * A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR
28   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35   *
36   *
37   * $Id: TestSCheckBox.java,v 1.7 2002/08/05 13:19:26 ludovicc Exp $
38   */
39  
40  
41  package test.view.swing;
42  
43  
44  import junit.framework.TestCase;
45  import org.apache.commons.logging.LogFactory;import org.apache.commons.logging.Log;
46  import org.scopemvc.core.Selector;
47  import org.scopemvc.view.swing.SCheckBox;
48  import org.scopemvc.view.swing.SPanel;
49  
50  
51  /***
52   * <P>
53   * </P>
54   *
55   * @author <A HREF="mailto:smeyfroi@users.sourceforge.net>Steve Meyfroidt</A>
56   * @version $Revision: 1.7 $ $Date: 2002/08/05 13:19:26 $
57   */
58  public final class TestSCheckBox extends TestCase {
59  
60  
61      private static final Log LOG = LogFactory.getLog(TestSCheckBox.class);
62  
63  
64      private SCheckBox checkbox;
65      private SwingDummyController controller;
66      private SPanel view;
67      private SwingDummyModel model;
68  
69  
70      public TestSCheckBox(String inName) {
71          super(inName);
72      }
73  
74  
75      protected void setUp() throws Exception {
76  
77          checkbox = new SCheckBox();
78  
79          view = new SPanel();
80          view.add(checkbox);
81  
82          controller = new SwingDummyController();
83          controller.setView(view);
84          controller.startup();   // does showView()
85  
86          model = new SwingDummyModel();
87      }
88  
89  
90      protected void tearDown() {
91          controller.shutdown();
92      }
93  
94  
95      public void testUnbound() throws Exception {
96          SuiteViewSwing.waitForAWT();
97          assertTrue(! checkbox.isEnabled());
98          assertTrue(! checkbox.isSelected());
99  
100         checkbox.setSelector(Selector.fromString("booleanProperty"));
101         SuiteViewSwing.waitForAWT();
102         assertEquals(Selector.fromString("booleanProperty"), checkbox.getSelector());
103         assertTrue(! checkbox.isEnabled());
104         assertTrue(! checkbox.isSelected());
105     }
106 
107 
108     public void testConvenience() throws Exception {
109         SuiteViewSwing.waitForAWT();
110         assertTrue(! checkbox.isEnabled());
111         assertTrue(! checkbox.isSelected());
112 
113         checkbox.setSelectorString("booleanProperty");
114         SuiteViewSwing.waitForAWT();
115         assertEquals(Selector.fromString("booleanProperty"), checkbox.getSelector());
116         assertTrue(! checkbox.isEnabled());
117         assertTrue(! checkbox.isSelected());
118     }
119 
120 
121     public void testBind1() throws Exception {
122         checkbox.setSelector(Selector.fromString("booleanProperty"));
123         assertEquals(Selector.fromString("booleanProperty"), checkbox.getSelector());
124 
125         controller.setModel(model);
126         SuiteViewSwing.waitForAWT();
127         assertSame(view.getBoundModel(), model);
128         assertSame(checkbox.getBoundModel(), model);
129         assertTrue(checkbox.isEnabled());
130         assertTrue(! checkbox.isSelected());
131 
132         model.setBooleanProperty(true);
133         SuiteViewSwing.waitForAWT();
134         assertTrue(checkbox.isEnabled());
135         assertTrue(checkbox.isSelected());
136 
137         model.setBooleanProperty(false);
138         SuiteViewSwing.waitForAWT();
139         assertTrue(checkbox.isEnabled());
140         assertTrue(! checkbox.isSelected());
141 
142         checkbox.doClick();
143         SuiteViewSwing.waitForAWT();
144         assertTrue(checkbox.isEnabled());
145         assertTrue(checkbox.isSelected());
146         assertTrue(model.getBooleanProperty());
147     }
148 
149 
150     public void testBind2() throws Exception {
151         checkbox.setSelector(Selector.fromString("booleanProperty1"));
152         assertEquals(Selector.fromString("booleanProperty1"), checkbox.getSelector());
153 
154         controller.setModel(model);
155         SuiteViewSwing.waitForAWT();
156         assertSame(view.getBoundModel(), model);
157         assertSame(checkbox.getBoundModel(), model);
158         assertTrue(checkbox.isEnabled());
159         assertTrue(! checkbox.isSelected());
160 
161         model.setBooleanProperty1(Boolean.TRUE);
162         SuiteViewSwing.waitForAWT();
163         assertTrue(checkbox.isEnabled());
164         assertTrue(checkbox.isSelected());
165 
166         model.setBooleanProperty1(Boolean.FALSE);
167         SuiteViewSwing.waitForAWT();
168         assertTrue(checkbox.isEnabled());
169         assertTrue(! checkbox.isSelected());
170 
171         checkbox.doClick();
172         SuiteViewSwing.waitForAWT();
173         assertTrue(checkbox.isEnabled());
174         assertTrue(checkbox.isSelected());
175         assertEquals(Boolean.TRUE, model.getBooleanProperty1());
176 
177         model.setBooleanProperty1(null);
178         SuiteViewSwing.waitForAWT();
179         assertTrue(checkbox.isSelected());
180         assertTrue(! checkbox.isEnabled());
181     }
182 
183 
184     public void testValidation() throws Exception {
185         checkbox.setSelector(Selector.fromString("invalidBooleanProperty"));
186         controller.setModel(model);
187         SuiteViewSwing.waitForAWT();
188         assertTrue(checkbox.isEnabled());
189         assertTrue(! checkbox.isSelected());
190 
191         checkbox.doClick();
192         SuiteViewSwing.waitForAWT();
193         assertTrue(checkbox.isEnabled());
194         assertTrue(checkbox.isSelected());
195         assertTrue(! model.getInvalidBooleanProperty());
196     }
197 
198 
199     public void testBadBind() throws Exception {
200         checkbox.setSelector(Selector.fromString("stringProperty"));
201         controller.setModel(model);
202         SuiteViewSwing.waitForAWT();
203 
204         assertTrue(! checkbox.isEnabled());
205         assertTrue(! checkbox.isSelected());
206 
207         checkbox.doClick();
208     }
209 
210 
211     public void testReadOnlyBind() throws Exception {
212         checkbox.setSelector(Selector.fromString("booleanReadOnlyProperty"));
213         controller.setModel(model);
214         SuiteViewSwing.waitForAWT();
215 
216         assertTrue(! checkbox.isEnabled());
217         assertTrue(checkbox.isSelected());
218     }
219 
220 
221     public void testControlIssue1() throws Exception {
222         checkbox.setSelector(Selector.fromString("booleanProperty"));
223         controller.setModel(model);
224         checkbox.setControlID("test1");
225         SuiteViewSwing.waitForAWT();
226 
227         assertNull(controller.lastControl);
228 
229         checkbox.doClick();
230         SuiteViewSwing.waitForAWT();
231         assertTrue(controller.controlMatches("test1"));
232 
233         checkbox.setControlID("test1a");
234         checkbox.doClick();
235         SuiteViewSwing.waitForAWT();
236         assertTrue(controller.controlMatches("test1a"));
237     }
238 
239 
240     public void testControlIssue2() throws Exception {
241         checkbox.setSelector(Selector.fromString("booleanProperty"));
242         controller.setModel(model);
243         checkbox.setControlID("test2");
244         SuiteViewSwing.waitForAWT();
245 
246         assertNull(controller.lastControl);
247 
248         model.setBooleanProperty(true);
249         SuiteViewSwing.waitForAWT();
250         assertTrue(controller.controlMatches("test2"));
251 
252         checkbox.setControlID("test2a");
253         model.setBooleanProperty(false);
254         SuiteViewSwing.waitForAWT();
255         assertTrue(controller.controlMatches("test2a"));
256     }
257 
258 
259     public void testBindNoMCE() throws Exception {
260         checkbox.setSelector(Selector.fromString("booleanProperty"));
261         assertEquals(Selector.fromString("booleanProperty"), checkbox.getSelector());
262 
263         SwingDummyModelNoMCE model = new SwingDummyModelNoMCE();
264 
265         controller.setModel(model);
266         SuiteViewSwing.waitForAWT();
267         assertSame(view.getBoundModel(), model);
268 
269         assertSame(checkbox.getBoundModel(), model);
270         assertTrue(checkbox.isEnabled());
271         assertTrue(! checkbox.isSelected());
272 
273         model.setBooleanProperty(true);
274         assertTrue(checkbox.isEnabled());
275         assertTrue(! checkbox.isSelected());
276 
277         view.refresh();
278         assertTrue(checkbox.isEnabled());
279         assertTrue(checkbox.isSelected());
280 
281         model.setBooleanProperty(false);
282         assertTrue(checkbox.isEnabled());
283         assertTrue(checkbox.isSelected());
284 
285         view.refresh();
286         assertTrue(checkbox.isEnabled());
287         assertTrue(! checkbox.isSelected());
288 
289         checkbox.doClick();
290         SuiteViewSwing.waitForAWT();
291         assertTrue(checkbox.isEnabled());
292         assertTrue(checkbox.isSelected());
293         assertTrue(model.getBooleanProperty());
294     }
295 }
296 
This page was automatically generated by Maven